What is model routing in AI coding?
By Flavio
Model routing chooses which model handles a request. Learn how automatic routing differs from manual model selection and fallback in coding agents.
Model routing means choosing which model handles a request according to a policy. A coding application can make that choice automatically based on the work requested.
Which AI model is best for coding? covers choosing and testing models. Vercel AI Gateway covers routing in an application you build.
How model routing works
A router evaluates the request and selects a model from an available pool. The policy might balance capability, speed, and cost. A fixed model selection uses your chosen model instead.
Fallback handles a different event: the preferred model cannot serve the request, so the application tries another. A system can combine routing and fallback.
In coding tools
Claude Code documents opusplan, which uses Opus for planning and Sonnet for execution. That is a workflow-based choice. Its fallback model chains separately handle certain model failures.
Codex’s configuration reference documents a selected model and model_provider. Those fields select the model and provider for a session.
Cursor Router classifies requests by task and complexity when Auto uses Balance or Intelligence. The documented router is available on Teams and Enterprise. Its model pool changes over time.
Grok Build documents custom models and /model <name> to switch the active model. Automatic per-request routing is not documented in that overview.
Details checked against each vendor’s documentation in November 2026.
A concrete example
In a Claude Code terminal session, select the documented hybrid setting:
/model opusplan
Then enter plan mode and ask:
Plan a test for src/lib/ai-glossary-entries.ts.
Check that future-dated entries stay unpublished.
Wait for my review before implementing it.
Planning uses the Opus phase. After you approve and move to execution, the setting switches to Sonnet. This example uses the workflow boundary to choose a model, rather than classifying every prompt.
When to use model routing
Routing helps when routine tasks and difficult problems share one workflow. Before adopting it, compare results on your own tests. A fixed model makes comparisons easier when you need to isolate a behavior change.
Pitfalls
Keep the prompt and test cases fixed when evaluating a router. Otherwise a better result could come from better context or a different task.
Check account access and billing before enabling an automatic mode. Cursor’s optimization modes have different usage and billing behavior. Automatic selection alone tells you little about the final cost.
Related on flaviocopes.com
- Which AI model is best for coding? explains how to compare models on your code.
- Cursor guide walks through the model picker and agent workflow.
- Architecture Dissector helps you inspect the resulting architecture when an agent makes larger changes.
Related glossary entries
- Frontier model: A frontier model is one of the most capable models right now, and the label moves. How Claude Code, Codex, Cursor and Grok name the model they point you at.
- Reasoning effort: Reasoning effort sets how long a model thinks before it answers. The levels in Claude Code and Codex, what Cursor's plans fix, and how Grok sets effort.
- Evals: An eval is a fixed prompt, a real agent run, and a check you can repeat. How Claude Code, Codex, Cursor and the Grok API score that run.
Want me to talk about your product? You can sponsor this site.