OpenRouter Model Fallback and Provider Ordering

Use OpenRouter's request-level models array and provider preferences for automatic failover.

openrouterfallbacksprovider-routing
Setup time15 minutes (estimate)
Estimated costPay-per-token at OpenRouter's listed model prices.
VerificationLast verified 2026-10-14

OpenRouter accepts a models array: if the first model errors (rate limit, downtime, moderation), it tries the next. provider preferences control which upstream hosts serve a model.

Steps

  1. Create an OpenRouter API key and export it as OPENROUTER_API_KEY.
  2. List your models in priority order in the models array (check slugs at openrouter.ai/models).
  3. Set provider preferences (order, fallbacks, data collection) to control which hosts serve each model.
  4. Send the request and log the response's model field.

Request

{
  "models": ["anthropic/claude-sonnet-5.5", "openai/gpt-6-sol", "meta-llama/llama-3.1-70b-instruct"],
  "messages": [{"role": "user", "content": "Summarize this changelog..."}],
  "provider": {
    "order": ["Anthropic", "OpenAI"],
    "allow_fallbacks": true,
    "data_collection": "deny"
  }
}
curl https://openrouter.ai/api/v1/chat/completions \
  -H "Authorization: Bearer $OPENROUTER_API_KEY" \
  -H 'Content-Type: application/json' -d @request.json

The response's model field tells you which model actually answered; log it. Verify current slugs at openrouter.ai/models.

Failure modes

Markdown version: /blueprints/openrouter-fallback-models.md

Want a deeper build of this?

Vote for an extended, fully tested version (more tools, a full workflow file). Votes decide what we build next.

– votes

Get one fully built blueprint a week

A weekly email: one blueprint with config, cost, setup time and failure modes, plus a vote on what we build next.

Related blueprints