Behind LLM Price Cuts: Prefix Caching, KV Cache, and Inference Cost
LLM list prices can drop sharply, but your bill depends on which tokens are discounted, how prefix and KV caches actually work, and whether your prompts can reuse computation. This article separates per-request KV cache from cross-request prefix cache, shows what they save (and what they do not), estimates KV memory, explains high hit rates, and gives a cost model plus practical prompt and validation guidance.
How to read an LLM price cut
When list prices fall to a quarter of their previous level, it is easy to assume that the same call volume will cost far less. For developers and enterprises, the more useful questions are which billable items changed and whether real traffic can use the new structure.
A typical request has an input (prefill) stage and an output (generation) stage. Some services also split cached and uncached input. If only one class of input is cheaper while output, other input, or add-on fees stay the same, the whole request will not automatically fall to one-fourth of the old cost.
Evaluate a price cut on three levels:
- Price: Did every line item drop, or only specific tokens?
- Technology: Which mechanisms reduce compute, GPU memory, or scheduling overhead?
- Workload: Can your actual request shape turn into a lower cost per completed task?
Caching is a useful lens, but a price drop is not all cache, and a high hit rate does not imply an unpublished model architecture.
Two caches that are easy to confuse
The common mistake is treating KV cache within one generation and prefix cache across requests as the same thing.
1. KV cache in a single generation
KV cache reuses historical attention states in autoregressive decoding. The point is that each new token should not recompute keys and values for the entire history.
Tokens are the model’s units of text; they need not map one-to-one to characters or words. Generation can be sketched as:
existing input → emit one tokenexisting input + new token → emit one more tokenappend and continue
In causal self-attention, each position produces Q, K, and V. Past positions cannot see the future, so under the same model and context, appending a token does not change already-computed past K/V. Those states can be stored and reused on the next step.
2. Prefix cache across requests
Prefix cache targets another kind of repetition: many requests share the same beginning, for example:
fixed system rulesfixed task instructionsfixed reference materialthis user’s question
If a long shared prefix is stable, the service may reuse the corresponding K/V and skip repeating that prefill.
Prefix cache usually rests on reusable KV states, but whether reuse happens across requests, how long entries live, and how they are billed are product and ops choices. Using KV cache in one generation does not imply a high hit rate across users or requests.
What KV cache actually saves
Inference has two main phases.
1. Prefill (input processing)
The model processes the existing input, builds per-layer historical K/V, and produces the first generation step. Long inputs can be expensive. Without cross-request reuse, the same long materials are processed again and again.
2. Decode (stepwise generation)
Each step typically computes the new position, appends its K/V, and attends from the new query to accessible history. KV cache avoids recomputing past positions’ forward pass; it does not remove history from attention.
Under full attention, as context grows, each new token must touch more K/V. Long generation can still be limited by GPU memory, memory bandwidth, and attention cost.
“With cache, each step only computes one token” is a simplification. More accurately: the new position runs a new forward pass; past K/V are reused; attention to history still happens.
Estimating KV cache memory
For common attention layouts:
cache bytes = 2 × B × L × H_kv × D × S × W
2: keys and valuesB: parallel sequencesL: layers that keep cacheH_kv: KV heads per layer (not always equal to query heads; GQA/MQA share KV heads)D: dimension per KV headS: cached tokens per sequenceW: bytes per element
Example:
layers: 32KV heads: 32head dim: 128cached length: 4096 tokenselement width: 2 bytesbatch: 1
Per token per layer: 2 × 32 × 128 × 2 = 16384 bytes (16 KiB). Full cache: 16 KiB × 32 × 4096 = 2 GiB. Ten equal-length sequences without sharing: about 20 GiB.
This is cache capacity only, not total GPU memory. Weights, activations, workspaces, metadata, fragmentation, and headroom still apply. New output tokens grow S, so plan for max output length and concurrency, not input length alone.
Why hit rates can look very high
Near-100% hit rate is not a general model property; it comes from request shape plus cache policy.
1. A fixed prefix dominates input
If every call attaches the same long document and the user question is small, token-level hits can be high. Example: 9,000 fixed tokens and 1,000 changing tokens. If the fixed part is fully reused, about 90% of input tokens may be counted as hits. That is arithmetic, not a service SLA.
2. Variable content at the end
Strict prefix reuse needs a matching start. Putting time stamps or random IDs first breaks reuse of later identical material.
Harder to reuse:current time → random request id → fixed rules → fixed material → user questionEasier to reuse:fixed rules → fixed material → necessary dynamic fields → user question
Do not rewrite semantics just for hits. Permissions, tools, and safety instructions come first.
3. Reuse only while the entry still lives
Eviction, capacity, inter-request delay, and routing all matter. A request on a worker that cannot see the cache will not reuse even identical text. High hits need both prompt design and service-side placement.
4. Different definitions of “hit rate”
Possible metrics include: fraction of requests with any hit; hit tokens over all input tokens; hit cache blocks; or reused prefill work. A tiny shared header can count as a request-level hit while saving little compute. Align definitions before comparing numbers.
Prefix reuse is not semantic similarity
Same meaning does not mean interchangeable K/V. Strict prefix reuse needs the same token sequence and compatible model, positional handling, and runtime config. Spaces, newlines, field order, or punctuation can change tokenization and cut the reusable prefix.
Even identical later text usually has different internal states if earlier context changed; representation depends on what came before.
Do not mix:
- Prefix state reuse: skip recomputing the same context, then still generate for the current question.
- Result cache: return a stored full answer, which needs extra checks on the question, permissions, data freshness, and output constraints.
A cost model for real savings
request cost =uncached input tokens × uncached input price+ cached input tokens × cached input price+ output tokens × output price+ other applicable fees
This is not a billing contract; use the provider’s published rates.
Three implications:
- High input hit rate is not a free request. Long answers can still be dominated by output.
- Cheap input is not equally valuable for every task. Short-in/long-out generation vs. long-in/short-out document scoring benefit differently.
- Task cost includes retries, failures, human review, and ops. The metric that matters is total cost per successful task at required quality and latency.
How developers improve reuse
1. Stabilize the shared prefix
Keep role, format, and durable rules in a fixed place. Avoid rewriting templates every call and avoid random IDs or timestamps in the common prefix unless needed.
2. Canonicalize serialization
Use stable field order, whitespace, and formatting for structured data. Different strings for the same facts break prefixes. Do not drop information the task needs or hide updates.
3. Do not pad prompts for a nicer hit percentage
Irrelevant fixed text can inflate hit stats while growing cache size and later attention cost. Optimize resources to finish the task, not a single ratio.
4. Split shared material by task
Different jobs have different rules and corpora. Per-task templates reuse better and add less noise than one huge bag of unrelated context.
Validate performance, cost, and quality together
Use controlled groups:
- First-seen long prefix
- Same prefix, only the trailing question changes
- Small change at the start
- Similar length, different content
Record input/output tokens, reported cache hits and their definition, time to first token, end-to-end latency, billed cost, and answer accuracy/format. Cover concurrency, inter-arrival times, and output lengths; repeat. First requests may fill cache; do not mix them with steady-state hits.
Resident cache also uses GPU memory and can reduce concurrency. A faster single request does not always mean higher system throughput.
Cache must respect isolation and data lifecycle
Enterprise prompts may hold internal documents, personal data, and permission rules. Cross-request reuse needs explicit isolation and authorization. Identical text is not enough to share state across users or tenants. Define cache scope, TTL, access control, and invalidation.
After permission changes, document updates, or deletions, confirm stale cache cannot affect results. Prefix cache stores intermediate states, not necessarily final answers, but those states still come from input and belong in data lifecycle management.
Price is the headline; cost structure is the story
KV cache avoids recomputing past positions; prefix reuse cuts repeated prefill across requests. Both can improve cost and latency for some workloads. Gains still depend on prompt layout, retention, scheduling, and output size.
Do not judge a price cut by list prices alone, and do not treat one high hit rate as universal. Clarify cache types and metrics, then verify on real bills, quality, and system performance. The goal is not the largest cache number; it is completing the same valid work with fewer resources, reliably and safely.
