LLM routing: how to pick a model for every request
LLM routing decides which provider and model serve each request. Five strategies, what each one costs, and why provider caches should shape your rules.
- Published
- Reading time
- 10 min read
In short
- LLM routing is the decision, made before each call, about which provider and model serve a request. Failover is a different job: it runs after a call has already failed.
- Start with rules you can read: a fixed mapping, a weighted split for canaries, and conditions on team, tier, or header. Add a learned or classifier-based router only when you have evaluation data to train and check it.
- Cost routing works because model prices differ by orders of magnitude, but the classifier adds its own latency and its own mistakes to every request it judges.
- Provider prompt caches are isolated by organization, and on Anthropic's API by workspace, so a router that moves a conversation to another provider or account pays full input price again. Keep each session on one target.
LLM routing is the decision, made for each request, about which provider and which model will serve it. The rule usually lives in an LLM gateway, so applications ask for a logical name like support-default and the gateway resolves it to a real target at call time.
Every team that calls more than one model does LLM routing, even if it is an if statement in application code. The useful questions are which signals the router reads, how you check that it chose well, and what it costs when it chooses badly.
What LLM routing decides, and what it does not
LLM routing picks a target before the call is made. Load balancing spreads traffic across targets that are interchangeable. Failover reacts after a call has failed. The three are often configured in the same file, but they answer different questions and fail in different ways, so keep them apart when you design and debug.
| Job | The question it answers | When it runs | What it reads |
|---|---|---|---|
| Routing | Which model should serve this request? | Before the call | The request: model name, headers, team, content |
| Load balancing | Which of several equivalent targets has capacity? | Before the call | Weights, key quotas, health |
| Failover | Where does this request go now that the first try failed? | After an error or timeout | The error class |
A router that sends a hard question to a weak model returns a bad answer with a 200 status. Nothing retries it. That is why routing mistakes are harder to see than failover mistakes, and why every routing strategy below needs a way to measure quality per target.
Static mapping: one name, one target
The simplest router maps a logical model name to one provider and model. Applications request summarize-fast; the gateway config says that means a particular small model on a particular provider. Changing the target is a config change, not a deploy.
This sounds too simple to count as routing, and it is still the most valuable step. It moves the choice of model out of application code, so a price change or a model retirement is handled in one place. It also gives you a stable name to attach budgets, dashboards, and evaluation results to.
What it costs is adaptability. A static map does not react to load, price, or the content of the request. Start here anyway. Every other strategy is a refinement of a mapping you already have.
Weighted splits for canaries and LLM load balancing
A weighted split sends a fixed share of traffic to each of several targets. A 95/5 split is the standard way to canary a new model: most users stay on the current one while a small slice shows you how the new one behaves on real traffic.
The same mechanism handles LLM load balancing. If one provider account keeps hitting its tokens-per-minute limit, splitting traffic across two keys or two providers raises the ceiling without any change in the application.
Splits have three costs that are easy to miss:
- Two models give two styles of answer. Users who send the same request twice may notice.
- Each target needs its own metrics. An average across a 95/5 split hides a canary that fails 30% of the time.
- Different models use different tokenizers and prices, so cost per request is no longer one number.
Keep splits short-lived for canaries. A permanent 50/50 split across different models is usually a decision nobody made.
Rule-based routing on team, tier, and headers
Rule-based routing evaluates conditions on the request, in priority order, and the first rule that matches picks the target. Typical conditions are the calling team, a customer tier, a header the application sets, or how much of a budget is already spent.
Rules are the right default for most LLM routing because you can read them. When a user asks why their request went to a given model, the answer is a line of config, not a model's opinion.
Bifrost, an open-source AI gateway by Maxim AI, is a good example of how far plain rules go. Its routing rules are written as CEL expressions and checked by scope, from virtual key to team to customer to global. Within a scope, rules run in ascending priority and the first match wins. A matching rule can name several weighted targets and a fallback list.
{
"name": "premium-tier",
"enabled": true,
"cel_expression": "headers[\"x-tier\"] == \"premium\"",
"targets": [
{ "provider": "anthropic", "model": "claude-opus-5-5", "weight": 0.9 },
{ "provider": "anthropic", "model": "claude-sonnet-5-5", "weight": 0.1 }
],
"fallbacks": ["openai/gpt-5.6"],
"scope": "global",
"priority": 10
}Two details in that design are worth copying whatever gateway you use. Rule variables include how much of a budget or token limit is already used, so a rule like budget_used > 85 can move traffic to a cheaper model before the budget runs out. And for streaming requests a ttft_timeout_ms setting moves to the next fallback when no first token arrives in time, which turns a slow provider into a failover event instead of a hung request.
The cost of rules is upkeep. Rules accumulate, and a rule that no longer matches anything still runs. Give each one a name, leave gaps in the priority numbers so you can insert rules later, and review the set when you review budgets.
Cost routing and auto routing: send easy requests to cheaper models
Cost routing, often sold as auto routing, sends each request to the cheapest model that can handle it. A classifier looks at the request and predicts whether a small model is good enough or the request needs a large one.
The economics are real. The FrugalGPT paper found that API prices for popular models differ by two orders of magnitude, and that a cascade of cheaper and stronger models could match the best single model with up to 98% lower cost on the benchmarks it tested. The RouteLLM paper trained routers on human preference data and reported cutting costs by over 2 times in some cases without lowering response quality.
The costs are also real, and they land on every request the router judges:
- Latency. A classifier is another model call, or at least an embedding and a lookup, in front of the real one.
- Misroutes. A request the classifier underrates goes to a model that cannot answer it, and the user gets a confident wrong answer.
- Drift. A router trained on last quarter's traffic does not know about this quarter's new feature.
Bifrost's Complexity Router shows the latency trade-off plainly. It labels each request Simple, Medium, or Complex so routing rules can act on the tier. Its decision-model classifier typically takes 600 to 800 milliseconds per request. The semantic classifier, which compares the request with reference phrases, is much faster. Classification runs only when a rule actually references the tier, so traffic that does not need it pays nothing.
That 600 to 800 milliseconds settles where cost routing belongs. It suits batch jobs and long agent runs, where the call itself takes many seconds and the saving is large. It is a poor fit for a chat interface where users feel every added half second before the first token.
Latency-aware routing and the herd problem
Latency-aware routing sends traffic to whichever target has been fastest recently. It helps when providers degrade unevenly, which they do, and it hurts when every router makes the same choice at once.
If all traffic moves to the fastest provider, that provider gets slower, the routers move everything back, and the cycle repeats. Avoid winner-take-all choices. Adjust weights gradually from smoothed error rates and latency percentiles, and keep a floor of traffic on every healthy target so you keep measuring it.
Bifrost Enterprise takes this approach with adaptive load balancing, which recomputes provider and key weights from latency and error signals, plus a circuit breaker that stops sending to a degraded endpoint. If you build your own, measure the right number. Time to first token is what users feel on a streamed response; total duration mostly reflects how long the answer is.
Why routing must respect provider prompt caches
Provider prompt caches belong to one account at one provider. Anthropic isolates caches between organizations and, on the Claude API, between workspaces. OpenAI says caches are not shared across organizations. A router that moves a conversation to another provider or another key loses the cache that the conversation has been warming.
That matters more than most routing gains. Prompt caching bills cached reads at a fraction of the input price, and an agent's prefix can be tens of thousands of tokens. A per-request router that alternates targets across a 40-turn session pays for a fresh cache write every time it switches.
The fix is session affinity: route the first request of a session, then keep the rest of the session on the same provider and key. Bifrost implements this as session affinity. The x-bf-session-id header identifies the session, the binding lasts one hour by default and refreshes on each request, and session headers sent by coding agents such as Claude Code and Codex CLI are picked up without configuration. Routing rules still decide which targets are allowed; affinity only decides which allowed target is tried first.
Which LLM routing strategy to start with
Start with the cheapest strategy that solves a problem you have, and add the next one only when you can measure what it changes.
| Strategy | Use it when | What it costs |
|---|---|---|
| Static mapping | Always. It is the base for everything else | Nothing. It does not adapt |
| Weighted split | Canarying a model, or spreading load across keys and providers | Per-target metrics, mixed answer styles |
| Rules on team, tier, header | Different callers need different models or budgets | Config upkeep |
| Cost or auto routing | Long or batch workloads with many easy requests and an evaluation set | Classifier latency, misroutes, retraining |
| Latency-aware weights | Providers degrade unevenly and you serve real-time traffic | Tuning, and herding if done naively |
The order is deliberate. Every LLM routing step after the first needs per-target quality data, so the work that pays for routing is the evaluation you run on each target. LLM evaluation covers how to build that suite, and what to record on every request covers the fields that let you split it by target.
Frequently asked questions
What is LLM routing?
LLM routing is the practice of choosing, for each request, which provider and model will serve it. The choice can come from a fixed mapping, a weighted split, rules on the request's team or headers, or a classifier that estimates how hard the request is. It usually runs in a gateway so that applications use one logical model name and the routing logic lives in one place.
What is the difference between LLM routing and load balancing?
Routing chooses the right model for a request by reading the request. Load balancing spreads requests across targets that are treated as equivalent, such as two API keys for the same model, to stay under rate limits. Most production setups do both: a rule picks the model, then load balancing picks which key or deployment serves it.
What is auto routing?
Auto routing is cost routing done by a model. A classifier or a small model reads each request and sends it to a cheaper model when it predicts the request is easy, and to a stronger one when it is hard. It saves money on workloads with many easy requests, and it adds the classifier's latency and error rate to every request it judges.
Does a model router add latency?
A rule-based router adds almost none, because evaluating a few conditions in memory takes microseconds next to a model call. A classifier-based router adds a full model call or an embedding lookup before the real request. Bifrost's decision-model classifier, for example, typically takes 600 to 800 milliseconds, which is acceptable for batch work and noticeable in chat.
How do you know if a router picked the wrong model?
You compare quality per target. Tag every request with the model that served it and the rule that chose it, run your evaluation checks on a sample of each target's traffic, and look for targets or rules whose scores fall below the rest. A misroute rarely produces an error, so a status-code dashboard will not show it.
Is model routing the same as failover?
No. Model routing picks a target before the call. Failover runs after a call fails and decides where to send the retry. They share configuration in most gateways, including the fallback list on a routing rule, but a routing mistake returns a bad answer while a failover mistake returns an error or a timeout.
Sources
- 01RouteLLM: Learning to Route LLMs with Preference DataarXiv:2406.18665
- 02FrugalGPT: How to Use Large Language Models While Reducing Cost and Improving PerformancearXiv:2305.05176
- 03Prompt cachingClaude API docs
- 04Prompt cachingOpenAI API docs
- 05Routing rulesBifrost docs
- 06Complexity routerBifrost docs
- 07Session affinityBifrost docs