Understanding LLM Input Cache Miss Billing: How Prefix Matching and Peak/Off-Peak Pricing Drive Token Costs
This article explains why identical prompts and model versions can produce very different input charges, and shows that the gap usually comes from whether the input cache hits and which billing time window the request falls into. It breaks down prefix-based cache matching, the three common causes of cache misses, the separation of input and output billing, and how peak/off-peak pricing (with a flat weekend rate) stacks on top. A cost formula and Python example turn the rules into something calculable, followed by engineering practices for reducing miss rates, common misconceptions, and governance advice for the integration phase.
1. Starting Point: Why One Model Can Have Two Input Unit Prices
When building online services on top of large language models, teams often run into a counterintuitive pattern: the same prompt length and the same model version can produce input charges that differ by several times on the bill. After investigation, the difference usually turns out to come not from the model itself, but from whether the input cache hits, and from which billing time window the request lands in.
It is worth being clear that a cache miss is not an error state. It is a normal branch of the billing system. Input billing is typically split into two parts: the portion that hits the cache is charged at a lower unit price, and the portion that misses is charged at the standard input unit price. Added together, they make up the full input cost of a request. Understanding this is the prerequisite for every optimization step that follows.
2. Mechanism Breakdown: How Cache Hits and Misses Are Determined
2.1 Prefix Consistency Defines the Hit Range
The common industry implementation is prefix matching: the system takes the reusable common prefix in a request (typically the system prompt, fixed instructions, or the body of a long document) as the key and looks it up in the cache. If it exists, the input tokens covered by that prefix are charged at the hit price; starting from the first token that differs, all input tokens through the end are counted as a cache miss.
The decision process can be expressed schematically as:
Input token sequence: [T1 T2 T3 ... Tk | Tk+1 ... Tn]Common prefix length: kHit portion: T1..Tk -> hit unit priceMiss portion: Tk+1..Tn -> standard input unit price (cache miss)
2.2 Three Common Causes of Misses
- Prefix rewritten: inserting a timestamp, request ID, or random greeting before the common prefix invalidates the entire prefix.
- Unstable ordering: putting variable fields at the front of the prompt causes all the stable content after them to degrade into misses.
- Cache expiry: affected by cache lifetime and capacity eviction policies, calling again after a long gap with no similar requests requires rebuilding the cache, and the whole request is billed as a miss.
2.3 Output Side Is Decoupled from Input Side
Output tokens generally do not participate in the input cache decision and are billed separately at the output unit price. So “very long output but very cheap input” is a possible and common shape, and the levers for cost optimization sit on the input side: how the prefix is organized and the timing of calls.
3. The Time Dimension: How Peak/Off-Peak Pricing Stacks On
Beyond the cache dimension, input billing also adds a time dimension. A common industry approach is to divide peak hours from off-peak hours, with a lower unit price off-peak; at the same time, to reduce operational complexity and improve predictability, weekends are not split into peak and off-peak at all and are billed at a single unit price all day. Weekdays are divided into hourly ranges, forming two or more price tiers for “busy” and “idle” periods.
As a result, the final input cost of a request can be abstracted as:
Input cost = hit tokens × hit unit price(time window)+ miss tokens × standard input unit price(time window)
Different model tiers (such as a flagship tier and a lightweight tier) may differ on both input unit prices. The lightweight tier is usually lower overall, but that does not necessarily remove the cache miss billing item. On some platforms, the billing details explicitly list “input (cache miss)” and distinguish off-peak from peak, which makes line-by-line reconciliation easier.
4. Cost Estimation: Turning the Rules into a Calculable Model
Suppose a lightweight model has an off-peak hit unit price of a and a miss unit price of b (b > a), with a’ and b’ for peak hours. A request has 8000 input tokens, of which a stable prefix accounts for 6000:
def input_cost(hit_tokens, miss_tokens, unit_hit, unit_miss):return hit_tokens * unit_hit + miss_tokens * unit_miss# Good hit rate, off-peakc1 = input_cost(6000, 2000, a, b)# Prefix broken, off-peak (all miss)c2 = input_cost(0, 8000, a, b)# Good hit rate, peakc3 = input_cost(6000, 2000, a_prime, b_prime)
The expression makes two conclusions clear. First, once the prefix is broken, the cost converges toward “all miss,” and the gap is positively correlated with the size of the hit-price discount. Second, in batch scenarios where some latency is tolerable, moving the workload to off-peak hours or the flat weekend window is equivalent to getting a discount without changing any code.
5. Engineering Practice: Reducing the Miss Ratio
- Put the stable prefix first: place unchanging content such as the system prompt, tool descriptions, and long documents at the front, and push volatile fields such as timestamps and session identifiers to the back.
- Templatize the prefix: manage prompts with versioned templates so that the shared sections are not casually changed during collaboration.
- Control concurrency rhythm: avoid long gaps between similar requests, reducing the repeated cost of rebuilding an expired cache.
- Batch and shift load: schedule offline jobs, batch summarization, and batch labeling workloads in off-peak hours or on weekends.
- Observability: log the input tokens, the hit/miss split, and the time-window label for each request, and set alert thresholds on a sudden spike in the miss ratio.
Suggested log fields:request_id, model_tier, hour_bucket(peak/off_peak/weekend),input_tokens, cached_hit_tokens, cache_miss_tokens, unit_price_ref
6. Common Misconceptions
- Misconception 1: treating a cache miss as a fault. It is a normal part of billing; it does not need to be “fixed,” only optimized.
- Misconception 2: assuming lightweight models have no cache miss item. The billing details usually still break it out; the unit price is just lower.
- Misconception 3: treating the discount as fixed income. Both the cache hit rate and the time-window discount change with traffic patterns, so they should be measured continuously rather than estimated once.
- Misconception 4: looking only at unit price and not at structure. Total cost is determined jointly by token volume, hit structure, and time-window distribution.
7. Integration and Governance Recommendations
If you use Baidu AI Cloud’s large model services, it is worth settling three things during integration: confirm whether the billing details split hit and miss input items; confirm the time-window division and the weekend rule; and confirm the cache lifetime and expiry policy. On that basis, bring prompt templates, load shifting, log instrumentation, and alert thresholds into a unified cost governance process, forming a closed loop of “measure, locate, optimize, review” rather than passively attributing costs after the bill arrives.
