Can I use the OpenAI SDK with models that aren't OpenAI's?
Yes. The openai package, in Python or JS/TS, only needs two things overridden to talk to a different backend: base_url and api_key. Everything else — client.chat.completions.create, the streaming shape, the message format — is the same call whether the model behind it is GPT, Claude, Gemini, or something else entirely.
AnyRouter implements that same OpenAI-compatible contract in front of 170+ models across 28+ providers, so the SDK you already have installed becomes a universal client instead of an OpenAI-only one.
One client, either language
Only two values change — the base URL and the key. Model choice moves into the model string itself:
from openai import OpenAI
client = OpenAI(
base_url="https://anyrouter.dev/api/v1",
api_key="sk-ar-v1-...",
)
resp = client.chat.completions.create(
model="anthropic/claude-opus-4-8",
messages=[{"role": "user", "content": "Explain base_url in one sentence"}],
)
print(resp.choices[0].message.content)Both snippets are the unmodified openai and openai-node packages — nothing installed beyond what an OpenAI integration already needs.
Streaming and tool calls carry over unchanged
Because the contract is the standard Chat Completions API, the parts of your code that already handle it don't need touching. Set stream=True and read deltas exactly as you would against OpenAI directly; function/tool-calling definitions pass through the same way.
- Streaming — stream=True (Python) or stream: true (TypeScript), same delta shape.
- Tool calling — the same tools array and tool_choice parameter.
- Other dialects on the same key — /messages for Anthropic-style clients, /responses for the newer Responses API.
Change the model, not the code
Because every model is addressed as a provider/model string, switching what a request runs on is a config value:
| Model id | Owner |
|---|---|
| openai/gpt-5.5 | OpenAI |
| anthropic/claude-opus-4-8 | Anthropic |
| google/gemini-2.5-pro | |
| z-ai/glm-5.2 | Z.ai |

No lock-in either direction
Since this is the real OpenAI API contract and not a proprietary wrapper, the same code points straight back at api.openai.com if you ever want to leave — nothing about the call shape is AnyRouter-specific. For the full catalog and failover behavior behind the endpoint, see /blog/one-api-every-llm.
Keep the OpenAI SDK, reach 170+ models across 28+ providers.
Get a key freeRelated posts
Point Claude Code at a custom base URL
Claude Code reads ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY, so pointing it at AnyRouter takes two environment variables — no plugin, no fork. You get every model in the catalog behind the same key, automatic failover when a provider is rate-limited, and one audit log shared with Codex, Cursor, and every other agent you run.
One API for every LLM
One OpenAI-compatible endpoint reaches every model in the catalog — 170+ models addressed as provider/model, with automatic failover across upstreams, routing presets, and streaming. Point your existing client at AnyRouter and change a model with a string, not a rewrite.
Route your first request in 2 minutes
Start free with your own keys, or top up and pay per token. Get $4/mo in credits and free models on Go — $2/mo, or free when you donate a provider key.
Start free