Skip to content
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. 1.Keep your primary model in model.
  2. 2.Add backup ids in models, in the order you want them tried. Fallbacks run on /api/v1/chat/completions.
  3. 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.