Sub topic 2
The cost, latency, and quality trade-off
This chapter assumes you know basic Python, have called a hosted language model through an API, and understand tokens and per-token pricing. It builds on the previous chapter, which described small and large model tiers. Here you will put numbers on what each tier costs and decide when a cheaper tier is good enough.
Three quantities to compare
Every routing decision balances three things.
- Cost is what you pay per request. Providers usually charge per input token and per output token, and output tokens cost more.
- Latency is how long the user waits. It has two parts: time to first token and the time to generate the rest of the answer.
- Quality is how often the answer is good enough for the task. You measure it against a labeled sample, not by impression.
Large models usually win on quality and lose on cost and latency. Small models do the opposite. Routing tries to get the large model's quality on the requests that need it and the small model's price and speed on everything else.
| Property | Small model | Large model |
|---|---|---|
| Price per token | Low | High (often several times more) |
| Latency | Low | Higher |
| Quality on easy tasks | Often equal | Equal |
| Quality on hard tasks | Drops sharply | Holds up |
The last two rows explain why routing works. If the small model matched the large one everywhere, you would use only the small one. If it were worse everywhere, you would use only the large one. The gap exists mainly on hard requests, and many workloads contain mostly easy ones.
A worked cost example
Suppose a request averages 1,000 input tokens and 300 output tokens. Assume these prices, which are made up for the example.
| Model | Input per 1M tokens | Output per 1M tokens |
|---|---|---|
| Small | $0.20 | $0.80 |
| Large | $3.00 | $15.00 |
The small model costs 1,000 × $0.20 / 1M + 300 × $0.80 / 1M = $0.00044 per request. The large model costs 1,000 × $3.00 / 1M + 300 × $15.00 / 1M = $0.0075 per request. The large model is about 17 times more expensive.
def request_cost(input_tokens, output_tokens, price_in, price_out):
# Prices are dollars per one million tokens.
return (input_tokens * price_in + output_tokens * price_out) / 1_000_000
small = request_cost(1000, 300, 0.20, 0.80)
large = request_cost(1000, 300, 3.00, 15.00)
print(f"small=${small:.5f} large=${large:.5f} ratio={large / small:.1f}x")Running this prints small=$0.00044 large=$0.00750 ratio=17.0x. If 70% of traffic could go to the small model, the average cost per request would be 0.7 × 0.00044 + 0.3 × 0.0075 = $0.00256. That is about 66% cheaper than sending everything to the large model.
Latency adds up differently
Latency matters most in interactive use, such as chat or autocomplete. A small model may answer in under a second where a large one takes several seconds. Routing to the small model first can improve the typical response time.
Latency can also get worse. A cascade, covered later, calls the small model and then the large model when it escalates. Those escalated requests wait for both calls. So a policy that lowers average cost can raise the slowest response times.
Quality is not one number
"Quality" depends on the task. A small model may extract dates from text as well as a large one. It may fail at multi-step reasoning. So measure quality per request type, not as one global score.
Also decide how much quality loss you accept. Some applications tolerate a 2% drop for a 60% saving. Others, such as medical or legal drafting, may not tolerate any drop on certain requests. That tolerance sets how aggressively you route to the small model.
Choosing the operating point
Think of routing as picking a point on a curve. At one end, everything goes to the large model: highest quality, highest cost. At the other, everything goes to the small model: lowest cost, lowest quality. A good policy sits where extra savings start to cost more quality than you can accept.
A practical way to decide:
- Define the quality bar for each request type.
- Measure both models on a labeled sample.
- Find the request types where the small model meets the bar.
- Route those to the small model, and keep the rest on the large one.
- Recheck cost and latency with real traffic numbers.
The next chapters cover what a router can look at and how to build rule-based and cascaded routers.
Exercise
Using the example prices in this chapter, a request costs $0.00044 on the small model and $0.0075 on the large model. If 80% of requests go to the small model through a router, what is the average cost per request, ignoring router overhead?
Show answer
0.8 × 0.00044 + 0.2 × 0.0075 = 0.000352 + 0.0015 = $0.001852 per request. That is about 75% cheaper than using the large model alone.
Exercise
Why can a policy that lowers average cost still make some responses slower?
Show answer
If the policy calls the small model first and escalates to the large model when needed, escalated requests wait for both calls. Their latency is the small model's time plus the large model's time, so the slowest responses get slower even as average cost falls.