Skip to Content
IDEsOpenRouterModel routing

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

TaskStart slug tier
Classification, grep, single-fileHaiku / flash / mini
Multi-step agent workSonnet / GPT-4.1 class
Deep debug, architectureOpus / o3 / thinking — last resort

Search current pricing on openrouter.ai/models  — rates change.

Provider sorting

{ "provider": { "sort": "price" } }
sortWhen
priceDefault — cost-sensitive agent loops
throughputLatency-sensitive, budgeted
latencyInteractive UX (still cap keys)

Avoid openrouter/auto and :nitro variants until you understand your traffic mix — unpredictable tier and cost.

Wire to tools

ToolConfig surface
OpenCodeopencode.json model + agent overrides
ClineModel 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.

Last updated on