OpenRouter model routing
OpenRouter model routing is picking a primary model slug plus optional models fallback list so cheap tiers handle routine work and capable models only run on failure or escalation.
Hub: Tokenminning with OpenRouter. Pattern: Model routing.
Fallback array pattern
Cheaper model first, capable model second:
{
"model": "anthropic/claude-haiku-4-20250514",
"models": ["anthropic/claude-haiku-4-20250514", "anthropic/claude-sonnet-4-5"]
}In Python OpenAI SDK:
client.chat.completions.create(
model="anthropic/claude-haiku-4-20250514",
extra_body={"models": [
"anthropic/claude-haiku-4-20250514",
"anthropic/claude-sonnet-4-5",
]},
messages=[...],
)OpenRouter bills only the model that succeeds. Failed primary attempts on rate limits/errors fall through without charge.
Tier selection
| Task | Start slug tier |
|---|---|
| Classification, grep, single-file | Haiku / flash / mini |
| Multi-step agent work | Sonnet / GPT-4.1 class |
| Deep debug, architecture | Opus / o3 / thinking — last resort |
Search current pricing on openrouter.ai/models — rates change.
Provider sorting
{
"provider": {
"sort": "price"
}
}sort | When |
|---|---|
price | Default — cost-sensitive agent loops |
throughput | Latency-sensitive, budgeted |
latency | Interactive UX (still cap keys) |
Avoid openrouter/auto and :nitro variants until you understand your traffic mix — unpredictable tier and cost.
Wire to tools
| Tool | Config surface |
|---|---|
| OpenCode | opencode.json model + agent overrides |
| Cline | Model picker + OpenRouter base URL |
| Aider | .aider.conf.yml model: openrouter/... |
Use one OpenRouter key per tool or environment — Activity.
Cline + OpenRouter
Queries like cline openrouter usually mean wiring VS Code Cline to https://openrouter.ai/api/v1 with a dedicated key and haiku-first model list. Same fallback and cap patterns apply.
Troubleshooting
Always billed for expensive model — primary is frontier; fallbacks never run. Set primary to haiku.
Context length errors — add larger model as second models entry.
Bill spike overnight — one key, runaway loop. Lower cap; haiku-only on that key.