Skip to content

Cut cost and latency, keep the quality

Decide which optimizations (prompt caching, batching, model routing, output limits, context reduction) fit a system's cost or latency problem, and reject the ones that would push quality below its threshold.

Scenario

A legal-operations platform reviews supplier contracts for a bank. Volume tripled this quarter, and so did the API bill. The CFO asks for a 40% cut by next month.

The first proposal on the table: "Move everything to the smallest model." It would hit the number. It would also miss clauses the bank's lawyers rely on.

Explanation

Optimization is a decision about which metric you can spend. Start from data: where do the tokens and the waiting time go? Then sort the levers by how much quality they put at risk.

Levers that don't change the answer:

  • Prompt caching. Reuses a prompt prefix that is identical across requests: tools, system prompt, long reference documents. It cuts input cost and time to first token for the cached part. It needs an exact match up to the breakpoint, reuse within the cache lifetime (5 minutes by default, refreshed each time it is read; a 1-hour option costs more to write), and has no effect on the output. Check cache_read_input_tokens in the usage to see it working.
  • Batching. The Message Batches API processes requests asynchronously at a lower cost. Most batches finish within an hour, but results can take up to 24 hours, and there is no streaming. Ideal for overnight runs, backfills and evals; wrong for anyone waiting on screen.
  • Streaming. Shows the answer as it is generated. It doesn't make anything cheaper, but users see output sooner.

Levers that can change the answer, so each needs an eval run:

  • Model routing and effort. A faster tier or a lower effort level cuts cost and latency. Anthropic's guidance: tuning effort is often a better lever than switching models. Adopt it where the eval stays above threshold.
  • Output limits. Asking for a shorter answer saves output tokens. A hard max_tokens cut is blunt: the response stops mid-sentence, so it suits short answers where the result comes first.
  • Context reduction. Fewer retrieved chunks, trimmed history and shorter documents cut input tokens. Remove what the task doesn't use, and keep what it does.

The rule: apply the levers that don't touch quality first. Apply the others one at a time, and only with an eval result that stays above the agreed threshold. A saving that the eval can't confirm isn't one.

Worked example

The legal-ops team measured before deciding. Last month's breakdown:

Workload Share of spend Latency need Finding
Clause extraction (interactive) 45% Lawyer waits on screen 18,000-token playbook resent uncached with each contract
Nightly portfolio re-scoring 35% Report due 07:00 Runs as 6,000 synchronous requests at night
Risk memo 20% Lawyer waits Eval at 93% against a 90% bar

Before: "Move everything to the smallest model." Untested, and it risks the memo, the step with the least margin.

After, one lever per finding:

  1. Cache the playbook on the extraction step. Same output, lower input cost, faster first token. The usage fields confirm cache reads.
  2. Batch the nightly re-scoring. Nobody reads it before 07:00, so asynchronous processing costs nothing in quality. Most batches finish within an hour, but one can take up to 24 hours, so the job submits it at 19:00. If it hasn't ended by 05:00, the job cancels it, keeps the partial results, and runs the unfinished requests synchronously in time for the report.
  3. Test a lower effort on extraction against its eval. It passes at 97% against a 95% bar: adopt.
  4. Reject a smaller tier for the memo. On the eval it drops to 84%, below the 90% bar. Keep the memo as it is.

Steps 1 to 3 together meet the CFO's target, and every quality bar still holds.