LLM Prompt Caching and Input Billing: A Technical Breakdown of Cache-Hit Discounts
This article explains how charging 20% of the original input price for cache hits changes LLM service billing, why the discount depends on cache hit rate rather than list price, and how prompt structure affects actual cost. It covers what prompt caching stores, a cost model for estimating savings, a practical checklist for improving hit rates, common implementation pitfalls, latency and architecture benefits, and methods for benchmarking cost and performance before and after the change.
1. What Actually Changed: A Pricing Structure Adjustment, Not a Blanket Price Cut
A cloud provider’s model-as-a-service platform announced that, starting at 00:00 Beijing time on November 23, 2026, it would adjust billing for a large model service in one region: the cached portion of input tokens would be charged at 20% of the original rate, while all other billing items stay the same. The technical significance is not how large the discount is, but that the “input” billing dimension is now split into two tiers: cache hit and cache miss.
This distinction matters: a lower unit price does not mean a proportionally lower bill. Actual spend depends on the hit rate, which is determined by how requests are constructed, how stable the context is, and the concurrency and routing strategy. Treating this as a structural pricing change is the only way to avoid drawing the wrong conclusions.
2. What Prompt Caching Actually Caches
Large model inference has two phases: prefill and decode. Prefill runs the input sequence through attention computation in one pass and produces reusable intermediate states, commonly called the KV cache. This computation scales roughly linearly with input length and is the main cost driver in long-context scenarios.
The idea behind prompt caching is that if multiple requests share the same prefix (system prompts, tool descriptions, knowledge base snippets, few-shot examples), the prefill result for that prefix can be reused, and subsequent requests only compute the incremental part. A “cache-hit input” charge is therefore a discount on repeated computation of a reusable prefix.
The boundaries need to be clear: hit detection usually requires the prefix to match exactly, byte by byte or token by token; the output, the uncached incremental input, and any per-call fees that some platforms list separately are generally not discounted. This is consistent with the original statement that other prices remain unchanged.
3. Cost Model: Writing the Bill as a Computable Formula
Let p be the unit price for uncached input, 0.2p the unit price after a hit, with output pricing and per-call charges unchanged. The total cost of a single request can be expressed as:
Cost = p * (L_uncached) + 0.2p * (L_cached) + q * L_out + c
Here L_uncached is the uncached input length, L_cached is the cached length, q is the output unit price, and c is the fixed per-call cost. With a hit rate of h = L_cached / (L_cached + L_uncached), the savings on the input side are 0.8h.
The conclusion is straightforward: the higher the share of input in total cost and the higher the hit rate, the greater the benefit. Some rough rules of thumb:
- Significant savings when the system prompt and knowledge base make up more than half of the total input and are repeated on every turn.
- Near-zero savings for short prompts, single-turn requests, or extraction tasks where every input is different; there is no need to re-architect for these.
- Limited improvement to the overall bill when output is long and input is short.
4. A Checklist for Improving Hit Rates
- Stabilize the prefix: move volatile content (timestamps, request IDs, randomly ordered candidate sets) to the end of the prompt so it does not pollute the prefix.
- Normalize content: standardize whitespace, line breaks, punctuation, and casing, and never concatenate uncleaned user input into the front of a template.
- Version templates: treat a prompt template change as a cache invalidation event, roll it out gradually, and assess cost fluctuations.
- Design in segments: order content as “stable knowledge block, semi-stable conversation history, volatile instructions” to maximize the reusable length.
- Session stickiness: route multi-turn conversations to the same instance or cache domain to avoid repeated prefill caused by load balancing.
- Observability: track cached length, uncached length, and output length separately instead of only looking at total tokens.
Illustrative pseudocode:
def build_prompt(knowledge, history, user_input):# Stable prefix first, volatile content laststable = normalize(knowledge) # Fixed order, normalized contentsemi = format_history(history) # Append-only growthvolatile = f"User input: {user_input}\nCurrent time: {now()}"return stable + semi + volatile
5. Common Pitfalls in Practice
First, putting variable fields at the front. A single differing character invalidates the prefix and sends the cost back to the original rate. Second, ignoring isolation and compliance requirements when using a shared “common prefix” across tenants; cache reuse must align with data boundary policies. Third, focusing only on unit price rather than structure, so hit rates improve only marginally while template maintenance complexity grows. Fourth, lacking a rollback plan: template changes should be quickly revertible and paired with monitoring and alerts for cost, latency, and error rates.
6. Architecture-Level Benefits
Cache hits save money and also reduce prefill latency, which noticeably improves experience for first-byte-sensitive scenarios such as intelligent customer service, code completion, and document question answering. On the engineering side, stable knowledge can be version-managed in object storage, traffic peaks can be smoothed with a message queue, a container platform can host a stateless inference gateway, and log services plus monitoring and alerting can form a cost dashboard. If you use Baidu AI Cloud’s general capabilities, it is still advisable to organize load testing and capacity planning around the idea that “hit rate is the core metric.”
7. Evaluation and Load Testing Methods
Run a controlled comparison before and after the change: fix a business sample set and record average input length, hit rate, cost per request, and end-to-end latency. Break results down by scenario (long-document question answering, multi-turn customer service, batch extraction) so averages do not hide the long tail. Set cost guardrails that trigger a review when the hit rate or pricing structure changes.
8. Conclusion
The signal from this kind of pricing adjustment is that the focus of inference cost optimization is shifting from “switching to a cheaper model” to “organizing context more intelligently.” For developers, the lever that is actually under your control is prefix design and hit rate, not passively waiting for price changes. Only by writing the cost model clearly and making hit rate an observable metric can you quickly assess the benefit and make trade-offs when the pricing structure changes.
