Measure before you optimize: the honest way to cut LLM spend
Cost work without per-request attribution is guesswork with a budget attached. What to instrument first, and which levers actually move the number.
Cost work without per-request attribution is guesswork with a budget attached. What to instrument first, and which levers actually move the number.
At some point every AI team gets the same instruction: cut the model spend. The common shortcut is to switch to a cheaper model and see what breaks. Occasionally that works. Without measurement it is a coin flip with a budget attached, and the coin flip usually costs more than the instrumentation would have.
The invoice gives you a total. It cannot tell you why the total is what it is. The unit that can be optimized is the individual request path, decomposed:
None of this needs elaborate tooling. It is structured logging at boundaries the system already has, aggregated per feature. What teams find is rarely what they expected: the model choice turns out to be fine, and the real cost lives in duplicated retrieved context or a retry loop nobody knew existed.
The least glamorous and usually the largest win. Deduplicate retrieved content, trim history to what the task needs, move static instructions out of per-request context so prompt caching can hold them, and send passages instead of whole documents.
One user action triggering five model calls is five times the cost. Batch where you can, merge prompts where quality allows, and make every retry a deliberate decision instead of a default.
Deterministic caching for identical requests. Semantic caching where near-duplicates are genuinely interchangeable, which is a product decision to be validated by evaluation rather than an infrastructure default.
Right-size the model per task: fast models for classification and extraction, stronger models for reasoning-heavy steps. A quality-gated router beats one expensive model for the whole pipeline, but the gating requires the evaluation suite from day one.
Streaming, progressive disclosure, and deferring expensive work until it is needed. Perceived latency is a product property as much as an infrastructure one.
Every lever above can degrade quality, and ungated optimization is how a cheaper product becomes a worse product. One rule prevents it:
No optimization ships without passing the same evaluation used for releases.
If that evaluation does not exist yet, build it first. It is smaller than it looks from the outside, and it is what makes every cost decision after it cheap.
Run it that way and the before/after numbers survive scrutiny, which is what separates cost engineering from cost theater.