If you build with LLMs, you probably juggle several provider accounts, keys and SDKs. Here's a shortcut: one OpenAI-compatible endpoint that serves models from Anthropic, OpenAI, Google, xAI, DeepSeek, Moonshot, Qwen and Z.ai, so you keep the SDK you already use and only change the model name.
I'm using Refract here. It's pay per token with no subscription, and prices are well below the official ones (Claude Sonnet 5.5 is $0.50 / $2.50 per 1M tokens against $2 / $10).
Python (OpenAI SDK)
import os
from openai import OpenAI
client = OpenAI(base_url="https://refracthub.com/v1", api_key=os.environ["REFRACT_API_KEY"])
for model in ["claude-sonnet-5-5", "gpt-6.2-sol", "gemini-4-argon", "grok-4.7"]:
r = client.chat.completions.create(
model=model,
messages=[{"role": "user", "content": "Explain recursion in one sentence."}],
)
print(model, "→", r.choices[0].message.content)
Node (OpenAI SDK)
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://refracthub.com/v1", apiKey: process.env.REFRACT_API_KEY });
const r = await client.chat.completions.create({
model: "claude-opus-5-5",
messages: [{ role: "user", content: "Write a haiku about TypeScript." }],
});
console.log(r.choices[0].message.content);
Python (Anthropic SDK)
The Anthropic Messages API works too, so existing Claude code needs only a new base URL:
import os, anthropic
client = anthropic.Anthropic(base_url="https://refracthub.com", api_key=os.environ["REFRACT_API_KEY"])
msg = client.messages.create(model="claude-sonnet-5-5", max_tokens=300,
messages=[{"role": "user", "content": "Summarise the plot of Hamlet in 3 lines."}])
print(msg.content[0].text)
Streaming, tools and images
Streaming (stream=True), tool calling and image inputs work the same way as with the official SDKs. A few more things that help:
- Spending caps per key, so a bug in a loop can't drain your balance.
- A usage log with the tokens and cost of every request.
-
"model": "auto"lets Refract pick a model for each request.
Try it
Get a key at refracthub.com and see every model ID and price on the models page. The examples above are also in a GitHub repo: refract-examples.
Top comments (0)