Drills D10

Cut LLM cost by 50% with no quality loss

Your LLM bill doubled last quarter. Finance wants it halved next quarter, and product says users must not notice any drop in quality. How do you do it?

45 minutes · revise 11.05 · 31.01 · 31.02 · 31.03 · 31.05 · 31.06 · 31.07 · 31.10 · 31.11 · 31.14

Clarify and scope

This drill is about method. The candidate who opens with “switch to a cheaper model” has already lost. Open with “first I need to know where the money goes, and what ‘no quality loss’ means as a number.”

Ask:

Baseline architecture

The architecture here is a loop, not a box diagram:

  1. MEASURE              2. RANK LEVERS            3. CHANGE ONE THING      4. VERIFY
 per-call ledger:   -->  cost share x expected  --> behind a flag      -->  paired offline eval
 feature, step,          saving x (1 - risk)        (cache, route,          + A/B or shadow
 model, tokens in /                                 trim, batch ...)        + billed cost delta,
 cached / out /                                                             measured, not estimated
 thinking, cost                                                                  |
       ^                                                                         |
       +----------------------- keep or revert, next lever ----------------------+

The request path after the changes:

 request --> [code fast path / exact cache] --hit--> response
                 |
             [router] -- easy --> small model --(validator fails)--+
                 |                                                 |
                 +------ hard --> large model <--------------------+
                               (static prefix served from the prompt cache,
                                trimmed context, capped reasoning effort)

 nightly summaries --> batch API (asynchronous, discounted)

Key choices and trade-offs

Rank the levers by risk to quality, lowest first.

1. Remove waste (no quality risk). Look for:

The ledger finds these within a day.

2. Prompt caching. Put the stable part of the prompt first (system prompt, tool definitions, few-shot examples, static documents) and the variable part (date, user, retrieved chunks) last. Mark the cache breakpoint where the provider requires it, and record cached tokens on every call. Cached input is billed at a fraction of the normal input price. The fraction, the cache-write premium and the TTL differ by provider, so check current prices. One trap: a deploy that adds a timestamp to the top of the system prompt silently drops the hit rate to zero. Alert on the hit rate.

3. Trim context. Fewer retrieved chunks, if recall@k holds at the smaller k. Clipped tool results. A summary in place of an old conversation history. Shorter few-shot sets. Each of these needs the eval, because removing context can remove the answer.

4. Route and cascade. Send easy turns to a small model and hard turns to a large one. Choose the model per task with your own eval, keep the table, and revisit it when models change. A cascade (small first, escalate when a validator fails) only pays off if the escalation rate is low. See the numbers below.

5. Batch API for anything that is not interactive: nightly summaries, backfills, eval runs. It is usually discounted (check current terms) and costs you only turnaround time.

6. Cap output and reasoning effort. Ask for shorter formats where users do not read long ones. Use lower reasoning effort on routine steps. Caching does nothing for output tokens, so this is the lever when output dominates the bill.

7. Response caching. Use exact caching for repeated deterministic calls (the same document classified twice). Consider a semantic cache only after you have measured the duplicate rate: personalised chat rarely repeats.

8. Longer-horizon levers. Distil or fine-tune a small model on logged traffic. Self-host only when steady volume makes the break-even work. Both are too slow to be the core of a one-quarter plan.

Evals

Guardrails and fallbacks

Observability and cost

The ledger is the whole game. Every call records feature, step, model, input / cached / output / thinking tokens, latency, cost source (provider-reported or price table) and the outcome. From it you build:

Each eval run also reports cost per case, so the cost of a prompt change is visible in the same PR comment as its quality.

The numbers

Prompt caching saving. Let f be the share of input tokens that are a cached prefix and c the cached price as a fraction of the normal input price (check your provider). Input cost falls by f × (1 − c), ignoring cache writes. Illustration: f = 0.6, c = 0.1 gives 0.6 × 0.9 = 54% off input cost.

Cascade break-even. Let C_s and C_l be the cost per request of the small and large models, and e the escalation rate. Expected cost = C_s + e × C_l. That beats “always large” only if C_s + e × C_l is less than C_l, that is e < 1 − C_s / C_l. If the small model costs a fifth of the large one, the cascade wins while e < 0.8. The real limit is quality and latency, not cost: every escalation pays for two calls and waits for both.

Illustrative 50% plan. Suppose the ledger shows this split of total spend: chat writer 60 (input 42, output 18), nightly summariser 20, retries and failed calls 5, reranker LLM 10, other 5. Assumptions: f = 0.6 and c = 0.1, the small model costs 0.2 of the large one, the batch factor is 0.5 (check current terms), and 10% of routed turns escalate.

LeverArithmeticSaving (points of total spend)
Prompt cache on writer input42 × 0.5422.7
Route half of writer turns to small modelremaining writer cost (19.3 + 18 = 37.3) × 0.5 × (1 − 0.2) = 14.9, minus escalations 37.3 × 0.5 × 0.1 = 1.913.0
Nightly summariser to batch20 × 0.510.0
Stop non-retryable retriesabout 4 of the 54.0
Totalabout 49.7

The point is not these exact numbers. The ledger tells you which rows exist, and the arithmetic tells you whether 50% is reachable before you touch anything.

Is the drop real? On 300 paired cases, suppose 6 cases flip pass to fail and 3 flip fail to pass. The net change is −3/300 = −1 point. With b + c = 9 discordant cases, SE ≈ √9 / 300 = 0.01, so the 95% interval is −1 ± 2 points, from −3 to +1. That is non-inferior at a 3-point margin, but not at 2. Decide δ before you look.

Latency. Caching lowers time to first token on long prompts. A small model is usually faster. A cascade adds the small model’s latency to every escalated request. Batch adds hours, which is acceptable only offline.

Follow-ups they will ask

  1. What if output tokens dominate the bill? Caching will not help. Cut output length, cap reasoning effort, and route to a smaller model.
  2. Why not move everything to the cheapest model? Cost per task, not per token. Longer outputs, more retries and more escalations can make it dearer, and quality drops on the hard slice.
  3. Would you add a semantic cache? Measure the near-duplicate rate first. Personalised chat rarely repeats, and a false hit is a wrong answer delivered confidently.
  4. When does self-hosting pay? When the GPU cost per hour, divided by the tokens per hour you actually push at realistic utilisation, beats the API price, including ops time. That usually needs steady, high volume.
  5. How do you stop the savings eroding? Cost per case in every eval run, a cache hit-rate alert, per-feature budgets with owners, and a monthly reconciliation with the invoice.
  6. Finance wants results in two weeks. Do the zero-risk levers first: waste, prompt caching and batch. Routing waits for the eval.

How to bring in your own work

You have per-call cost ledgers in three repos and a measured routing table. You have not cut a large, real invoice by half.

esc

Narrow with repo:jm layer:eval q:naive mine · ↑↓ to move, enter to open