If you are building an application that uses large language models, chances are you have already hit the same wall most teams hit: one model is great at code, another handles creative writing better, and a third is cheaper for simple classification tasks. An LLM router sits between your application and multiple models, directing each request to the best model for the job.
It sounds like a small architectural decision. In practice, it is one of the most impactful choices you can make for cost, latency, and output quality.
TL;DR
- An LLM router is middleware that directs prompts to different language models based on task type, complexity, cost, or latency requirements
- Routing can cut LLM costs by 50-80% by sending simple tasks to cheaper models and reserving expensive ones for complex work
- Common routing strategies include rule-based, classifier-based, and cascade (try cheap first, escalate if needed)
- You should consider a router once you are using more than one model or spending over a few hundred euros per month on API calls
- Open-source options like RouteLLM, LiteLLM, and Martian exist, but many teams build custom routers tailored to their specific workloads
What Is an LLM Router?
At its simplest, an LLM router is a layer that sits between your application code and one or more LLM providers. When your app sends a prompt, the router decides which model should handle it, sends the request, and returns the response through a unified interface.
Think of it like a load balancer, but instead of distributing traffic evenly, it distributes intelligently. A customer support query asking “what are your opening hours?” does not need the same model as a request to analyse a complex legal contract.
The router typically evaluates some combination of:
- Task complexity — simple lookups vs multi-step reasoning
- Required capability — code generation, creative writing, structured data extraction
- Cost constraints — budget per request or per user tier
- Latency requirements — real-time chat vs batch processing
- Model availability — failover when a provider is down or rate-limited
Why You Need One (and When You Don’t)
If your entire application runs on a single model and you are happy with the cost and quality, you probably do not need a router yet. Keep it simple.
But the moment any of these become true, routing earns its place:
- You are using multiple models and switching between them manually in code with if/else blocks
- Your LLM bill is growing and you know that 70% of your requests are simple enough for a smaller, cheaper model
- Latency matters and you want fast responses for straightforward queries while still having access to powerful models for hard problems
- Reliability is critical and you need automatic failover when one provider goes down
- You are building a product with different user tiers (free users get a fast small model, paying users get the flagship)
Routing Strategies
1. Rule-Based Routing
The simplest approach. You define explicit rules: if the prompt is under 100 tokens and tagged as FAQ, send to Model A. If it contains code, send to Model B. If it is a summarisation task, send to Model C.
This works well when your use cases are clearly defined and limited in number. It is easy to understand, easy to debug, and has zero overhead. The downside is it does not adapt, and edge cases pile up fast.
2. Classifier-Based Routing
A lightweight classifier (often a small model itself, or even a logistic regression) analyses each incoming prompt and categorises it. The category determines the model. This is more flexible than rules and can handle ambiguous inputs better.
The trade-off is that you now have a classifier to train and maintain. If your classifier gets it wrong, you send a complex prompt to a cheap model and get a poor result. Monitoring accuracy is essential.
3. Cascade Routing
Start with the cheapest model. If the response meets a quality threshold (confidence score, format validation, or a quick evaluation), use it. If not, escalate to a more capable model. This is sometimes called the “waterfall” approach.
Cascading is excellent for cost optimisation. The cheap model handles the easy 60-70% of requests, and you only pay premium prices for the genuinely hard ones. The downside is added latency when escalation happens, since you are now making two API calls.
4. Semantic Routing
Embed the incoming prompt and compare it against a set of reference embeddings that represent different task types. The closest match determines the route. This is particularly useful when your task categories are nuanced and hard to capture with rules or simple classifiers.
5. Hybrid Approaches
In practice, most production routers combine strategies. Rules handle the obvious cases (fail quickly, route quickly). A classifier picks up the middle ground. A cascade catches quality failures. This layered approach gives you the best of all worlds at the cost of more moving parts.
What a Basic Router Looks Like
Here is a simplified example in Python to illustrate the concept:
class LLMRouter:
def __init__(self, models: dict, classifier):
self.models = models # {"simple": client_a, "complex": client_b}
self.classifier = classifier
def route(self, prompt: str, **kwargs):
category = self.classifier.classify(prompt)
model = self.models.get(category, self.models["default"])
return model.complete(prompt, **kwargs)
def route_with_fallback(self, prompt: str, **kwargs):
try:
return self.route(prompt, **kwargs)
except Exception:
return self.models["fallback"].complete(prompt, **kwargs)
Real implementations handle retries, streaming, token counting, cost tracking, and observability. But the core pattern is this simple: classify, route, respond.
Tools and Frameworks Worth Knowing
The LLM routing space has matured quickly. Here are the options worth evaluating:
- LiteLLM — a popular open-source proxy that provides a unified API across 100+ LLM providers. It handles routing, fallbacks, load balancing, and spend tracking. Good starting point for most teams.
- RouteLLM — developed by researchers at LMSys, this framework specifically focuses on cost-efficient routing between strong and weak models using trained classifiers. Their research showed 2x cost reduction with minimal quality loss.
- Martian — a managed routing service that automatically selects the best model per request. Less control, but less maintenance.
- OpenRouter — acts as a unified gateway to multiple model providers with built-in routing capabilities.
- Custom builds — many teams, including ours, build bespoke routers tailored to their specific workloads. When your routing logic is core to your product, owning it makes sense.
Practical Considerations
Before you build or adopt a router, think through these:
- Observability first. If you cannot measure which model handled which request and how it performed, you cannot optimise your routing. Log everything: model used, latency, token count, cost, and ideally some quality signal.
- Start with rules, graduate to classifiers. Do not over-engineer on day one. Simple rules get you 80% of the benefit. Add sophistication when you have data to justify it.
- Test routing decisions. Build an evaluation set of prompts where you know the ideal model. Run your router against it regularly. Routing accuracy degrades as models get updated and new ones launch.
- Watch for model drift. Providers update models without warning. A model that was perfect for your use case last month might behave differently after a silent update. Your router should be resilient to this.
- Consider the unified API benefit. Even if you only use one model today, routing through a unified layer means swapping or adding models later is a configuration change, not a code change.
The Cost Argument in Numbers
To put this in perspective: as of early 2026, flagship models like Claude Opus or GPT-4.5 cost roughly 10-15x more per token than their smaller siblings (Claude Haiku, GPT-4o mini). If 60% of your traffic is simple enough for the smaller model, a router paying for the big model only when needed cuts your bill by around 50%.
For a team processing 100,000 requests per day, that is the difference between a monthly LLM bill of €15,000 and one of €6,000. The router itself costs almost nothing to run.
Where This Is Heading
LLM routing is becoming table stakes for production AI applications. As the number of available models grows and specialisation increases (models fine-tuned for medical, legal, code, multilingual), intelligent routing becomes less of a nice-to-have and more of a necessity.
We are also seeing routers become smarter. Instead of static rules, they learn from feedback loops: if a routed response gets a thumbs-down from a user, that signal feeds back into routing decisions. The line between routing and orchestration is blurring.
For teams building AI-powered products, getting routing right early saves enormous pain later. It is the kind of infrastructure investment that pays for itself within weeks.
If you are building AI features into your product and want to get the architecture right from the start, get in touch. We help teams design and implement LLM infrastructure that scales without burning through budget.
📷 Photo by Steve Johnson (@steve_j) on Unsplash



