Module 7 · AI infrastructureLesson 84 of 886 minAdvanced
Model routing
Not every prompt needs the biggest model. A router sends each request to the cheapest model that can handle it well.
Compare total cost and time with a router and with everything sent to the large model.
The landscape of models is wide: tiny fast models, mid-size models, frontier models; open models you host and APIs you call. Prices per token can differ by 100 times, and speed by 10 times. Most real traffic is a mix of easy and hard requests.
How routing works
A router sits in front of several models and picks one per request:
- Rules: by task type or endpoint ("autocomplete" goes to small, "report" to large), by prompt length, or by customer tier.
- Classifier: a small, fast model labels the request as easy or hard.
- Cascade: try the small model first; if it's unsure or a quick check fails, escalate to the large model.
- Semantic: route by embedding similarity to known request types.
Other jobs of a model gateway
The same layer usually also handles:
- Fallbacks: if a provider times out or rate-limits, retry on another model or provider.
- Load balancing across API keys, regions and self-hosted replicas.
- Caching (semantic or exact).
- Logging, cost tracking and budgets per team or customer.
- Safety filters on inputs and outputs.
Measure, don't assume
Routing saves money only if quality holds. Keep an evaluation set per task type, compare models on it, and watch for drift as models are updated. Log which route each request took, so you can tell whether complaints come from the small model.