Optimization

The Cheapest Token Is the One You Don't Recompute

Prefix caching and prompt reuse in AI serving: how cache hits cut input cost and first-token latency, how prompt structure determines hit rates, and the isolation and measurement caveats that decide whether reuse is safe.

The Cheapest Token Is the One You Don't Recompute
Optimization · Inference Watch

At a glance

  • Prefix reuse cuts both input cost and first-token latency when prompts share a stable head.
  • Structure prompts longest-shared-first: system brief, then documents, then the variable ask.
  • Hit rate is a design outcome, not a platform feature; measure it per workload.
  • Caching improves speed and cost, not quality; outputs should be identical to an uncached run.

A large share of production input tokens are not new. They are the same system brief, the same retrieved passages, the same document under review, sent again on the next request. Recomputing them on every call is pure waste: the model already did the work.

Prefix reuse — sometimes called prompt caching or KV cache reuse — is the mechanism for not doing that work twice. It is one of the few optimizations that lowers cost and latency at the same time, which makes it worth designing for rather than discovering.

What actually gets reused

Reuse happens at the level of the prompt prefix. If two requests begin with the same sequence of tokens, the serving system can keep the computed key/value state for that sequence and start decoding from there. The longer and more stable the shared prefix, the more work is avoided.

This means prompt layout determines the benefit. A prompt that puts a variable customer name in the first line breaks the shared prefix for every request. A prompt that puts the shared brief first and the variable question last preserves it. For how this state relates to quality, see KV Cache and Token Quality.

Design prompts longest-shared-first

  1. System brief and rules. Stable for the workload; put it first.
  2. Retrieved or attached documents. Shared across a batch of questions about the same document; next.
  3. Conversation history or task context. Shared within a session.
  4. The variable ask. Last, because it changes every time.

Avoid writing timestamps, request identifiers, random ordering of retrieved passages or per-user greetings into the shared head. Each of those silently resets the cache and the savings.

Read the pricing, not just the feature

Many token services price cached input differently from fresh input, often at a discount, because it costs less to serve. That is a legitimate line item to negotiate, and it changes the economics of the workload: a task dominated by a large shared document can be much cheaper than its raw input count suggests.

Ask three questions of any provider: is reuse automatic or configured, how long does a cached prefix persist, and how is cached input billed. A provider that offers the feature but bills it identically to fresh input is offering latency, not savings. See Token Metering and Billing for the reconciliation side.

Isolation and correctness

Reuse must not leak one customer's content into another's request. Providers handle this through isolation guarantees, but a self-hosted deployment needs explicit design: cache keyed by tenant and prompt hash, eviction under memory pressure, and no cross-tenant sharing of user-supplied prefixes. Document the policy; it will be asked in procurement.

Correctness is the other constraint. Cached and uncached runs should produce equivalent outputs. If a provider's cache changes results, that is a bug. Include a cached-versus-fresh comparison in your acceptance tests, and treat a difference as a failure rather than a new normal. The test design is in A Quality Bar You Can Test.

Measure the hit rate

The benefit is bounded by the hit rate, and the hit rate is a property of your prompt design and traffic, not of the platform alone. Measure cached input tokens as a share of total input tokens, per workload, and track it over time. A drop usually means someone added a timestamp to the shared brief.

Then compute the effective input price: fresh tokens at list, cached tokens at their rate, weighted by the observed mix. That is the number to compare across providers, and the reason two identical rate cards can produce different bills.

What we watch

  • Whether the prompt is ordered with the shared head first.
  • Whether the provider bills cached input separately and at what rate.
  • Whether tenant isolation for cached prefixes is documented.
  • Whether hit rate and effective input price are measured per workload.

Prefix reuse rewards the same discipline that makes any serving work cheaper: understand where the repeated cost is, and stop paying it twice. It is not a clever trick so much as an acknowledgement that most production prompts are variations on a theme — and the theme is the part worth caching.

Questions buyers ask

What is prefix caching?

Prefix caching stores the computed state for an identical leading portion of a prompt — typically the system instruction or a shared document — and reuses it on later requests that begin the same way. It avoids recomputing those tokens and usually reduces time to first token.

Does prompt caching affect output quality?

It should not. Reusing computed state for identical text is mathematically the same as recomputing it; if outputs differ materially between cached and uncached runs, that is a defect to investigate, not a trade-off to accept.

How do we improve cache hit rates?

Order the prompt so the longest shared content comes first and the variable part comes last, keep the shared head byte-identical across requests, and avoid timestamps or request IDs at the top of the prompt that change every call.

Filed in Optimization. The wider frame — how serving cost and token quality travel into price — is in The Transmission.

IW

Inference Watch Research

Inference Watch covers AI compute and inference infrastructure. Company Watch items are reproduced with attribution and are not independently verified.