Sub topic 14
Route requests and cascade between models
This chapter assumes you can call an LLM API, have a small quality evaluation set (see the earlier chapter on evals), and know your baseline cost and latency per request. Routing and cascades both depend on those two things.
Why one model for everything wastes money
Most traffic is easy. A support bot sees many "what are your opening hours?" questions and a few multi-step billing disputes. Sending all of it to your strongest model pays the premium price for work a cheaper model would handle equally well. Two patterns fix this: routing and cascading.
- Routing picks a model before the call, based on the request itself.
- Cascading calls a cheap model first, checks the result, and escalates only if the check fails.
Routing
A router looks at the request and chooses a model. Common signals:
- Task type (classification, extraction, or open-ended reasoning).
- Input length or number of documents attached.
- A user tier or a feature flag.
- A small classifier model that labels the request as "easy" or "hard".
Start with rules. A rule such as "extraction tasks go to the small model" is cheap, fast, and easy to debug. Add a classifier only when rules stop being accurate enough.
Cascading
A cascade pays for the strong model only when the cheap one falls short.
def answer_with_cascade(question, cheap_fn, strong_fn, is_good_enough):
draft = cheap_fn(question)
if is_good_enough(question, draft):
return draft
return strong_fn(question)The quality check, is_good_enough, decides everything. Useful checks include:
- Schema validation, for example "the output parses as JSON with the required fields".
- Rule checks, such as a required citation or an answer within an allowed set.
- A confidence signal, if your task provides one.
- A grader model, which adds its own cost and latency.
The cost and latency trade-off
A cascade is not free. A request that escalates pays for both calls and waits for both. Suppose the cheap model costs 1 unit, the strong model costs 10, and 70% of requests pass the check. Average cost is 1 + 0.3 × 10 = 4 units, against 10 for the strong model alone. If only 20% passed, the average would be 1 + 0.8 × 10 = 9 units, and the extra latency on most requests would not be worth it.
So the pass rate must be high enough to cover the wasted cheap calls. Measure it before you commit.
Common errors
- No evaluation set. Without one, you cannot tell whether the cheap model's accepted answers are actually good. Run your eval set through the whole pipeline, not each model alone.
- A weak quality check. A check that passes bad drafts hides quality loss. A check that rejects good drafts wastes money. Track both.
- Ignoring tail latency. Escalated requests are the slowest. Report latency by path (cheap only versus escalated), not just the average.
- Router drift. Traffic changes over time. Log which path each request took and re-check the pass rate regularly.
Exercise
A cheap model costs 2 units per request and a strong model costs 12. In a cascade, 60% of requests pass the quality check on the cheap draft. What is the average cost per request, and is it cheaper than always using the strong model?
Show answer
Every request pays 2 for the cheap call. The 40% that fail also pay 12. Average cost = 2 + 0.4 × 12 = 6.8 units. This is cheaper than 12 units for the strong model alone, though escalated requests take longer because they wait for two calls.