Migrate from OpenAI
Move an OpenAI Chat Completions or Responses client to AnyRouter by changing the base URL, API key, and model id.
Change the base URL, API key, and model id; your chat.completions and responses calls stay the same.
What changes
| Setting | Before | After |
|---|---|---|
| Base URL | https://api.openai.com/v1 | https://anyrouter.dev/api/v1 |
| API key | OPENAI_API_KEY | AnyRouter key (sk-ar-...) from the dashboard |
| Model | gpt-4o-mini, gpt-4o | openai/gpt-5.4-mini, openai/gpt-5.4, or any id from the catalog |
typescript
import OpenAI from "openai"
const client = new OpenAI({
baseURL: "https://anyrouter.dev/api/v1",
apiKey: process.env.ANYROUTER_API_KEY,
})
const completion = await client.chat.completions.create({
model: "openai/gpt-5.4-mini",
messages: [{ role: "user", content: "Summarize this pull request." }],
})
// Responses works with the same client
const response = await client.responses.create({
model: "openai/gpt-5.4-mini",
input: "Extract the action items from this transcript.",
})Verify
bash
curl https://anyrouter.dev/api/v1/chat/completions \
-H "Authorization: Bearer sk-ar-your-key" \
-H "Content-Type: application/json" \
-d '{"model": "openai/gpt-5.4-mini", "messages": [{"role": "user", "content": "Write a release note."}]}'List models with GET https://anyrouter.dev/api/v1/models.
Routing preferences (optional)
Add a provider block to cap price, prefer latency, or set upstream order. All fields are in Provider Routing.
json
{ "provider": { "sort": "latency", "max_price": { "prompt": "2.00", "completion": "8.00" }, "allow_fallbacks": true } }Troubleshooting
| Symptom | Fix |
|---|---|
| 401 Unauthorized | Send Authorization: Bearer sk-ar-.... An OPENAI_API_KEY does not work here. |
| 404 for the model | Include the owner, for example openai/gpt-5.4-mini. Check Models. |
AnyRouter routes requests to third-party models. Models and outputs are provided as is, with no warranty; you use them at your own risk. Disclaimer