OpenRouter
Move OpenRouter Chat Completions requests to AnyRouter, including provider preferences for ordering, price caps, and fallbacks.
Moving from OpenRouter is mostly a base-URL and key change. AnyRouter accepts the same provider/model ids and the same request-level provider preferences on its OpenAI-compatible endpoints, so your ordering, price caps, and fallback settings carry over unchanged.
Before you start
- An AnyRouter API key (prefixed
sk-ar-). Create one in the dashboard. - An existing OpenRouter integration built on the OpenAI-compatible client.
Your HTTP-Referer and X-Title headers can stay — AnyRouter reads both for dashboard attribution, so no header changes are needed.
What changes
| Setting | Before (OpenRouter) | After (AnyRouter) |
|---|---|---|
| Base URL | https://openrouter.ai/api/v1 | https://anyrouter.dev/api/v1 |
| API key | OpenRouter key | Your AnyRouter key, prefixed sk-ar- |
| Model | provider/model | provider/model from the AnyRouter catalog |
| Provider preferences | provider object | provider object — same fields |
Before and after
The client swap is a base URL and key change; model ids keep the provider/model form.
import OpenAI from "openai"
const client = new OpenAI({
baseURL: "https://openrouter.ai/api/v1",
apiKey: process.env.OPENROUTER_API_KEY,
})
const completion = await client.chat.completions.create({
model: "anthropic/claude-sonnet-4.6",
messages: [{ role: "user", content: "Summarize this support thread." }],
})
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: "anthropic/claude-sonnet-4.6",
messages: [{ role: "user", content: "Summarize this support thread." }],
})
Migrate
Swap the base URL and key
Change the base URL from https://openrouter.ai/api/v1 to https://anyrouter.dev/api/v1, and use your AnyRouter key (prefixed sk-ar-).
Verify each model id exists
Model ids keep the same provider/model form. Confirm each one is in the AnyRouter catalog by listing Models.
Keep your provider preferences
Request-level provider preferences carry over unchanged: only, ignore, order, sort, max_price, and allow_fallbacks. Leave them as they are.
Provider preferences
Use only to allowlist, ignore to exclude, order to pin a preference order, and sort to choose the strategy:
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": "Draft a changelog entry."}],
"provider": {
"only": ["OpenAI", "Groq"],
"order": ["Groq", "OpenAI"],
"sort": "latency",
"allow_fallbacks": true
}
}'
Price caps
Filter out upstreams above your budget. Prices are dollars per 1M tokens:
{
"provider": {
"sort": "price",
"max_price": { "prompt": "1.00", "completion": "4.00" },
"allow_fallbacks": true
}
}
If every route is filtered out, the request fails — AnyRouter never silently ignores a price ceiling.
Disable fallbacks
Fallbacks are on by default. Turn them off when reproducibility matters more than availability (an eval run against a fixed upstream):
{ "provider": { "allow_fallbacks": false } }
Verify
Send one request with your new key and confirm you get a reply:
curl https://anyrouter.dev/api/v1/chat/completions \
-H "Authorization: Bearer sk-ar-your-key" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-sonnet-4.6",
"messages": [{"role": "user", "content": "Say hello in one sentence."}]
}'
Migrate with an agent prompt
Paste this into a coding agent (Claude Code, Cursor, Codex, …) to do the swap:
Migrate this project from OpenRouter to AnyRouter.
1. Change the OpenAI client base URL from https://openrouter.ai/api/v1
to https://anyrouter.dev/api/v1
2. Swap the OpenRouter key for ANYROUTER_API_KEY (prefix sk-ar-). Never hardcode it.
3. Model ids keep the same provider/model form — verify each id exists in the
AnyRouter catalog at https://anyrouter.dev/api/v1/models
4. Request-level `provider` preferences (only / ignore / order / sort /
max_price / allow_fallbacks) are supported — keep them as they are.
5. Leave your HTTP-Referer and X-Title headers as-is — AnyRouter reads both for
dashboard attribution, so no header changes are needed.
6. Keep streaming and error handling unchanged.
7. Add a smoke test that sends one short prompt and prints the reply.
Only swap the provider config — do not change UI or business logic.
Troubleshooting
A model id returns 404
The provider/model id must exist in the AnyRouter catalog. Some OpenRouter ids differ — list Models and pick the matching AnyRouter id.
My price cap is being ignored
It isn't — max_price is a hard filter. If no upstream fits your ceiling, the request fails rather than routing to a more expensive provider. Loosen the cap or set allow_fallbacks: true.
Related
- Smart Routing — how AnyRouter picks an upstream.
- Provider Routing — every
providerfield in detail. - Models API — list every available model.
- AnyRouter vs OpenRouter — honest side-by-side.
- OpenRouter alternative — checklist of markup, BYOK, billing, and lock-in.