OpenRouter Model Fallback and Provider Ordering
Use OpenRouter's request-level models array and provider preferences for automatic failover.
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
- Create an OpenRouter API key and export it as
OPENROUTER_API_KEY. - List your models in priority order in the
modelsarray (check slugs at openrouter.ai/models). - Set
providerpreferences (order, fallbacks, data collection) to control which hosts serve each model. - Send the request and log the response's
modelfield.
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.jsonThe response's model field tells you which model actually answered; log it. Verify current slugs at openrouter.ai/models.
Failure modes
- Model slugs get retired; check openrouter.ai/models.
- Fallback model differs in behavior and price; log the answering model.
- Provider restrictions that are too strict leave no available route.
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.
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
Complexity-Based Cheap/Strong Model Router
Route easy requests to a cheap model and hard ones to a strong model using a lightweight classifier plus escalation.
LiteLLM Proxy with Fallbacks and Load Balancing
An OpenAI-compatible gateway that load-balances deployments and falls back across providers on errors.
Local-First Routing with Ollama and Cloud Fallback
Serve requests from a local Ollama model, falling back to a cloud model only when local fails or the task needs it.