LLM Token Billing and Cache-Hit Cost Modeling: A Practical Guide
LLM API pricing is not a single per-million-token number: cache-hit input, regular input, and output tokens are billed at different rates. This article presents a practical cost model based on cache hit rate, token structure, and peak/off-peak pricing. It derives a weighted cost formula with a code example, compares two providers under 98% and 95% hit-rate scenarios, and shows how the cheaper option can reverse when cache hit rate falls. It also explains how to evaluate subscription packages and peak/off-peak policies through time-window differences, quota conversion, and fit judgment, then closes with recommendations for sensitivity analysis, cache expiration, scheduling, and periodic recalculation.
1. Why a Cost Model Is Necessary
The pricing structure of LLM APIs is far more complex than a simple “price per million tokens.” Current mainstream billing methods usually split a request into three parts: cache-hit input, regular input that misses the cache, and model-generated output. The unit prices for these three parts differ significantly. The cache-hit price may be only a fraction of the regular input price, while the output price is often several times the input price.
As a result, comparing only a single headline price can easily lead to wrong conclusions. Real cost depends on a combination of three variables: cache hit rate, input/output ratio, and calling time window. Any rigorous cost assessment should first define these three parameters clearly, then plug them into the pricing formula.
2. Building the Basic Cost Formula
Assume a model is priced as follows: cache-hit input price P_cache, regular input price P_input, and output price P_output, all in CNY per million tokens. For a batch of N tokens, the composition is:
- Cache-hit portion: ratio r (for example, 98%)
- Missed input portion: ratio i (for example, 1.5%)
- Output portion: ratio o (for example, 0.5%)
The comprehensive cost per 100 million tokens is:
weighted_cost_per_million = r × P_cache + i × P_input + o × P_outputcost_per_100M = weighted_cost_per_million × 100
Expressed as illustrative code:
def cost_per_100m_tokens(p_cache, p_input, p_output,hit_rate=0.98, input_ratio=0.015,output_ratio=0.005):"""Calculate comprehensive cost per 100 million tokens (CNY)."""per_million = (hit_rate * p_cache+ input_ratio * p_input+ output_ratio * p_output)return per_million * 100
This formula is the foundation of the entire cost analysis. The following sections use it to demonstrate two typical scenarios.
3. Scenario 1: Cost Comparison Under a High Cache Hit Rate
In scenarios such as code completion, long-document question answering, and multi-turn chat, system prompts and historical context are highly repetitive, so the cache hit rate can reach about 98%. With a token distribution of 98% cache hits, 1.5% regular input, and 0.5% output, one cloud provider’s model costs about CNY 12.57 per 100 million tokens. Another provider that offers more aggressive off-peak cache pricing costs about CNY 9.40 per 100 million tokens under the same structure.
The conclusion is straightforward: in high-hit-rate scenarios, the provider with the lower cache unit price has the lower comprehensive cost. Cache-hit tokens account for the overwhelming majority of token consumption, so the impact of the other two parts on total cost is heavily diluted. This is also why providers have been competing to lower cache prices in recent years: cache pricing directly determines the economic viability of Agent-style long-context applications.
4. Scenario 2: When Hit Rate Falls, the Conclusion Can Reverse
However, cache hit rate is not always controllable. It can decline significantly in the following scenarios:
- Context differs greatly from request to request, such as random document summarization
- The interval between requests exceeds the cache validity period, causing frequent cache expiration
- User requests are highly dispersed and lack a stable prefix
Lower the hit rate to 95% and plug it back into the formula: the originally more expensive option costs about CNY 14.92 per 100 million tokens, while the originally cheaper option, because its regular input price is higher, rises to about CNY 18.25. The ranking reverses.
This case shows that every one-percentage-point drop in cache hit rate corresponds to a meaningful cost transfer—from the low-priced cache range to the high-priced regular input range. When selecting a model, do not rely only on the ideal hit rate promoted officially. Instead, estimate the hit-rate range based on your own business request patterns and run sensitivity analysis, such as measuring at 98%, 95%, and 90%, to reach a robust conclusion.
5. Evaluating Peak/Off-Peak Pricing and Subscription Packages
In addition to pay-as-you-go billing, major cloud providers generally offer subscription packages, usually divided into monthly tiers such as entry, professional, and flagship, as well as peak/off-peak time-of-day pricing. To evaluate whether a package is cost-effective, three conversions are essential:
1. Time-window policy differences: Different platforms define “peak” with different breadth. Some providers define peak hours as only 4 hours per day, giving broader coverage; others have longer peak periods, so package benefits are consumed faster during peak hours. Even with the same “X billion tokens per week” quota, the actual usable amount can differ significantly because of time-window definitions.
2. Quota conversion: Convert the token quota included in a package back to the API list-price value using the official conversion ratio. For one provider, for example, the weekly quotas of its three tiers correspond to API list-price values of about CNY 160, CNY 955, and CNY 2,229, while the monthly package fees are CNY 118, CNY 538, and CNY 1,078. The package unit price is roughly 50%–70% of the API list price.
3. Fit judgment: The conversion ratio is only a baseline. The real benefit depends on whether your usage can fill the quota. You can use the following logic for the decision:
Monthly API estimated cost = monthly token volume × comprehensive unit price (including hit-rate and time-window adjustments)If monthly API cost > package fee × 1.2 → package is more cost-effectiveIf usage fluctuates widely and peak months far exceed quota → combined model (package + overage pay-as-you-go) is more robust
6. Practical Recommendations
- Profile before selecting: Measure your own request token structure, including input/output ratio and context repetition, instead of applying generic assumptions.
- Run multi-tier sensitivity analysis: Cover at least high, medium, and low hit-rate scenarios to avoid being misled by a single scenario.
- Pay attention to cache expiration strategy: The match between cache validity period, invalidation granularity, and request rhythm directly determines the upper limit of the hit rate.
- Schedule by time window: For non-real-time batch tasks such as offline data labeling and log summarization, schedule execution during off-peak periods whenever possible to reduce costs significantly.
- Recalculate regularly: Model pricing and package policies update frequently. Rerun the cost model every quarter and codify the calculation logic in scripts to keep the accounting consistent.
7. Conclusion
The essence of LLM cost evaluation is a three-variable function: cache hit rate × token structure × time-window pricing. Any single-point price comparison can be misleading. Only by building your own cost model and feeding in real business parameters can you reach a credible selection conclusion. Whether using pay-as-you-go billing or subscription packages, the final measure should return to “cost per unit of effective output”—that is the real economics of technical selection.
