Sub topic 2
The cost, latency, and quality trade-off
This chapter assumes you can write basic Python, have called a hosted language model through an API, and know that tokens are the unit of billing. It builds the cost and latency model that every later routing decision depends on.
Why this chapter comes before any router
A router is a policy for spending. Before you can say whether a policy is good, you need three numbers for each model: what a request costs, how long it takes, and how often the answer is acceptable. This chapter defines those numbers, shows how to compute them, and explains where the simple versions go wrong.
The previous chapter described what separates small and large models. Here the question changes from "how do they differ?" to "what does the difference cost, and when is it worth paying?"
Cost: more than the price per token
Hosted models usually charge separately for input tokens (your prompt) and output tokens (the model's reply). Output tokens are typically priced several times higher than input tokens. The cost of one request is:
cost = input_tokens * input_price + output_tokens * output_pricePrices are normally quoted per million tokens, so divide before you multiply. The following helper does that. The prices in it are made-up placeholders, not real quotes. Replace them with your provider's current price list.
PRICES = {
# dollars per million tokens: (input, output)
"small": (0.15, 0.60),
"large": (3.00, 15.00),
}
def request_cost(model: str, input_tokens: int, output_tokens: int) -> float:
price_in, price_out = PRICES[model]
return (input_tokens * price_in + output_tokens * price_out) / 1_000_000
small = request_cost("small", 1200, 300)
large = request_cost("large", 1200, 300)
print(f"small: ${small:.6f} large: ${large:.6f} ratio: {large / small:.1f}x")With these placeholder prices, the same request costs about 20 times more on the large model. The exact ratio varies by provider and model family, but ratios of 10x to 50x are common. That gap is the reason routing exists.
Things that change the real cost
- Prompt length. A long system prompt or retrieved documents are billed on every request. Routing a long-context request to the large model multiplies the gap.
- Output length. Large models are often more verbose, and output tokens cost more. Two models can produce different numbers of tokens for the same prompt.
- Caching. Some providers discount repeated prompt prefixes. If a cache applies to one model and not the other, the effective ratio changes.
- Retries and failures. A request that fails and is retried is paid for more than once, in time and sometimes in tokens.
- Fixed overhead. Infrastructure, logging, and a classifier or judge model add cost that is not part of either model's price.
Latency: two numbers, not one
Latency has two parts that users feel differently.
- Time to first token (TTFT) is the delay before the reply starts to appear. It depends on prompt length, queueing at the provider, and model size.
- Generation time is how long the rest of the reply takes. It is roughly output tokens divided by tokens per second.
Total latency is approximately:
latency = ttft + output_tokens / tokens_per_secondSmall models usually have lower TTFT and higher tokens per second. For a chat interface that streams text, TTFT dominates how fast the product feels. For a batch job that waits for the full reply, total latency matters and TTFT hardly does.
Measure latency as a distribution, not an average. A model with a mean of 1.2 seconds and a 99th-percentile of 15 seconds feels slow to the 1 percent of users who hit the tail, and those users often file the complaints. Track at least the median (p50) and p95 or p99.
Quality: the hardest axis to put a number on
Cost and latency come from billing records and timers. Quality does not. "The large model is better" is true on average over a broad benchmark and may be false on your task. Two facts matter for routing:
- Quality is task-specific. On extraction, classification, short rewrites, and lookups, a small model often matches a large one. On multi-step reasoning, long documents, and ambiguous instructions, the gap widens.
- Quality is measured per request class. The routing question is never "which model is better?" It is "for this kind of request, is the small model good enough?"
To turn quality into a number, define an acceptance test for your task. Examples are exact match against a label, a passing unit test for generated code, or a rubric score from a human or a judge model. Then quality for a model is the fraction of requests it passes. The evaluation chapter covers this in detail. For now, treat it as a number between 0 and 1 you can measure on a labeled sample.
Putting the three axes together
The three axes pull against each other. The table shows typical tendencies, not guarantees.
| Property | Small model | Large model |
|---|---|---|
| Cost per request | Low | High, often 10x to 50x |
| Time to first token | Lower | Higher |
| Tokens per second | Higher | Lower |
| Quality on simple requests | Often sufficient | Sufficient |
| Quality on hard requests | Drops noticeably | Higher |
| Capacity limits | Usually generous | Often tighter |
The key observation is that the large model's extra quality is only useful on requests where the small model fails. On easy requests, both models produce an acceptable answer, and the large model's extra cost and delay buy nothing.
The break-even idea
Suppose a fraction p of your traffic is easy, meaning the small model's answer would be acceptable. If you could identify those requests perfectly and send them to the small model, your average cost per request would be:
avg_cost = p * cost_small + (1 - p) * cost_largeThe saving against sending everything to the large model is p * (cost_large - cost_small) per request. Two consequences follow.
- Savings scale with how many easy requests you have, and with the price gap. If
pis 0.2, even a perfect router saves at most 20 percent of the large-model bill. - Savings are capped by the small model's own cost. You can never get below
cost_smallper request.
Here is a small calculation to build intuition. It reuses request_cost from above.
def average_cost(p_easy: float, cost_small: float, cost_large: float) -> float:
return p_easy * cost_small + (1 - p_easy) * cost_large
cost_small = request_cost("small", 1200, 300)
cost_large = request_cost("large", 1200, 300)
for p in (0.0, 0.2, 0.5, 0.8, 1.0):
avg = average_cost(p, cost_small, cost_large)
saving = 1 - avg / cost_large
print(f"easy fraction {p:.1f}: avg ${avg:.6f} saving {saving:.0%}")This is an upper bound. It assumes perfect identification of easy requests and no overhead. Real routers misclassify some requests, and a cascade pays for the small model on every request. Those effects are the subject of later chapters. The expected-cost formulas for each design appear in the cascading chapter.
Misrouting has two different costs
A router can be wrong in two directions, and the damage differs.
- Sending an easy request to the large model wastes money and adds latency. The user still gets a good answer. This is a cost error.
- Sending a hard request to the small model produces a worse answer. The user may notice, retry, or leave. This is a quality error.
Cost errors are visible on your invoice and are easy to detect. Quality errors are silent unless you measure for them. That asymmetry pushes teams toward over-spending when nobody is watching quality, and toward under-spending when nobody is watching the bill. A routing policy needs both measured.
Quality errors also have uneven consequences. A slightly weaker answer to a casual chat question is a small loss. A wrong answer in a financial summary, a medical context, or generated code that runs automatically is a large one. When the cost of a wrong answer is high, accept more cost errors on purpose by sending that class of request to the large model.
Choosing a point on the trade-off
There is no single correct balance. You choose it from product requirements. A practical way to do this:
- Set a quality floor. Decide the lowest acceptable pass rate on your acceptance test, for example 95 percent of what the large model achieves.
- Set a latency budget. Decide the p95 latency users will tolerate, and whether TTFT or total time is the binding constraint.
- Minimize cost under those two constraints. Among policies that meet the floor and the budget, pick the cheapest.
Framing it this way avoids a common mistake: optimizing cost first and discovering the quality loss later. It also makes decisions repeatable, because the floor and budget are written down.
A worked example
A support tool handles 100,000 requests a day. Each request averages 1,200 input tokens and 300 output tokens. Using the placeholder prices above, the large model costs about $0.00810 per request and the small model about $0.00036.
- All large: 100,000 × $0.00810 = $810 per day.
- All small: 100,000 × $0.00036 = $36 per day, but a labeled sample shows only 78 percent of answers pass, against 96 percent for the large model. The quality floor of 95 percent of 96 is 91.2 percent, so all-small fails the floor.
- A router that sends 60 percent of traffic to the small model and keeps the pass rate at 94 percent meets the floor. Its cost is 60,000 × $0.00036 + 40,000 × $0.00810 = $21.60 + $324 = $345.60 per day, a saving of about 57 percent.
The numbers are illustrative, but the structure is the point. The saving is large, yet the policy is accepted only because quality was measured against a stated floor.
Latency effects specific to routing
Routing changes latency in ways that are easy to overlook.
- The router adds time. A rule-based router costs microseconds. A classifier model or an LLM-based router adds a network call. Measure it.
- Cascades add time on escalation. A request that goes small then large pays both latencies in sequence. Its latency is roughly the small model's time plus the large model's time. Escalated requests are the slowest ones, so the tail gets worse even when the median improves.
- Load shifts. If most traffic moves to the small model, its provider rate limits matter more, and the large model sees fewer but harder requests, which may be longer.
Common errors when reasoning about the trade-off
- Comparing list prices instead of per-request cost. Output length and prompt size change the ratio. Compute cost from real token counts.
- Using a public benchmark as your quality number. Benchmarks measure general ability. Your acceptance test measures your task.
- Averaging latency. Averages hide the tail.
- Ignoring the distribution of requests. If 90 percent of your traffic is hard, routing saves little. Measure the easy fraction before building anything.
- Treating quality as fixed. Providers update models, and your traffic changes. A number measured in March may not hold in September. The monitoring chapter returns to this.
- Forgetting the overhead. A router, a judge model, or logging adds cost and latency that can erase a small saving.
Is routing worth it for you?
Routing adds code, tests, and monitoring. It pays off when three conditions hold together:
- Your volume is high enough that the price gap becomes a real line item.
- A meaningful share of requests, commonly 30 percent or more, is easy for the small model.
- You can measure quality, so you can tell whether a policy is safe.
If volume is low, a single model is simpler and the engineering time costs more than the savings. If you cannot measure quality, routing is a gamble, so build the acceptance test first.
Exercise
A request has 2,000 input tokens and 500 output tokens. The small model costs $0.20 per million input tokens and $0.80 per million output tokens. The large model costs $4.00 per million input tokens and $20.00 per million output tokens. Compute the cost on each model, and say how much money a perfect router saves per request if 70 percent of requests are easy for the small model.
Show answer
Small: (2000 × 0.20 + 500 × 0.80) / 1,000,000 = (400 + 400) / 1,000,000 = $0.0008. Large: (2000 × 4.00 + 500 × 20.00) / 1,000,000 = (8000 + 10000) / 1,000,000 = $0.018. Average with a perfect router: 0.7 × 0.0008 + 0.3 × 0.018 = 0.00056 + 0.0054 = $0.00596. Saving versus all-large: 0.018 − 0.00596 = $0.01204 per request, about 67 percent.
Exercise
After adding a cascade, your median latency drops from 1.4 s to 0.6 s, but p95 rises from 3 s to 4.5 s. Explain why both can happen, and name one number you would check next.
Show answer
Most requests are now answered by the small model, which is faster, so the median falls. Escalated requests pay for the small model's attempt and then the large model's call in sequence, so the slowest requests get slower and p95 rises. Check the escalation rate, since it sets how many requests take the slow path. The small model's latency on escalated requests is also worth checking.
Exercise
Name two reasons a router that sends a hard request to the small model can be harder to notice than one that sends an easy request to the large model.
Show answer
A wrong routing to the large model shows up as higher spend on the invoice, while a wrong routing to the small model gives a weaker answer that no billing record flags. The user may also retry or leave without reporting anything, so the failure only appears if you run an acceptance test or collect feedback.