⚠️ Pending Update · 2026-08-29 Verification · Content may be outdated, please refer to official docs Updated: 2026-08-29 · Status: Pending Verification
Introduction
OpenRouter is more than a model aggregator — it has built-in routing. A single request can list multiple models so the gateway falls back automatically when the primary fails, or it can distribute load across providers by preference. This means you get high availability at the gateway layer without writing your own failover logic. This article shows three patterns.
架构图
Pattern 1: Automatic Fallback
When the primary model is rate-limited or down, OpenRouter tries the next entry in the models array:
curl https://openrouter.ai/api/v1/chat/completions \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-3.5-sonnet,openai/gpt-4o-mini,meta-llama/llama-3.3-70b-instruct:free",
"messages": [{"role":"user","content":"Explain an inverted index in one sentence."}]
}'
OpenRouter tries Claude first, then GPT-4o-mini, then free Llama. The X-Openrouter-Model response header indicates which model served the request, and the provider field in the body names the actual provider.
Pattern 2: Routing Preferences
OpenRouter exposes three routing preferences:
highest_throughput: prefer the provider with the highest current throughputlowest_price: prefer the cheapest providerlowest_latency: prefer the lowest-latency provider
import os, requests
payload = {
"model": "openai/gpt-4o-mini",
"messages": [{"role": "user", "content": "hi"}],
"routing": "lowest_price"
}
headers = {
"Authorization": f"Bearer {os.environ['OPENROUTER_API_KEY']}",
"HTTP-Referer": "https://myapp.example.com",
"X-Title": "myapp",
}
r = requests.post(
"https://openrouter.ai/api/v1/chat/completions",
json=payload, headers=headers, timeout=30,
)
print(r.json()["choices"][0]["message"]["content"])
Note: HTTP-Referer and X-Title are optional but recommended headers that let your app appear on OpenRouter's leaderboard.
Pattern 3: Pin or Ignore Providers
To force a specific provider (e.g. only OpenAI direct, not Azure), use provider.order:
{
"model": "openai/gpt-4o-mini",
"messages": [{"role": "user", "content": "hi"}],
"provider": {
"order": ["OpenAI"],
"allow_fallbacks": false
}
}
Conversely, to block a provider: "ignore": ["Together"]. Combining the two gives fine-grained control over cost and latency.
Advanced: Multiple Providers for One Model
A single model name (e.g. openai/gpt-4o-mini) may have several providers behind it. Setting provider.allow_fallbacks=true makes OpenRouter switch providers automatically on failure — no code change required. The provider_name field in the response tells you which one served the request.
Troubleshooting
- Slow responses after fallback: caused by free-model queuing. Put a paid model first.
routingfield ignored: make sure the model actually has multiple providers; otherwise it has no effect.- Pin a specific provider: use the
provider.orderfield to force an order. - Different prices for same model: providers may price the same model differently.
lowest_pricepicks the cheapest automatically.
Combining fallback, routing, and provider filtering maximizes availability within free-tier limits.
Routing Configuration Example
{
"model": "deepseek/deepseek-chat:free",
"fallback": ["meta-llama/llama-3.3-70b:free", "google/gemini-2.0-flash:free"],
"routing": {
"on_429": "fallback",
"on_5xx": "fallback",
"on_timeout": "fail"
}
}
Best Practices
- Cap fallback chains at 3: each layer doubles latency; 3 layers is near the user-patience limit.
- Same model, multiple providers: back up each model with both OpenRouter and the original (e.g. DeepSeek direct) so one provider outage does not break you.
- Add a cache layer: Redis 60-second cache catches duplicate requests when free tier hits 429.
🚀 Get Started: One-Click Free API Access
Want to call all the free models above with a single API key, no need to sign up for each provider? Apishare.cc provides a unified API Key — one key, 100+ models, free models at zero cost.
👉 Register on Apishare.cc → Get your unified API Key
📊 Want to see more free model rankings? Check out the Sep 2026 Free LLM API Rankings →
Get Started: APIShare Free API Directory
- Claim free credits: Register · Sign in
- Browse all free APIs: Free API Directory
About the Free API Aggregator
The models covered in this guide are all served through the APIShare free API aggregator, which gives you one key for the whole catalog.
- Full model catalog: APIShare free API directory
- Sign up for a free trial key: Register and claim your API key