AI ENGINEERING · LLM FOUNDATIONS · PRACTICE · 6 OF 35

How to Choose an LLM: Quality, Cost and Latency

How to pick a language model: the quality, cost and latency triangle, frontier versus small fast versus self-hosted open-weight models, the capability checklist (context window, modalities, tool use, structured output), time to first token versus tokens per second, a worked monthly cost estimate, routing, your own eval set, privacy, and a thin provider layer against lock-in.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
1 / 17

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • Quality
  • cost
  • latency
  • filter on hard needs
  • your own evals
  • route easy to small
  • mind privacy
  • stay swappable

Notes

The idea

Here is the core idea. Every model sits somewhere on a triangle of quality, cost and latency. Bigger models usually give better answers, but they cost more per token and respond more slowly. Smaller models are cheap and quick, but make more mistakes on hard tasks. So the question is never which model is best. It is which is the cheapest and fastest model that is still good enough for this particular task.

The triangle
  • quality: right answers on YOUR task
  • cost: price per request, times requests per month
  • latency: how long the user waits for an answer
  • bigger model: better quality, higher cost, slower
  • goal: the cheapest, fastest model that is good enough

Three families

Models come in three broad families. Frontier models are the largest ones from the big labs, served through an A P I. They are best at hard reasoning, long tasks and agents, and they cost the most. Small fast models from the same providers are often ten to thirty times cheaper and great at classifying, extracting and short replies. Open weight models you download and run yourself. You control the data and can fine tune them, but now you operate the G P Us.

Three kinds of model
  • frontier (hosted API) hardest reasoning, long tasks, agents; priciest
  • small fast (hosted API) classify, extract, short replies; 10-30x cheaper
  • open-weight (you host) weights you download and run; you control data, can fine-tune, but you run GPUs

Check the features

Before comparing quality, filter on hard requirements. Does the context window fit your largest prompt plus the answer? Can it accept the inputs you have, like images, P D Fs or audio? Does it call tools reliably, including several at once? Does it offer a strict structured output mode that follows a JSON schema? Does it handle the languages your users write in? Any model that fails one of these is out, however good its scores look.

Hard requirements
  • context window: fits your biggest prompt + output?
  • max output length
  • modalities: images, PDFs, audio in? images out?
  • tool use: reliable calls, parallel calls?
  • structured output: strict JSON Schema mode?
  • languages you serve
  • region, privacy terms

Two kinds of speed

Latency has two parts. Time to first token is how long before any text appears. It grows with prompt length, because the model must read the whole prompt first. Tokens per second is how fast text flows after that. Say a small model starts in zero point three seconds and writes one hundred and fifty tokens a second. A three hundred token answer takes two point three seconds. A big model at one point five seconds and fifty tokens a second takes seven and a half.

A 300-token answer
total = TTFT + tokens / speed

small: 0.3 + 300 / 150
     = 0.3 + 2.0 = 2.3 s
big:   1.5 + 300 / 50
     = 1.5 + 6.0 = 7.5 s

chat UI: stream, so TTFT is
  what the user feels
batch job: total time matters

A monthly cost

Now a cost estimate, using example prices. Twenty thousand requests a day is six hundred thousand a month. Each sends fifteen hundred input tokens and gets three hundred back. That is nine hundred million input tokens and one hundred and eighty million output tokens. At two dollars per million in and eight dollars per million out, that is eighteen hundred plus fourteen hundred and forty, about thirty two hundred dollars a month. A small model at a tenth of the price, around three hundred.

Worked estimate
20,000 requests/day x 30 = 600k/mo
each: 1,500 in + 300 out tokens

input:  600k x 1,500 = 900M tok
output: 600k x   300 = 180M tok

example price per 1M tokens:
  in 2 USD, out 8 USD
cost = 900 x 2 + 180 x 8
     = 1,800 + 1,440 = 3,240 USD
small model at ~1/10: ~324 USD

Routing

Most traffic is easy, so you rarely need the big model for everything. Put a router in front. If eighty percent of requests go to the small model and twenty percent to the big one, the bill drops from about thirty two hundred dollars to about nine hundred, a cut of over seventy percent. Route with simple rules, a cheap classifier, or a cascade: try the small model first and escalate when its answer fails a check, like invalid JSON or low confidence.

Route by difficulty
80% easy  -> small:  0.8 x 3,240 / 10
                   =   259 USD
20% hard  -> big:    0.2 x 3,240
                   =   648 USD
total ~907 USD vs 3,240 (-72%)

how to route:
  rules (length, intent, tier)
  a small classifier model
  cascade: escalate if a check fails

Hosting it yourself

Open weight models change the economics. Instead of paying per token, you pay for G P U hours whether they are busy or idle. That pays off when volume is high and steady, when data must never leave your network, when you need to fine tune, or when the model must run offline. The price is real engineering: a serving stack, autoscaling, upgrades and someone on call. Quantised small models can even run on a single G P U or a laptop.

Open-weight trade-offs
  • you pay per GPU hour, busy or idle, not per token
  • pays off: high steady volume, strict data rules, need to fine-tune, offline or edge
  • costs you: serving stack, scaling, upgrades, on-call
  • quantised small models can run on one GPU or a laptop

Your own evals

Leaderboards tell you how a model does on someone else's test, and some of those tests have leaked into training data. Build your own eval set instead. Take fifty to three hundred real cases from your logs, including the awkward ones. Give each a check: an exact answer, valid JSON, or a rubric scored by a person or a judge model. Run every candidate on the same cases with the same prompts. Use leaderboards only to pick the shortlist.

Build an eval set
  • 50-300 real cases from your logs, edge cases too
  • each with a check: exact match, schema valid, or a rubric graded by a person or a judge model
  • run every candidate model, same prompts, same cases
  • leaderboards: a first filter, never the decision

Reading the results

Here is how results might look. Decide the bar first: say ninety two percent of cases pass, and the slowest five percent of answers finish under five seconds. The frontier model passes but is slow and expensive. The small model is fast but misses the bar. The routed setup passes ninety four percent at under a third of the cost. That is the pick. Keep the eval and rerun it every time a model or prompt changes.

Example results
model        pass   p95     USD/mo
frontier     95%    7.5 s   3,240
small        86%    2.3 s     324
open, hosted 89%    3.0 s   ~1,500
routed       94%    3.1 s     907

bar: 92% pass, p95 under 5 s
winner: routed
keep the eval; rerun it on
every model or prompt change

Privacy

Ask where the model runs and where your data goes. With a provider A P I, read the terms: how long prompts are kept, whether they are used for training, and whether a zero retention option exists. Many models are also offered inside the big cloud platforms, in your own account and region. Self hosting keeps data inside your network entirely. Whatever you choose, sign a data processing agreement, redact personal data you do not need, and log what you send.

Where does data go?
  • provider API: check data retention, training use, zero-retention options
  • your cloud account: same model, your region + keys
  • self-hosted: data never leaves your network
  • always: data processing agreement, redact PII, log what you send

Avoid lock-in

Models improve every few months, and prices fall, so you will switch. Make it cheap. Put a thin layer between your app and the providers: one function that takes the model, the messages, the tools and a schema, with one small adapter per provider. Read the model id from config, pin exact versions, and log tokens, cost and latency per call. The same layer gives you a fallback model when a provider has an outage. Keep it thin.

A thin layer
complete(model, messages,
         tools, schema) -> reply

one adapter per provider
model id comes from config
pin exact model versions
prompts stored per model
log tokens, cost, latency
fallback model on errors

keep it thin: no big framework

Common mistakes

A few mistakes come up again and again. Choosing by leaderboard or by hype. Sending every request, even trivial ones, to the biggest model. Estimating cost from input tokens alone, when output tokens cost several times more. Testing with five happy examples. Assuming a prompt tuned for one model works as well on another. And pointing at a latest alias, so the model changes under you without warning. Each one is fixed by measuring rather than guessing.

Avoid these
  • picking by leaderboard or by hype
  • frontier model for every request, even trivial ones
  • forgetting output tokens cost more than input
  • testing with 5 happy cases
  • one prompt for all models
  • letting "latest" alias change under you silently

Numbers worth knowing

Some numbers worth knowing, all rough. Output tokens usually cost three to five times as much as input tokens. Small models are often ten to thirty times cheaper than frontier ones. Time to first token is roughly a fifth of a second to two seconds, and output runs at about thirty to two hundred tokens a second. Context windows run from about a hundred thousand to over a million tokens. Prices change quickly, so always redo the maths.

Ballpark numbers
output vs input price    ~3-5x
small vs frontier price  ~10-30x cheaper
time to first token      ~0.2-2 s
output speed             ~30-200 tok/s
context windows          ~100k-1M+ tok
useful eval set          ~50-300 cases
cached input             far cheaper

always recompute with
current prices

A decision recipe

Put it together as a recipe. One, write down the hard requirements. Two, shortlist three or four models of different sizes from at least two providers. Three, build an eval set and decide the bar. Four, measure each candidate's pass rate, slow end latency and monthly cost. Five, pick the cheapest one that clears the bar, or route between two if your traffic mixes easy and hard requests. Six, rerun the evals whenever a new model or price appears.

Six steps
  • 1 write the hard requirements
  • 2 shortlist 3-4 models, mixed sizes, from 2+ providers
  • 3 build the eval set + bar
  • 4 measure pass rate, p95 latency, cost per month
  • 5 cheapest that clears the bar; route if traffic is mixed
  • 6 rerun evals on every new model or price change

Say it like this

How to say it. First I filter on hard requirements: context size, tool use, strict JSON and our data rules. Then I run three candidates on a two hundred case eval built from real traffic. A small model handles about eighty percent of requests, and hard ones go to a frontier model, for about nine hundred dollars a month and three seconds at the slow end. It all sits behind a thin provider layer, so switching is a config change.

In the interview
  • "I filter on hard needs: context, tools, JSON, data rules. Then I run 3 models on a 200-case eval. The small one handles 80% of traffic; hard cases go to a frontier model. ~900 USD a month, p95 3 s, behind a thin layer so we can swap."

Interview questions

Q1How would you choose an LLM for a new feature?

Filter candidates on hard requirements (context window, modalities, tool use, structured output, data rules), shortlist a few models of different sizes, run them on an eval set built from real cases, and pick the cheapest one that clears the quality and latency bar.

Q2What is the quality, cost and latency trade-off?

Larger models usually answer better but cost more per token and respond more slowly; smaller models are cheaper and faster but fail more on hard tasks. You choose the point on that triangle the task needs, not the strongest model available.

Q3What is the difference between time to first token and tokens per second?

Time to first token is the delay before any output appears and grows with prompt length; tokens per second is the generation speed after that. Total time is roughly TTFT plus output tokens divided by speed, and with streaming the user mostly feels TTFT.

Q4How do you estimate the monthly cost of an LLM feature?

Multiply monthly requests by average input and output tokens to get token totals, then multiply each by its own price. For example 600k requests at 1,500 in and 300 out is 900M input and 180M output tokens; output is usually priced several times higher.

Q5What is model routing and why use it?

A router sends easy requests to a small cheap model and hard ones to a larger model, using rules, a classifier or a cascade that escalates when the small model's answer fails a check. Since most traffic is easy, it can cut cost by well over half with little quality loss.

Q6Why not just pick the model at the top of a public leaderboard?

Leaderboards measure other tasks, may be contaminated by training data and ignore your prompts, formats and cost limits. Only an eval set of your own real cases, with clear pass checks, tells you how a model performs for your product.

Q7When does self-hosting an open-weight model make sense?

When volume is high and steady enough to keep GPUs busy, when data must not leave your network, when you need to fine-tune, or when the model must run offline. You trade a per-token bill for GPU hours plus the work of serving, scaling and upgrading.

Q8How do you avoid lock-in to one model provider?

Put a thin abstraction in front of providers: one call interface with an adapter per provider, model ids in config, pinned versions, per-model prompts and logged cost and latency. Combined with a standing eval set, switching or adding a fallback becomes a config change you can verify.