Migrate from the OpenAI API
Change the OpenAI base URL and API key to call 600+ models through TrustedRouter. Keep the OpenAI SDK, your model names, streaming and tool calls.Change the base URL and key. Keep the OpenAI SDK.
Up to 1 million free tokens. No card required.
Change two lines
Point the OpenAI SDK at TrustedRouter with a new base URL and key. Your model names, messages, streaming and tool calls stay the same.
Before: OpenAI
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["OPENAI_API_KEY"],
)
response = client.chat.completions.create(
model="gpt-5.4-mini",
messages=[{"role": "user", "content": "Say hello"}],
)After: TrustedRouter
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api-azure.trustedrouter.com/v1",
api_key=os.environ["TRUSTEDROUTER_API_KEY"],
)
response = client.chat.completions.create(
model="gpt-5.4-mini",
messages=[{"role": "user", "content": "Say hello"}],
)Before: OpenAI
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
const response = await client.chat.completions.create({
model: "gpt-5.4-mini",
messages: [{ role: "user", content: "Say hello" }],
});After: TrustedRouter
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api-azure.trustedrouter.com/v1",
apiKey: process.env.TRUSTEDROUTER_API_KEY,
});
const response = await client.chat.completions.create({
model: "gpt-5.4-mini",
messages: [{ role: "user", content: "Say hello" }],
});Changed lines are marked +. Create a key in the console and store it as TRUSTEDROUTER_API_KEY.
Model names keep working
Send the OpenAI names you use today, dated versions included. To try another lab, use its full name from the models page.
| You send | TrustedRouter runs |
|---|---|
gpt-5.4-mini | openai/gpt-5.4-mini |
gpt-4.1-2025-04-14 | openai/gpt-4.1 |
anthropic/claude-sonnet-5.5 | Claude Sonnet 5.5 |
trustedrouter/auto | A ranked list of models, with fallback |
What works the same
OpenAI models behave as they do today. Other labs' models differ, so test each one you switch to.
| Feature | Works the same? |
|---|---|
| Chat Completions | Yes |
| Streaming | Yes |
| Tool calls | Yes, on models that support them |
| JSON output | Yes, on models that support it |
| Other labs' models | Test each one; features differ by model |
If OpenAI is down
List a backup model. If the first one fails, TrustedRouter sends the request to the next. Or use trustedrouter/auto and let the router choose. More options are in provider routing.
response = client.chat.completions.create(
model="gpt-5.4-mini",
messages=messages,
extra_body={"models": [
"gpt-5.4-mini",
"anthropic/claude-haiku-4.5",
]},
)
Zero data retention
Send prompts only to providers that keep no data. If none qualifies, the request fails before any provider sees it. It never falls back to a weaker one.
extra_body={
"provider": {"min_privacy": "zdr"},
}
Rate limits
You set your key's limits as spend caps in USD: daily, weekly or monthly. When a cap is reached or traffic is throttled, you get a 429 with Retry-After. Wait that long, then retry. See spend controls.
Test these before you switch
- Tool calls
- JSON output
- Streaming
- Rate limits and retries on 429
- Zero data retention, if you handle customer data
- The same real prompts on the old and new model: compare answers, speed and price per request
- Rollback: keep the old base URL in one setting
Read next: OpenAI compatible API, provider routing, pricing.