All use cases
Uptime
Keep an agent up when a provider goes down
List backup models in one request. If the primary model's providers are down or rate-limited, AnyRouter tries the next model.
01
The problem
What this is for
An agent pinned to one model stops mid-task during a provider outage or a 429 burst. Retry loops in your code add latency and still hit the same provider.
02
What to do
Three steps, then copy
- 1.Keep your primary model in model.
- 2.Add backup ids in models, in the order you want them tried. Fallbacks run on /api/v1/chat/completions.
- 3.Read the model field in the response to see which one answered. Or use anyrouter/auto and let AnyRouter pick a healthy model.
curl · models fallback
bash
curl https://anyrouter.dev/api/v1/chat/completions \
-H "Authorization: Bearer $ANYROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-5.4-mini",
"models": ["anthropic/claude-sonnet-4.6", "z-ai/glm-4.7-flash"],
"messages": [{ "role": "user", "content": "Plan the next step." }]
}'AI SDK
ts
import { createAnyRouter } from "@anyr/ai-sdk-provider"
import { generateText } from "ai"
const anyrouter = createAnyRouter()
const { text } = await generateText({
model: anyrouter("openai/gpt-5.4-mini"),
prompt: "Plan the next step.",
providerOptions: {
anyrouter: {
extraBody: { models: ["anthropic/claude-sonnet-4.6", "z-ai/glm-4.7-flash"] },
},
},
})
console.log(text)Ready to try it
The guide has the full walkthrough. Sign up if you still need a key.
Related
Next playbooks
AUTO
Start on anyrouter/free or anyrouter/auto
Two built-in virtual models: Go+ free failover (anyrouter/free) and stable paid failover (anyrouter/auto). Do not pick a flaky SKU for your first request.
OpenRun Hermes Agent on AnyRouter
An open-source agent with 40+ tools. Swap the base URL once and it can call the catalog — start on anyrouter/auto.
OpenRun the Claude Agent SDK on any model
query() already reads ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY. Point both at AnyRouter — no SDK fork.
Open