LLM API Cost Modeling: Cache Hit Rate, Token Mix, and Subscription Plans
This article explains why comparing LLM API costs by cache price alone can be misleading. It introduces a unified token-weighted cost model, analyzes cost crossover points under different cache hit rates, and evaluates off-peak pricing and subscription plan break-even thresholds. It also outlines monitoring metrics and pseudocode for calculating real costs, then provides practical guidance for choosing between pay-as-you-go pricing and subscription plans based on workload token structure.
LLM API Cost Modeling: Cache Hit Rate, Token Mix, and Subscription Plans
When selecting an LLM inference service, one of the most easily misused metrics is the “cache unit price” or “price per million tokens.” The actual bill is usually determined by a combination of cached hits, non-cached input, output, peak and off-peak periods, subscription plan quotas, retries, and concurrency limits. If two services differ by a factor of two in cache unit price, their real costs may not differ by the same factor. When cache hit rate falls or output share rises, the cost ranking may even reverse. Cost evaluation should therefore return to a unified model: first measure the business token structure, then calculate the weighted unit price, and finally combine plan quotas and utilization to perform break-even analysis.
1. Why Unit-Price Comparisons Can Be Misleading
Assume an inference service offers three billing tiers: cache-hit price, non-cached input price, and output price. The cache-hit price is usually the lowest, the non-cached input price is in the middle, and the output price is the highest. Total tokens in a business request consist of three parts: prefix or context that hits the cache, input that misses the cache, and model-generated output. If the workload is dominated by long system prompts, fixed knowledge-base prefixes, and reused multi-turn conversations, the cache hit rate may be high, and the cache unit price carries the largest weight. If the workload is dominated by short prompts, high output, and frequently changing context, the cache hit rate will be low, and the non-cached input price and output price carry more weight.
The original example compares two anonymous options: Option A has a cache price of CNY 0.115 per million tokens, while Option B has an off-peak cache price of CNY 0.05 per million tokens. Looking only at the cache price, Option B appears to be about half the price of Option A, which easily leads to the conclusion that Option B is cheaper. However, under the example token structure of 98% cache hits, 1.5% non-cached input, and 0.5% output, the cost per 100 million tokens is CNY 12.57 for Option A and CNY 9.40 for Option B. When the cache hit rate drops to 95%, non-cached input rises to 4.5%, and output remains at 0.5%, the cost becomes CNY 14.92 for Option A and CNY 18.25 for Option B. The ranking reverses. This shows that real cost is determined by the weighted result of “hit rate × cache price + non-cached input × input price + output × output price,” not by a single price.
2. Unified Cost Model
Let total token volume be (T) (in millions of tokens), the cache-hit ratio be (h), the non-cached input ratio be (i), and the output ratio be (o), satisfying:
[
h+i+o=1
]
Let the three unit prices be (P{cache}), (P{input}), and (P_{output}), in CNY per million tokens. Total cost is:
[
C = T \times (h \cdot P{cache} + i \cdot P{input} + o \cdot P_{output})
]
If total tokens are 100 million, that is, (T=100), then:
[
C = 100 \times (h \cdot P{cache} + i \cdot P{input} + o \cdot P_{output})
]
This formula has three key implications. First, the higher the cache hit rate, the greater the weight of the cache unit price, and the more advantageous a low-cache-price option becomes. Second, the higher the output ratio, the greater the weight of the output unit price, and the more advantageous a service with lower output pricing becomes. Third, the non-cached input ratio is the “remainder” term. When the hit rate falls, it usually absorbs most of the increase, so the non-cached input price is highly sensitive in medium- and low-hit-rate scenarios.
For the cost crossover point between two options, set (C_A(h)=C_B(h)). Under the simplified assumption that output ratio (o) is fixed and non-cached input ratio is (i=1-h-o), the cost difference is:
[
CA-C_B = (1-h-o)\Delta P{input} + o\Delta P{output} + h\Delta P{cache}
]
Here (\Delta P) represents the difference in the corresponding unit prices between the two options. After rearranging, we can solve for the cache hit rate (h^) at which the two options are equal. When the actual hit rate is above (h^), the option with the lower cache price may be better. When it is below (h^*), the option with the lower non-cached input price or output price may be better. In engineering practice, there is no need to derive this manually; simply plug sampled business data into the formula.
3. Example Calculation and Crossover Interpretation
In the example, at a 98% hit rate, the cost per 100 million tokens is CNY 12.57 for Option A and CNY 9.40 for Option B, with Option B about 25% lower. This matches the intuition that a high hit rate amplifies differences in cache unit price. At a 95% hit rate, Option A costs CNY 14.92 and Option B costs CNY 18.25, so Option A becomes cheaper. The reason is not that the cache unit price changed, but that the non-cached input share rose from 1.5% to 4.5%, increasing the weight of the non-cached input price and offsetting the cache-price advantage. This example shows that if the business cache hit rate is consistently stable above 98%, cache price can be a key comparison point. If the hit rate fluctuates around 95%, non-cached input price and output price must also be compared; looking only at cache price is insufficient.
In production, cache hit rate is not a fixed value. System prompt changes, knowledge-base updates, multi-turn conversation truncation, long-document splitting, request parameter changes, and concurrent routing to different nodes can all affect the hit rate. It is recommended to measure both request-weighted and token-weighted hit rates separately, because long-context requests have a much greater cost impact than short requests. It is also important to distinguish “cacheable prefixes” from “non-cacheable content” to avoid mistaking theoretical hit rate for billed hit rate.
4. Peak/Off-Peak Pricing and Subscription Plans
Peak and off-peak pricing further changes cost. In the example, Option B has an off-peak cache price of CNY 0.05 per million tokens, but it is valid only during specific periods. Option A’s cache price of CNY 0.115 per million tokens is more stable. If business traffic can be scheduled, moving offline batch processing, index construction, and evaluation tasks to off-peak periods can significantly reduce cost. If business traffic is concentrated in peak periods, the actual coverage of off-peak pricing is limited.
Subscription plans convert usage-based costs into fixed monthly fees and weekly quotas. In the example, the monthly fees are CNY 118, CNY 538, and CNY 1,078. The off-peak weekly quotas are 317 million, 1.900 billion, and 4.433 billion tokens, respectively. The peak restriction is Monday through Friday from 14:00 to 18:00, that is, four hours per day. Based on the example, the API-equivalent value of the three plans is approximately CNY 160, CNY 955, and CNY 2,229. The ratio of plan price to API-equivalent value is approximately 48%–74%, generally close to a 50%–75% discount, with a smaller discount at the low tier and a more obvious discount at the high tier.
Whether a plan is cost-effective depends on utilization. Let the monthly fee be (F) and the API-equivalent value of the full plan quota be (V). The utilization threshold is approximately:
[
u^* = \frac{F}{V}
]
When actual utilization is above (u^*), the plan is cheaper than pay-as-you-go pricing. Below that threshold, pay-as-you-go pricing is more flexible. Using the example values, 118/160 is about 73.8%, 538/955 is about 56.3%, and 1,078/2,229 is about 48.4%. In other words, the low-tier plan needs relatively high utilization to be worthwhile, while the high-tier plan approaches break-even at about half utilization. If business usage fluctuates widely and a large amount of quota is idle, a fixed plan may cause waste. If usage is stable and close to the quota limit, a plan can reduce budget uncertainty.
Peak restrictions also require attention. Four hours per day is not a large share of a natural week, but business peaks may be concentrated in those four hours. If the peak-period token share is high, the plan’s “off-peak quota” cannot fully represent effective capacity. Peak concurrency, queuing, and rate-limiting risks should be evaluated separately. Weekly quota resets also require weekly monitoring to avoid spending too loosely early in the week, being constrained later, or wasting quota on weekends.
5. Engineering Implementation: Monitoring Metrics and Calculation Script
It is recommended to establish the following monitoring metrics: token-weighted cache hit rate, non-cached input share, output share, peak/off-peak token distribution, actual cost per million tokens, plan quota utilization, retry rate, rate-limit rate, and cache storage and write costs. The cost model should be recalculated weekly, not only once during service selection.
The following pseudocode can be used for unified calculation:
function real_cost(total_million_tokens, hit_ratio, output_ratio, p_cache, p_input, p_output):non_cache_input_ratio = 1 - hit_ratio - output_ratioweighted_price = hit_ratio * p_cache+ non_cache_input_ratio * p_input+ output_ratio * p_outputreturn total_million_tokens * weighted_pricefunction plan_threshold(monthly_fee, api_equivalent_value):return monthly_fee / api_equivalent_value
If a plan offers a weekly quota of (Q) hundred million tokens and a monthly fee of (F), then ignoring peak restrictions and quota waste, the monthly quota is approximately (4.33 \times Q) hundred million tokens, or (433 \times Q) million tokens. The effective unit price is approximately:
[
P_{plan} = \frac{F}{433 \times Q}
]
This value is only for ideal-capacity comparison. In practice, use “consumed quota” rather than “nominal quota” for calculation. For plans with peak-period rate limits, also calculate the share of usable tokens during peak periods and include queuing time, failed retries, and degradation costs in total cost of ownership.
6. Selection Recommendations
First, sample before comparing prices. Use real business requests to measure hit rate, input/output structure, and peak/off-peak distribution, covering at least one week. Second, calculate three scenarios separately: high hit rate, medium hit rate, and low hit rate, and observe whether the cost ranking remains stable. Third, treat a subscription plan as a “capacity commitment” rather than a simple discount: choose a plan when utilization exceeds the threshold and peak behavior is acceptable; retain pay-as-you-go flexibility when usage fluctuates widely or peaks are concentrated. Fourth, for high-output tasks, focus on output unit price; for high-cache-reuse tasks, focus on cache unit price; for medium- and low-hit-rate tasks, focus on non-cached input price. Fifth, set budget alerts and quota alerts, review weekly, and avoid using nominal unit prices alone for annual budgeting.
The conclusion is that LLM inference cost is the product of business token structure and billing rules. Cache unit price is only one factor. Cache hit rate, input/output ratio, peak/off-peak coverage, and plan utilization jointly determine the real bill. Replacing single-point price comparisons with a unified formula and continuous monitoring enables stable, explainable decisions between high and low hit rates and between pay-as-you-go pricing and subscription plans.
