What is an LLM router?
Definition
An LLM router is a component that picks which language model should answer each request, before the call is made. It sends simple prompts to smaller, cheaper models and hard ones to stronger models, using rules, a trained classifier or a routing model, aiming to cut cost and latency without a drop in answer quality.
How does an LLM router decide which model answers?
Routers make one decision per request: which model should answer this prompt, given quality, cost and latency. They differ in how they make it.
| Router type | How it decides | Example |
|---|---|---|
| Rules | Fixed conditions: task type, prompt length, user tier, keywords | "Classification goes to the small model" |
| Trained classifier | A trained model scores how much a request needs the strong model; a threshold sets the cut | RouteLLM routers, trained on human preference data |
| Rating by a fast model | A fast model rates the request, then a policy weighs that rating against prices and benchmarks | OpenRouter Auto Router |
| Managed routing model | A provider-trained model picks from a pool of models, within a chosen mode | Microsoft Foundry model router |
RouteLLM (Ong et al., last revised February 23, 2025, an older source) is the open research version. It trains routers that "dynamically select between a stronger and a weaker LLM during inference" and reports cost cuts of "over 2 times in certain cases" with little loss of response quality on its benchmarks. Its Apache-2.0 code repository (last updated August 2024) exposes the trade-off as a cost threshold, which it recommends calibrating on your own queries. Its README example asks for 50% of calls to go to the strong model and gets a threshold of 0.11593.
OpenRouter's Auto Router (doc updated November 16, 2026) shows the rating approach. A fast decision model "rates eleven aspects of the request in one call", such as task type, difficulty and whether speed matters. A routing policy then weighs that rating "against live prices, cache status, and benchmark performance" to pick both a model and a reasoning effort.
How is an LLM router different from a gateway or a cascade?
| LLM router | LLM gateway | Model cascade | |
|---|---|---|---|
| Decides | Which model should answer this request | How a call reaches a provider: keys, budgets, failover, logs | Whether a cheap answer is good enough, after seeing it |
| When | Before the call | Around every call | After the first call, sometimes several |
| Calls per request | One | One, plus retries or fallbacks | One to several |
| Main risk | Sending a hard request to a weak model | Becoming a single point of failure | Paying twice when the first answer is rejected |
The two can ship together. A router can run as a feature inside a gateway, and a gateway's fallback list is a simple, failure-driven kind of routing.
FrugalGPT (Chen, Zaharia, Zou, May 2023, an older source) describes the cascade: it "sends a query to a list of LLM APIs sequentially", and a scoring function rates each answer. If the answer is reliable it is returned; otherwise the next model is asked. The paper reports that FrugalGPT can match the best single model (for example GPT-4) "with up to 98% cost reduction". A router skips the first attempt; a cascade can judge the actual answer.
Example: score a router on your eval set before it sees traffic
Router benchmarks measure someone else's prompts. Before you route real traffic, run your own labeled requests through every policy you are considering. The script below does that for a toy router. The scores, the right and wrong answers, and the costs are all made up, so the logic is easy to follow.
# Score a router on a labeled eval set before it touches production traffic.
# Everything below is made up for illustration: the router scores, which model got each answer right,
# and the costs (relative units: the small model costs 1 per request, the large one 20).
SMALL, LARGE = 1, 20
# (request, router score = how likely the request needs the large model, small correct?, large correct?)
evals = [
("reset my password", 0.05, True, True),
("what are your opening hours", 0.08, True, True),
("translate 'invoice' to German", 0.12, True, True),
("summarize this 2-line ticket", 0.20, True, True),
("classify ticket: billing or tech", 0.25, True, True),
("extract the order ID from this email", 0.31, False, True),
("draft a polite refund refusal", 0.42, True, True),
("why did invoice 42 total change", 0.55, False, True),
("compare plans A and B for 30 seats", 0.61, True, True),
("find the bug in this SQL query", 0.74, False, True),
("plan a migration from v1 to v2 API", 0.86, False, False),
("refactor this 200-line function", 0.93, False, True),
]
def run(threshold):
"""Requests scoring at or above the threshold go to the large model."""
large = [e for e in evals if e[1] >= threshold]
correct = sum(e[3] if e[1] >= threshold else e[2] for e in evals)
cost = sum(LARGE if e[1] >= threshold else SMALL for e in evals)
return len(large), correct, cost
print(f"{'policy':<22}{'large calls':>12}{'correct':>9}{'cost':>6}")
for name, t in [("always small", 1.01), ("router, t=0.70", 0.70),
("router, t=0.50", 0.50), ("router, t=0.30", 0.30), ("always large", 0.0)]:
n, ok, cost = run(t)
print(f"{name:<22}{n:>8}/{len(evals)}{ok:>7}/{len(evals)}{cost:>6}")
# What the router got wrong at t=0.50: sent to the small model, which failed, while the large one would have passed.
print("misrouted at t=0.50:", [e[0] for e in evals if e[1] < 0.50 and not e[2] and e[3]])
Output of python3 route.py (Python 3.11):
policy large calls correct cost
always small 0/12 7/12 12
router, t=0.70 3/12 9/12 69
router, t=0.50 5/12 10/12 107
router, t=0.30 7/12 11/12 145
always large 12/12 11/12 240
misrouted at t=0.50: ['extract the order ID from this email']
At a threshold of 0.30 the toy router matches the always-large accuracy (11 of 12) at 145 cost units instead of 240. At 0.50 it saves more but loses one answer, and the last line names it, so you can see which kind of request the router underrates. One request fails on both models: routing cannot fix what no model in the pool can do. On real data, replace the made-up columns with your router's scores and your graders' verdicts, using the same AI evals you already run.
What do managed LLM routers add, and what do they limit?
Microsoft's model router documentation (updated November 18, 2026) shows the trade-offs of a managed router in one page:
- Modes instead of thresholds. Balanced, the default, considers models within a small quality range of the best one (the docs give 1 to 2% as an example) and picks the most cost-effective. Cost mode widens the band, for example to 5 to 6%. Quality mode ignores cost.
- The smallest context window wins. "The effective context window is the smallest context window among the models in your pool."
- Parameters can disappear. When the selected model does not support an optional parameter, such as temperature on a reasoning model, the router drops it.
- Routing is not free. You pay a routing fee per 1 million input tokens, plus the selected model's usage.
- The answering model is visible. Each response's model field names the model that answered.
OpenRouter adds hard limits on the pool with allowed_models and excluded_models, and a cost_tier setting of low, medium or high. Both services can keep a conversation on one model (Microsoft's session affinity is in preview), because switching models loses prompt-cache hits.
What should you check before routing production traffic?
- Every model in the pool passes your evals. A router that can pick a model nobody tested ships an untested release.
- The threshold is calibrated on your traffic, not on a benchmark, and recalibrated when your mix of requests changes.
- The answering model is logged with each request, next to cost and latency, so a quality drop can be traced to a routing change.
- Context, tools and parameters fit every routable model, or the pool is narrowed to models that support them.
- Total cost includes the router. Count routing fees, the classifier call and lost cache hits, then compare with a single-model baseline.
- Data rules hold for every model. Check where each model in the pool processes data before it can receive a request.
For the token prices behind these choices, see inference cost. In our generative AI development work, simple requests go to smaller models, repeated work is cached, and token budgets carry alerts. Any routing change is scored on an evaluation set from your own cases before it ships.
Sources
- RouteLLM: Learning to Route LLMs with Preference Data, arXiv (Ong, Almahairi and others; UC Berkeley, Anyscale, Canva), 2025-02-23
- RouteLLM, LMSYS on GitHub, 2024-08-10
- FrugalGPT: How to Use Large Language Models While Reducing Cost and Improving Performance, arXiv (Chen, Zaharia, Zou), 2023-05-09
- What is model router?, Microsoft Learn (Microsoft Foundry), 2026-11-18
- Auto Router, OpenRouter docs, 2026-11-16
- Deprecations, OpenAI API docs, 2026-11-18
Frequently asked questions
Does an LLM router add latency?
Yes, a little: the routing decision runs before the model call, and a classifier or rating model is an extra step. It can still lower average latency when many requests go to faster, smaller models.
Can I build an LLM router myself?
A rules-based router is a few lines of code in your model layer. A learned router needs labeled data on which model answered which requests well, plus a way to recalibrate it as models and traffic change.
Is there an open-source LLM router?
Yes. RouteLLM from LMSYS is Apache-2.0 licensed and ships trained routers, an OpenAI-compatible server and tools to calibrate the routing threshold. Its repository was last updated in August 2024, and its README examples use gpt-4-1106-preview, which OpenAI shut down on October 23, 2026, so expect to change the model pair and recalibrate the threshold.
Does routing work for agents?
It can: each step of an agent may get a different model, a fast one for a short classification and a stronger one for planning. Keep a conversation on one model where you can, since switching loses prompt-cache hits.
Services
Related terms
Mikhail BodnarchukFounder of Codeception and CodeceptJSBoth are open-source testing frameworks: Codeception for PHP, CodeceptJS for JavaScript.LinkedInGitHub