# Use the OpenAI SDK with any model

> The official openai package for Python and TypeScript doesn't have to mean OpenAI models. Override base_url and api_key, keep every other call the same, and address hundreds of models across many providers as provider/model strings, including OpenAI's own.

- Date: July 12, 2026
- Category: guides
- HTML: https://anyrouter.dev/blog/openai-sdk-any-model

## 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 hundreds of models across many 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:

### Python

```python
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)
```

### TypeScript

```ts
import OpenAI from "openai"

const client = new OpenAI({
  baseURL: "https://anyrouter.dev/api/v1",
  apiKey: process.env.ANYROUTER_API_KEY,
})

const resp = await client.chat.completions.create({
  model: "google/gemini-2.5-pro",
  messages: [{ role: "user", content: "Explain base_url in one sentence" }],
})
console.log(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 | Google |
| z-ai/glm-5.2 | Z.ai |

![AnyRouter model page listing a model's provider, context length, and pricing](https://cdn.anyrouter.dev/screenshots/model-hy3-with-bg-2026-11.webp)

_Every model id resolves to its own page with specs and upstream provider._

## 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 hundreds of models across many providers.

[Get a key free](https://anyrouter.dev/dashboard)
