Sub topic 5
Pick the smallest model that meets the bar
What this chapter assumes
You have read the earlier chapters on token pricing, latency, measurement, and the small evaluation set. You can call an LLM API from Python. You have a baseline of cost and latency per request, and a labeled set of test cases with a scoring function. This chapter uses all three.
Model choice is usually the largest single lever on both cost and latency. A smaller model in the same family often costs several times less per token and generates tokens faster. The risk is that quality drops on the cases you care about. The method here keeps that risk visible: define the bar first, then test models from smallest to largest, and stop at the first one that clears it.
Define the bar before you compare models
The bar is a written, numeric requirement. Without it, model comparison turns into a vote on which outputs "look better".
A useful bar has three parts:
- A quality threshold on your evaluation set, such as "at least 92% of cases pass".
- A latency limit, such as "p95 time to first token under 1.5 seconds".
- A cost ceiling, such as "under $0.004 per request at expected token counts".
Set the quality threshold from the current system, not from a hope. If your current model passes 94% of cases and users are satisfied, a candidate that passes 93% may be acceptable. Decide that in advance, and decide how much noise you will tolerate. With 100 test cases, a difference of one or two points is within run-to-run noise, especially at nonzero temperature.
What actually differs between models
Model size is not the only variable. When you compare candidates, record these properties.
| Property | Why it matters |
|---|---|
| Input and output price per million tokens | Sets cost. Output is usually priced higher than input. |
| Generation speed (tokens per second) | Sets generation time for long outputs. |
| Time to first token | Sets how fast a response starts, mostly prefill and queueing. |
| Context window | Limits how much prompt and retrieved text fits. |
| Quality on your task | The only property that general benchmarks cannot tell you. |
| Rate limits | Smaller models often have higher limits, which helps concurrency. |
Published benchmarks help you build a shortlist. They do not replace your own evaluation, because your prompts, your data, and your output format are specific. A model that ranks lower on a public benchmark can match a larger one on a narrow task such as classifying support tickets into five labels.
Which tasks tolerate smaller models
Tasks with a narrow output space and a clear right answer are the best candidates:
- Classification and routing into a fixed set of labels.
- Extraction of fields from text into a fixed JSON schema.
- Short rewrites, such as fixing grammar or normalizing format.
- Summaries of short, well-structured inputs.
Tasks that tend to need a larger model:
- Multi-step reasoning, where an early mistake carries through.
- Long documents where details must be tracked across many pages.
- Open-ended writing where tone and nuance matter.
- Tool use with many tools or complex argument schemas.
These are tendencies, not rules. Test them on your data.
Run the comparison
The procedure is the same for every candidate: run each model on the same evaluation set with the same prompt, then record quality, cost, and latency. Keep sampling settings fixed. If you use temperature above zero, run each case more than once and average, or the comparison will mostly measure luck.
The following script evaluates several models over a case list and prints one row per model. It takes the model call and the scoring function as arguments, so it works with any provider. The fake_call and fake_score functions at the bottom stand in for your real API wrapper and grader so the script runs as shown.
import statistics
import time
# Placeholder prices in USD per million tokens. Replace with your provider's current prices.
PRICES = {
"small": {"input": 0.20, "output": 0.80},
"medium": {"input": 1.00, "output": 4.00},
"large": {"input": 5.00, "output": 20.00},
}
def evaluate_model(model, cases, call_fn, score_fn, repeats=1):
"""Run every case against one model. Return quality, cost, and latency summary.
call_fn(model, case) must return (text, input_tokens, output_tokens).
score_fn(case, text) must return True or False.
"""
passes = 0
total_runs = 0
costs = []
latencies = []
for case in cases:
for _ in range(repeats):
start = time.perf_counter()
text, in_tok, out_tok = call_fn(model, case)
latencies.append(time.perf_counter() - start)
price = PRICES[model]
costs.append((in_tok * price["input"] + out_tok * price["output"]) / 1_000_000)
passes += 1 if score_fn(case, text) else 0
total_runs += 1
latencies.sort()
p95_index = max(0, int(len(latencies) * 0.95) - 1)
return {
"model": model,
"pass_rate": passes / total_runs,
"mean_cost": statistics.mean(costs),
"p95_latency_s": latencies[p95_index],
}
def compare(models, cases, call_fn, score_fn, repeats=1):
return [evaluate_model(m, cases, call_fn, score_fn, repeats) for m in models]
if __name__ == "__main__":
# Stand-ins so the script runs without an API key.
def fake_call(model, case):
answer = case["expected"] if model != "small" or case["id"] % 5 else "wrong"
return answer, 200, 20
def fake_score(case, text):
return text == case["expected"]
cases = [{"id": i, "expected": "ok"} for i in range(50)]
for row in compare(["small", "medium", "large"], cases, fake_call, fake_score):
print(
f"{row['model']:<7} pass={row['pass_rate']:.2f} "
f"cost=${row['mean_cost']:.6f} p95={row['p95_latency_s']:.4f}s"
)With the stand-ins, the small model fails one case in five, so you see a pass rate of 0.80 against 1.00 for the others. With a real API, you would replace fake_call with a function that calls the provider and reads token counts from the response.
Read the results as a trade-off
Look at the whole table, not one column. A typical result looks like this:
| Model | Pass rate | Cost per request | p95 latency |
|---|---|---|---|
| small | 0.88 | $0.00006 | 0.6 s |
| medium | 0.95 | $0.00028 | 1.1 s |
| large | 0.96 | $0.00140 | 2.4 s |
If the bar is 92% pass rate, the medium model is the smallest that meets it. The large model costs five times as much for one extra point, which is inside the noise for most evaluation sets. The small model is cheap but fails the bar.
Then inspect the failures of the small model. If most of them come from one category, such as inputs with unusual formatting, you have two options besides moving up a size: fix the prompt for that category, or route only that category to a larger model. The routing chapter covers the second option.
Edge cases and common errors
Tuning the prompt for one model. A prompt written and polished against a large model may underperform on a small one, while a short edit would fix it. Give each candidate a fair chance: try one round of prompt adjustment, such as clearer instructions or an added example, before ruling a smaller model out. Do not tune endlessly for the small model while leaving the large one untouched, because that biases the comparison the other way.
Ignoring output length differences. Models differ in verbosity. A cheaper model that writes twice as many tokens narrows the cost gap, and a longer answer also adds generation time. Compare cost per request using measured output tokens, not price per token alone.
Comparing on easy cases only. If your evaluation set is mostly easy inputs, every model passes and the smallest looks free. Make sure the set includes the hard and unusual inputs from real traffic.
Treating latency as fixed by size. Smaller models are usually faster, but provider load, region, and queueing also affect latency. Measure at the times of day your traffic arrives.
Forgetting retries. If a model fails the format check and your code retries, the true cost per successful answer is higher than the mean cost per call. Count retries in the cost column.
Version drift. Providers update and retire model versions. Pin an explicit version where the provider allows it, and rerun the evaluation set before changing versions.
Revisit the choice over time
The right model today may not be the right one in six months. New small models often match the quality of older large ones. Schedule a re-evaluation when a provider releases a model, when your traffic mix changes, or when monitoring shows quality or cost drifting. Because the evaluation set and the script already exist, this costs little.
Exercise
Your bar is 90% pass rate and p95 latency under 2 seconds. Results: small gives 0.86 pass and 0.7 s; medium gives 0.93 pass and 1.4 s; large gives 0.94 pass and 3.1 s. Which model do you pick, and what would you try before settling on medium if cost matters a lot?
Show answer
Pick medium. It is the smallest model that meets both the quality and latency bar, and large fails the latency limit. Before settling, inspect the small model's failures and try one prompt revision (clearer instructions or an example). If that lifts the small model to at least 0.90 on a rerun, it would be cheaper. Also consider routing only the failing category to medium.
Exercise
A teammate says the small model "looks just as good" after reading ten outputs. Name two problems with this conclusion and one measure that fixes them.
Show answer
Ten samples is too few to separate real differences from noise, and reading outputs without a scoring rule is subjective and may miss rare failures. Run the full evaluation set with a fixed pass/fail scoring function and compare pass rates against the bar set in advance, repeating runs if temperature is above zero.