# Keep the OpenAI SDK, reach every model

> Markdown mirror of https://router.one/integrations/openai-sdk for AI assistants and crawlers. Router One is an OpenAI-compatible LLM API gateway.
> Last updated: 2026-08-24

If your code already uses the official OpenAI SDK, the entire migration is two constructor arguments: base URL and key. Everything else — chat completions, streaming, tool calls — keeps working, and the same client object now reaches GPT, Claude, Gemini, and DeepSeek family models by model string, with a cost trace per request.

## Configure OpenAI SDK to use the Router One base URL

Python and JS/TS both take the base URL in the client constructor:

`openai-sdk-example.py`

```bash
from openai import OpenAI

client = OpenAI(
    base_url="https://api.router.one/v1",
    api_key="sk-your-router-one-key",
)

resp = client.chat.completions.create(
    model="<model-id-from-/models>",
    messages=[{"role": "user", "content": "Hello!"}],
)
# JS/TS: new OpenAI({ baseURL, apiKey }) — same two arguments
```

## Which model ID should OpenAI SDK send?

Copy the exact model ID from the /models page — IDs are case-sensitive, and the page lists each model's context window, capabilities, and current per-token rates. Create a dedicated API key per tool with its own maxSpend cap, so one runaway tool can't affect other workloads.

## Verify the OpenAI SDK call in your request trace

After your first request, open Dashboard → Logs to see its full trace: model, tokens, cost, latency, and status code. From here every OpenAI SDK call has a ledger and a trail instead of being a black box.

## FAQ

### Do I need to change any request code?

No — requests, streaming, and tool calls use the standard Chat Completions interface. Only the client constructor changes: base URL and API key. Model switching is just the model string.

### Which models can OpenAI SDK use through the gateway?

Any chat-capable model in the catalog — GPT, Claude, Gemini, Grok, DeepSeek, GLM, MiniMax, and Doubao families. The /models page is the source of truth for model IDs and per-token rates.

### Does this work from Mainland China?

Yes. The gateway is reachable from Mainland China without a VPN, and the configuration is identical to the global setup.

### How do I debug a 401/403/429?

Open Dashboard → Logs first to see whether requests reached the gateway and with what status, then walk the error-codes reference to check env vars, key status, and limits.

## See also

- All integration guides: https://router.one/integrations
- Debug 401/403/429 in OpenAI SDK: https://router.one/llm-api-error-codes
- Dify setup: https://router.one/integrations/dify
- Roo Code setup: https://router.one/integrations/roo-code
- What the gateway layer does: https://router.one/llm-api-gateway
- OpenAI-compatible API: https://router.one/openai-compatible-api
- API docs: https://router.one/docs
- Canonical page: https://router.one/integrations/openai-sdk
- Models and per-model token rates: https://router.one/models (markdown: https://router.one/models.md)
- Pricing: https://router.one/pricing
- API docs (markdown): https://router.one/docs.md
- Company facts: https://router.one/facts/company.md
