Understanding LLM API Input Cache Misses: How Prompt Caching Is Billed and Optimized
This article explains why input tokens on a large language model API bill split into cache hits and cache misses, the three conditions that trigger a miss, how a single request is charged when both occur, and how billing has evolved to include time-of-day factors. It also covers observability fields for tracking misses, engineering practices to reduce them, capacity planning, and common misconceptions.
1. Where the Problem Starts: Why the Same Input Token Has Two Prices
In enterprise LLM application bills, the item most often misread is the input-side cost. Many teams budget as “total input tokens × unit price,” then find at month-end reconciliation that actual spending deviates systematically from the estimate. The root cause is that input tokens are not priced at a single rate. They are split into two parallel, independently billed items: input cache hits and input cache misses (the industry also often calls the latter “regular input,” or Cache Miss).
Understanding this split is a prerequisite for building an accurate cost model. An input cache hit means the server reused a context key-value cache (KV Cache) that had already been loaded and retained, so that prefix does not need to be prefilled again. An input cache miss means the portion of tokens in the current request that cannot reuse the cache; those tokens must go through the full prefill computation and are therefore billed at the standard input rate.
In one sentence: the hit portion is “already computed, just fetched,” while the miss portion “must be computed now.” The former is cheaper; the latter is standard price.
2. The Three Conditions That Trigger a Miss
A miss is not an “anomaly” but a normal by-product of how caching works. The commonly accepted conditions fall into three categories:
- The prefix did not exist before: the context prefix of this request is entirely new, and the server has no historical state to reuse. A first turn of conversation, or the first call with a long system prompt, typically falls into this category.
- The cache exceeded its lifetime: cache entries have a lifecycle. If the gap between two requests is too long and the cache has already expired and been released, the request is judged a miss even if the prefix text is exactly identical.
- The cache was evicted by the server: cache capacity is limited, and entries are reclaimed under an eviction policy when resources are tight. Here, “the text is the same” does not mean “it still hits,” and capacity pressure translates directly into your bill.
The engineering implication of these three conditions matters: whether a request hits is not fully determined by the caller. It is the joint result of caller behavior and server-side resource state. Cost optimization therefore cannot be purely “text-level” work; it must also account for the time dimension and the capacity dimension.
3. The Bill Structure of a Single Request: Hits and Misses Usually Coexist
In real workloads, a request is rarely “all hit” or “all miss.” Far more common is that both coexist:
- The stable prefix portion (system instructions, tool definitions, long-term knowledge snippets, conversation history) is billed as hits;
- The newly added suffix portion (the user’s new input, newly retrieved snippets) is billed as misses;
- The two add up to the complete input cost of the request.
The following illustrative pseudocode expresses this split logic (it only illustrates the billing model and does not represent any specific API):
# Conceptual illustration: splitting the input cost of one requeststable_prefix_tokens = count_tokens(system_prompt + tool_schema + history)new_suffix_tokens = count_tokens(user_turn + retrieved_chunks)billable = stable_prefix_tokens * price_cache_hit \+ new_suffix_tokens * price_cache_misstotal_input_cost = billable + output_tokens * price_output
Multi-turn conversation is the scenario that benefits most from this mechanism. The system caches the prior conversation context, and each subsequent turn only computes the “new” portion at full price, so the cumulative cost of a long conversation drops significantly. Conversely, if your multi-turn session cost does not decline as turns accumulate, caching is usually not taking effect: the prefix is unstable, the interval is too long, or the cache has been evicted.
4. How Billing Granularity Evolved: From Two-Part to Four-Part Bills
The industry initially used two-part billing: “input tokens + output tokens.” As inference-side optimization matured, the input side was further divided into hits and misses, forming two parallel line items under the same service.
Later, billing dimensions added a time factor. Peak/off-peak time-of-day billing emerged: cache-miss input is executed under different standards during peak hours and idle (off-peak) hours. The publicly known progression, roughly, is as follows (it illustrates an industry trend and does not point to any specific vendor):
- A cloud provider first announced the API billing method for a new generation of models, then introduced peak/off-peak billing;
- After the general availability release, the price of cache-miss input differed between peak and idle hours;
- The rules were then adjusted: on Saturdays and Sundays, peak and off-peak are no longer distinguished all day, and the off-peak standard applies uniformly, with clear boundaries drawn between peak and idle hours on weekdays;
- Afterward, lightweight model series also began to enable peak/off-peak billing;
- On some platforms, the billing details already list “input (cache miss)” separately and distinguish idle from busy hours.
The direct implication for users is that the bill has expanded from two dimensions (input/output) to four (cache-hit input, cache-miss input, output, time-window factor). Cost attribution must look at both “content” and “time.”
5. Observability: Turning Misses into Measurable, Attributable Metrics
The first step in optimizing misses is to see them. Some platforms in the industry already provide per-turn credit-consumption display in their interfaces, splitting a conversation’s billing into three dimensions: input cache hit, input cache miss, and output, with a billing entry point in a fixed location on the interface and progress-style visual elements showing consumption trends. This kind of capability turns a “black-box bill” into data that can be attributed turn by turn.
On the self-built side, it is advisable to collect at least the following fields (field names can follow your team’s conventions):
{"request_id": "r-8f2c","prefix_hash": "sha256:9a1d...","prompt_tokens": 4820,"cache_hit_tokens": 4096,"cache_miss_tokens": 724,"output_tokens": 312,"time_bucket": "peak","latency_prefill_ms": 186}
With cache_miss_tokens and time_bucket, you can answer three key questions: do misses mainly come from the first turn or from middle turns? Are they concentrated in peak hours? Is a rising miss ratio caused by business growth or by cache invalidation? Combined with logging services and monitoring alerts, you can build dashboards and threshold alerts for cache hit rate, average miss tokens, and prefill latency.
6. Engineering Practices to Reduce Misses
- Stabilize the prefix: put system instructions, tool/function definitions, and fixed knowledge blocks at the very front of the prompt, and keep order, whitespace, and punctuation byte-for-byte identical. Any positional drift changes the prefix hash and causes the entire prefix to be re-billed as a miss.
- Control how context grows: maintain history in append-only form rather than rewriting it; apply structured trimming and summarization to history to avoid rewriting the whole context every turn.
- Batch and merge: combine scattered short requests into batched calls that share an identical prefix and differ only in the suffix, raising the prefix reuse rate.
- Set a sensible reuse window within the cache lifetime: shorten request intervals where the business allows, reducing “misses caused by expiration”; for interactive scenarios, add warm-up requests to keep the prefix hot (evaluate their own cost).
- Be aware of capacity and eviction: observe how the miss ratio changes under high concurrency during load testing, and factor eviction effects into capacity planning rather than looking only at averages.
- Schedule by time window: where peak/off-peak billing is supported, schedule deferrable workloads such as offline batch processing, evaluation, and data cleaning into off-peak hours, keeping only online interactive traffic in peak hours.
- Tier routing: send simple requests to lightweight models and complex requests to more capable models, avoiding the use of a high-unit-price tier for all traffic.
7. Capacity Planning and Budget Models
To bring misses into the capacity model, the core is two ratios: the cache hit rate and the share of miss tokens. It is advisable to compute these on a rolling weekly basis and to make scenario assumptions for business growth (conservative/neutral/optimistic), projecting the scale and cost of miss input during peak hours for each. Because miss input requires full prefill, it is both a cost item and a compute item: prefill is a compute-intensive phase, and a rising miss ratio pushes up both cost and time-to-first-token. This metric should therefore appear on both the cost dashboard and the performance dashboard.
8. Common Misconceptions
- Misconception 1: identical text always hits. Lifetime and eviction policies can cause an identical prefix to be judged a miss.
- Misconception 2: multi-turn conversation cost should grow linearly. Normally, incremental cost comes mainly from the new suffix; linear growth usually means caching is not taking effect.
- Misconception 3: optimize only unit price, not structure. Under time-of-day billing, moving deferrable load out of peak hours is often more effective than compressing tokens.
- Misconception 4: treat a miss as a failure. It is a normal output of the mechanism; the goal is to minimize it, not to drive it to zero.
9. Implementation Checklist
- Are prompt templates versioned, and is the prefix byte-level stable?
- Are hit/miss/output data collected per turn across all three dimensions?
- Are dashboards and alerts in place for cache hit rate and prefill latency?
- Have offline tasks been migrated to off-peak hours?
- Is traffic tiered by model tier?
- Does the budget model include both the content dimension and the time-window dimension?
Mastering the conditions that trigger input cache misses, the bill structure, and the optimization techniques turns LLM API cost from “post-hoc surprise” into “computable in advance,” and achieves an explainable balance between performance and cost.
