Skip to content
mentoor

Topic 4 of 5 · 5 min read

Cutting cost and latency without losing quality

Goal: Pick the change with the best cost, latency and quality trade-off for a stated workload and name the eval it must pass.

Cut cost and latency one change at a time, aim each change at the biggest line in your measurements, and ship it only if your eval scores hold. Most savings come from sending fewer tokens and making fewer sequential calls, not from clever tricks.

Check yourself · 1 of 3

Why are shorter answers often the most effective way to cut both cost and latency?

Choose one answer

Why it matters

Quality is the third number in the budget. A cheaper model that gets 5 percent more answers wrong may cost more in support tickets than it saves. Without an eval, you cannot tell.

The levers

  • Route by difficulty. Send easy requests to a smaller, faster model and hard ones to a larger one. A classifier or simple rules can decide.
  • Trim the prompt. Remove unused instructions, duplicate examples and retrieved passages the answer never uses. Shorter input lowers cost and time to first token.
  • Cache stable prefixes. If every request starts with the same long system prompt or document, prompt caching makes the repeated part cheaper and faster.
  • Cap the output. Ask for a short format, set a max output tokens limit, and avoid asking the model to repeat the input. Output tokens cost more and take the most time.
  • Limit reasoning effort. Use low effort or a small thinking budget on tasks that do not need long reasoning.
  • Batch work nobody waits for. Asynchronous batch endpoints suit overnight jobs.
  • Parallelise independent calls. Three lookups that do not depend on each other take the time of one if run together.
  • Stream so users start reading at the first token.

The process

  1. Read the trace and pick the largest cost or time contributor.
  2. Choose the lever that targets it.
  3. Run your eval set on the old and new versions. Compare quality, cost per successful task and p95.
  4. Ship only if quality is within the margin you set in advance, such as no more than one point lower.

Before and after

Weak: "Switch everything to the small model, it is five times cheaper."

Better: "Route the 70 percent of requests the classifier labels as simple to the small model. Eval: 200 labelled requests, accuracy must stay within one point of the current result, and p95 must stay under 3 seconds." Now the saving is measured, and a regression blocks the release.

What goes wrong

  • Optimising without a baseline, so nobody knows whether it helped.
  • Cutting prompt text that carried a rule, which shows up as a quality drop weeks later.
  • Caching with a changing prefix. A timestamp at the start of the prompt prevents any cache hit.

Examples

Routing a support classifier

Workload: 100 000 requests a month, 70 percent are simple (order status, password reset), average 800 input tokens.

Change: a rules-and-classifier step sends simple requests to a small model.

Eval it must pass: 300 labelled tickets with their correct handling. Accuracy within one point of the large-model baseline, p95 under budget, and cost per successful task reported before and after.

If accuracy drops two points on the billing category, route only the categories that held.

Cache-friendly prompt order

Before: the prompt starts with Today is 2026-12-02 14:03 and then 8 000 tokens of policy text. The first line changes every minute, so the cache never hits.

After: policy text first, then a cache breakpoint, then the date and the user's question. The 8 000 tokens are now read from cache on most requests, which lowers both their price and the time before the first token.

Key points

  • Start from the trace or the cost log and target the largest contributor, instead of applying every tip at once.
  • Output tokens cost more and take longer than input tokens, so shorter answers are often the biggest single saving.
  • Prompt caching only works when the repeated content is a stable prefix, so put changing values after it.
  • Run independent calls in parallel and batch anything that no user is waiting for.
  • Ship a change only when an eval run shows quality inside a margin agreed in advance.

Common mistakes

  • Moving to a smaller model across the board without running an eval on real examples.
  • Putting timestamps, user names or request ids at the start of a prompt and wondering why caching saves nothing.
  • Trimming a prompt by feel and removing a rule the model needed.
  • Changing three things at once so the effect of each cannot be measured.

Check yourself · 2 of 3

A prompt starts with the current date and time, followed by 8 000 tokens of fixed policy text. Prompt caching saves almost nothing. What is the fix?

Choose one answer

Check yourself · 3 of 3

A team plans to move every request to a model that is five times cheaper. What should they do before shipping?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic