LLM Inference Pricing: How Prefix Caching Reduces API Costs
A cloud provider’s reduction of cached-input pricing to 20% of its previous rate highlights the role of prefix caching in LLM inference economics. This article explains how cached inputs are processed and billed, why input and output tokens have different costs, and how prompt design, request routing, and usage monitoring can help teams turn cache discounts into measurable savings.
1. The Pricing Change: A Discount Focused on Cached Inputs
A cloud provider recently announced a price reduction for one large language model on its Model-as-a-Service (MaaS) platform, limited to a specific region. The key change was that the price for cache-hit input tokens would fall to 20% of its previous rate, while all other prices would remain unchanged.
Three details matter:
- The scope is limited. The change applies to one model service in one region, indicating targeted pricing for a particular inference resource pool rather than a platform-wide reduction.
- Only cached inputs receive the discount. The new rate applies to the portion of a request that hits the cache. Uncached input tokens and output tokens retain their existing prices.
- The reduction is substantial. Charging 20% of the previous rate means an 80% price cut for cache-hit inputs.
Understanding the practical impact requires a closer look at cached inputs and their role in LLM inference costs.
2. Why LLM Input and Output Tokens Are Priced Differently
Usage-based LLM pricing typically charges by token count, with separate rates for input tokens—the prompt—and output tokens—the completion. Output tokens often cost significantly more.
This difference reflects the computational characteristics of inference:
- Input processing, or prefill: The model processes the prompt’s tokens in parallel. This stage is compute-intensive and can take substantial advantage of parallel execution.
- Output generation, or decode: The model generates tokens autoregressively, one at a time. Each token depends on the preceding result. This stage is memory-intensive and offers less parallelism within an individual sequence, often making each output token more expensive to serve.
The additional distinction between cached and uncached input tokens comes from context caching, also commonly called prefix caching or prompt caching.
3. How Prefix Caching Works
3.1 The Core Idea
During inference, a Transformer computes intermediate key-value (KV) states for the input tokens across its layers. These states are repeatedly accessed during autoregressive generation.
Prefix caching builds on a simple observation:
If multiple requests share an identical input prefix—such as a system prompt, fixed reference documents, or few-shot examples—the corresponding KV states can be computed once and reused, rather than recomputed for every request.
This reduces the work required to process the shared portion of subsequent prompts.
3.2 What Determines a Cache Hit?
Cache hits generally require the prefix to match exactly at the token level.
Request A: [System prompt: 2,000 tokens][User question: 50 tokens][Output...]Request B: [System prompt: 2,000 tokens][Different question: 80 tokens][Output...]<------ Identical prefix ------>These 2,000 tokens can be reused from the cache
If a token differs within the shared prefix—even because of capitalization or whitespace that changes tokenization—the matching prefix ends at that point. Tokens beyond the mismatch cannot reuse that same cached prefix.
3.3 Cost and Performance Benefits
Prefix caching offers two main benefits:
- Lower costs: Cache-hit input tokens are billed at a discounted rate.
- Lower latency: Reusing cached KV states skips prefill computation for the matching prefix and can substantially reduce time to first token (TTFT).
A simple cost estimator separates cached inputs, uncached inputs, and outputs:
def estimate_cost(prompt_tokens, cached_tokens, output_tokens,input_price, cache_hit_price, output_price):# Prices are in CNY per 1,000 tokenscache_miss = (prompt_tokens - cached_tokens) / 1000 * input_pricecache_hit = cached_tokens / 1000 * cache_hit_priceoutput = output_tokens / 1000 * output_pricereturn cache_miss + cache_hit + output
For an illustrative calculation, suppose an application uses:
- A fixed system prompt of 8,000 tokens
- An average user question of 200 tokens
- An average output of 500 tokens
- An uncached input rate of CNY 0.50 per 1,000 tokens
- A cache-hit rate of CNY 0.10 per 1,000 tokens
- An output rate of CNY 1.50 per 1,000 tokens
Without caching, the input cost per request is:
8,200 / 1,000 × 0.50 = CNY 4.10
If the full 8,000-token system prompt hits the cache, the input cost becomes:
(8,000 / 1,000 × 0.10) + (200 / 1,000 × 0.50) = CNY 0.90
That is approximately a 78% reduction in input cost. Output cost remains CNY 0.75, so the total request cost falls from CNY 4.85 to CNY 1.65—approximately a 66% reduction.
The important distinction is that a discount on cached inputs does not translate directly into the same percentage reduction in the total bill. Overall savings depend on how much input is cached and how much the application spends on output generation.
4. How Teams Can Maximize Cache Savings
4.1 Structure Prompts for Reuse
- Put fixed content first. Place stable system instructions, domain knowledge, and few-shot examples at the beginning of the prompt. Put dynamic content, such as user questions and timestamps, afterward.
- Keep changing information out of the shared prefix. Inserting a changing value such as “Current time: …” at the start of a system prompt can prevent reuse of the otherwise stable content that follows.
- Group requests consistently. Route requests that share a system prompt through the same service configuration to improve the likelihood of cache reuse.
The goal is to preserve a long, identical prefix across requests without adding unnecessary content.
4.2 Align Routing and Conversation Management
In multi-turn conversations, keeping the existing context prefix consistent naturally supports cache reuse.
Repeated requests to the same model instance or resource pool also tend to have better cache reuse than requests distributed across separate pools. Routing and session-management decisions should therefore be considered alongside prompt design.
4.3 Make Costs Observable
Teams should use the provider’s usage records and billing details, supported by logging and monitoring tools, to track:
- Cache-hit rate over time
- Differences in cache-hit rates across business functions and prompt templates
- Average input and output token counts per request
A discounted rate is only one part of the cost equation. These metrics help establish whether requests are actually benefiting from the cache and where engineering changes could improve savings.
5. Three Caveats When Evaluating the Discount
5.1 Lower Cached-Input Prices Do Not Guarantee Lower Bills
If requests share little or no common prefix, the cache-hit rate may remain close to zero. In that case, a large reduction in cached-input pricing will have little effect on actual spending.
Realizing the discount may require changes to prompt structure and request patterns.
5.2 Region and Model Restrictions Still Apply
Pricing changes of this kind may be limited to a particular region or model version. Teams deploying across regions or using other versions must calculate costs using the rates applicable to those services.
A discount announced for one deployment scope should not be assumed to apply globally.
5.3 Longer Prefixes Are Not Always Better
Adding large amounts of rarely used reference material merely to create a longer shared prefix can be counterproductive.
When that prefix misses the cache, the extra tokens increase prefill work, latency, and input cost. Cache optimization must therefore balance reuse against the amount of context the application actually needs.
6. Conclusion
This pricing change illustrates how prefix caching can translate inference efficiency into lower customer costs. When cached states can be reused at scale, providers have more room to discount the input tokens that avoid repeated computation.
For application teams, however, the right conclusion is not simply “prices fell, so costs will fall.” Savings depend on how prompts are organized and how requests are served.
The practical priorities are straightforward: place stable content first, move dynamic content to the end, and monitor cache-hit rates. Together, these practices help turn discounted cached-input pricing into measurable reductions in API spending.
In token-based pricing, prompt structure is not just a matter of model behavior—it is also a cost-engineering decision.
