LLM Inference Pricing: How Cache Hits Shape Real API Costs
Cache-aware pricing makes LLM API costs depend on more than published token rates. This article examines the relationship between disaggregated inference and prompt caching, compares costs for high- and low-reuse workloads, and outlines practical ways to improve cache utilization and monitor spending.
As large language models become more capable, the cost of running inference is drawing increasing attention. In one next-generation model’s pricing update, standard input and output token rates increased severalfold over the previous generation, while cached-input pricing rose much more modestly.
This apparent inconsistency reflects changes in inference architecture as well as providers’ efforts to balance infrastructure efficiency with commercial pricing. For developers, it also changes how API costs should be evaluated: published token prices alone do not tell the whole story.
1. Why Cached-Input Prices Can Rise More Slowly
In the previous generation of the model discussed here, uncached input cost roughly six times as much as cached input, while output cost about 25 times as much. In the newer generation, those ratios widened to approximately 10:1 and 50:1, respectively.
Standard input and output rates increased substantially, but the cached-input tier saw the smallest increase.
One architectural development behind this pricing pattern is disaggregated serving, which separates the two main stages of LLM inference:
- Prefill: Processes the input context and is generally compute-intensive.
- Decode: Generates output tokens and is generally memory-bandwidth-intensive.
Traditional serving deployments often run both stages on the same compute node, creating resource contention and inefficient GPU memory use. Disaggregated architectures separate these stages and can introduce shared key-value (KV) cache pools supported by memory and high-speed networking.
In coding and long-document analysis workloads, system prompts and reference materials often remain largely unchanged across requests. Shared cache scheduling can make these frequently reused contexts available for subsequent inference, with cache hit rates exceeding 90% in some highly repetitive workloads.
By widening the price gap between cached and uncached input, providers create a financial incentive for developers to structure requests for reuse. Better cache utilization can reduce repeated processing and ease the platform’s overall compute load.
Pricing alone, however, does not establish which serving architecture a particular provider uses. The connection is best understood as an architectural and economic rationale for cache-aware pricing.
2. Modeling Costs by Workload
With separate prices for cached input, uncached input, and output, comparing headline token rates is no longer sufficient. Actual costs depend heavily on two workload characteristics:
- The input-to-output token ratio.
- The input cache hit rate.
The following examples use these assumed prices:
| Token category | Price per million tokens |
|---|---|
| Output | CNY 100 |
| Uncached input | CNY 20 |
| Cached input | CNY 2 |
These figures are used for the calculations below, rather than presented as a current price quote.
The effective input price is:
Effective input price =cached-input price × cache hit rate+ uncached-input price × (1 − cache hit rate)
If the input-to-output ratio is r:1, the blended cost per million total tokens is:
Blended cost =(r × effective input price + output price) / (r + 1)
Here, the cache hit rate represents the share of input tokens billed at the cached-input rate.
Scenario 1: Enterprise Coding Agent With High Context Reuse
An enterprise coding agent may read a large codebase as context while generating a comparatively small amount of output. Assume an input-to-output ratio of 20:1.
If the codebase context remains stable and is repeatedly reused within a session, the input cache hit rate may reach 90%.
The effective input price is:
2 × 0.9 + 20 × 0.1 = CNY 3.8 per million input tokens
The output price remains:
CNY 100 per million output tokens
The blended cost is:
(20 × 3.8 + 1 × 100) / 21≈ CNY 8.4 per million total tokens
High cache utilization substantially reduces the blended cost. Although output remains expensive, the workload contains far more input than output, and most of that input receives the cached rate.
Scenario 2: Independent Developer With Low Context Reuse
Consider a developer making occasional API calls with substantially different prompts each time. There is little reusable context.
Assume a 20% input cache hit rate and an input-to-output ratio of 5:1.
The effective input price is:
2 × 0.2 + 20 × 0.8 = CNY 16.4 per million input tokens
The output price is still:
CNY 100 per million output tokens
The blended cost becomes:
(5 × 16.4 + 1 × 100) / 6≈ CNY 30.3 per million total tokens
The low-reuse workload has a much higher blended cost. This pricing structure therefore favors standardized, context-heavy applications with substantial reuse over ad hoc requests with little shared context.
The difference is driven by workload characteristics—not simply by whether the customer is an enterprise or an individual developer.
A Python Cost Estimator
The following function estimates effective input pricing and blended cost for different cache hit rates and input-to-output ratios:
def calculate_cost(hit_rate, input_output_ratio,price_output=100, price_input_miss=20, price_input_hit=2):"""Calculate blended costs for a workload, in CNY per million tokens.:param hit_rate: Share of input tokens billed as cached input (0.0–1.0):param input_output_ratio: Input-to-output ratio, e.g. 20 means 20:1"""# Calculate the weighted average input price.avg_input_price = (price_input_hit * hit_rate+ price_input_miss * (1 - hit_rate))# Calculate the blended cost across input and output tokens.total_input_tokens = input_output_ratiototal_output_tokens = 1total_tokens = total_input_tokens + total_output_tokenstotal_cost = (total_input_tokens * avg_input_price+ total_output_tokens * price_output)cost_per_million_tokens = total_cost / total_tokensreturn {"effective_input_price": avg_input_price,"blended_cost_per_million_tokens": round(cost_per_million_tokens, 2)}# Test the enterprise coding agent scenario.print("Enterprise scenario:", calculate_cost(hit_rate=0.9, input_output_ratio=20))# Test the independent developer scenario.print("Independent developer scenario:",calculate_cost(hit_rate=0.2, input_output_ratio=5))
The resulting blended costs are approximately CNY 8.38 and CNY 30.33 per million total tokens, respectively.
These are normalized costs across input and output combined, not the price of a million-token request or a replacement for estimating total token volume.
3. Practical Strategies for Developers
When cached input is substantially cheaper than uncached input, context management becomes an application architecture concern rather than a minor prompt optimization.
1. Keep Stable Content at the Beginning of the Prompt
Place stable instructions, system settings, and reusable reference documents before dynamic user input.
Many prompt-caching mechanisms rely on prefix matching. Keeping the shared prefix consistent is therefore central to improving cache reuse. Reference documents belong in that prefix when they remain unchanged across the requests being optimized.
2. Manage and Reuse Conversation State
For multi-turn conversations and agent workflows, use the provider’s context-caching APIs or session-management mechanisms where available.
These mechanisms can help reuse existing context rather than repeatedly processing the full conversation history. The exact request format and whether context must still be transmitted depend on the provider’s API, so follow the relevant API documentation.
3. Build Token-Level Cost Monitoring
Tracking cache utilization in production requires visibility into individual API calls. Collect and analyze token usage details, including cached input, uncached input, and output wherever the API reports them.
Container platforms, logging services, and monitoring tools can support this workflow. Build cost dashboards that show cache hit rates and spending by application or business module.
These dashboards make it easier to identify changes in cache reuse and adjust prompt structure accordingly.
4. Conclusion
The shift from simple token pricing toward cache-aware pricing is closely connected to the evolution of inference infrastructure, including disaggregated serving and pooled cache management.
Higher headline rates can coexist with comparatively favorable economics for workloads that repeatedly reuse large contexts. Conversely, applications with little reusable input may face much higher effective costs.
For developers and enterprises, the practical lesson is to evaluate pricing against real workload characteristics. Measure input-to-output ratios, track the share of input tokens receiving cached rates, and structure stable context for reuse.
Effective context caching can help control API spending while supporting high-throughput, low-latency agent applications. As LLM applications mature, managing context efficiently is becoming an increasingly important engineering capability alongside selecting a capable model.
