The Real Cost of LLM Inference: Why Cache Hit Rate Determines Cost-Effectiveness
Evaluating Large Language Model (LLM) APIs by comparing per-million-token prices often leads to inaccurate conclusions. The actual billing is determined by a combination of cache hit rates, uncached input prices, output prices, and your specific business traffic structure. This article explores how to build a token traffic structure model, explains why cache hit rate is the most sensitive variable in cost curves, and provides a practical framework for comparing pay-as-you-go and subscription pricing. By applying this evaluation checklist, developers can accurately assess the true cost of LLM inference and make data-driven decisions.
1. Why the “Listed Price” Isn’t the “Real Cost”
When selecting an LLM API, developers often start by comparing the per-million-token unit prices published by various vendors. While straightforward, this approach frequently leads to wrong conclusions. The actual invoice for LLM inference depends not on an isolated unit price, but on a combination of cache pricing, standard input pricing, output pricing, and your business traffic structure.
A common misconception: Vendor A sets a very low unit price for cache hits, while Vendor B’s is slightly higher. Looking only at this metric, Vendor A seems cheaper. However, if your business has a low cache hit rate, a large portion of tokens will be billed at the standard input rate, potentially making the overall cost higher. In other words, discussing unit prices in isolation from your traffic profile is meaningless.
Therefore, the core premise here is: to evaluate LLM inference costs, you must first build a “traffic structure model” for your business, plug in each vendor’s pricing to calculate the total, and finally make a comprehensive decision considering the billing mode (pay-as-you-go vs. subscription).
2. Building Your Token Traffic Structure Model
In real-world applications, token consumption can typically be divided into three categories:
- Cache Hit Tokens: System prompts, fixed tool definitions, and historical context in multi-turn conversations. These are highly repetitive across requests, and modern inference services usually offer a significantly lower cache price for matching prefixes.
- Uncached Input Tokens: New user inputs and retrieval results generated per request, billed at the standard input rate.
- Output Tokens: Content generated by the model, usually carrying the highest unit price.
Take a cost-sensitive, high-frequency calling scenario as an example. A common ratio assumption is: 98% cache hits, 1.5% uncached inputs, and 0.5% outputs. This applies to scenarios like code completion or tool-calling agents, which feature long system prompts, short user inputs, and short outputs.
The formula for the total cost of 100 million tokens can be written as:
Total Cost = 100M * (98% * cache_price + 1.5% * input_price + 0.5% * output_price)
Plugging in a set of hypothetical prices for illustration might yield roughly $12.57 for Plan A and $9.40 for Plan B, making B the better choice. However, if the cache hit rate drops from 98% to 95%, the 3% of tokens “squeezed out” of the cache—due to the several-fold or even tenfold price difference between cache and standard input—will significantly inflate the total. The calculation might then flip to $14.92 for Plan A and $18.25 for Plan B, reversing the conclusion entirely.
3. Cache Hit Rate is the “Sensitive Variable” in Cost Curves
As shown above, the cache hit rate is the most elastic variable in the cost model. A mere 3-percentage-point fluctuation is enough to swap the cost rankings of two plans. This offers two key takeaways:
First, measure the hit rate before selecting a vendor. Before formal procurement, run real traffic in a test environment for a while and calculate the percentage of cache hit tokens returned by the service. This varies drastically by use case: multi-turn conversations and long system prompt scenarios can achieve over 95%, while single-turn Q&A where the context changes every request might see a pitifully low hit rate.
Second, actively optimizing the hit rate saves money. You can improve cache hits through the following engineering practices:
- Keep system prompts stable; avoid inserting volatile content like timestamps or random IDs at the prefix.
- Place static content at the beginning of the prompt and dynamic content at the end, as caching usually relies on prefix matching.
- Implement a logical context truncation strategy for multi-turn conversations, preserving the prefix consistent with the previous turn as much as possible.
A sample self-check code snippet:
def estimate_cost(total_tokens, hit_rate, cache_price, in_price, out_price, out_ratio=0.005):cached = total_tokens * hit_rateuncached_in = total_tokens * (1 - hit_rate - out_ratio)output = total_tokens * out_ratioreturn (cached * cache_price + uncached_in * in_price + output * out_price) / 1_000_000
Plugging in the measured hit rate makes the comparison clear.
4. Peak/Off-Peak Pricing: Time as a Cost Variable
Beyond traffic structure, the time of the API call also affects the unit price. Some vendors adopt peak/off-peak time-based pricing, where cache or input prices during off-peak hours might be half or less of peak hours. Note that definitions of “peak hours” vary: some define a long daytime window every day as peak, while others restrict peak to specific hours on weekdays (e.g., 2:00 PM to 6:00 PM).
For developers, this presents two optimization opportunities:
- Stagger batch tasks. Latency-insensitive tasks like data cleaning, offline evaluation, and batch summarization can be scheduled during off-peak hours to directly benefit from lower prices.
- Understand peak rules when evaluating plans. Certain subscription plans offer different quotas for peak and off-peak hours. The narrower the peak window, the higher the actual availability.
5. Converting Between Subscriptions and Pay-As-You-Go
An increasing number of vendors offer monthly subscription plans (e.g., fixed quota plans for coding assistants or agents). To determine if a plan is worth it, the key lies in “reverse-calculating the quota”:
Plan Implicit Unit Price = Monthly Fee / Monthly QuotaPay-As-You-Go Equivalent Price = Same Quota * Pay-As-You-Go Unit Price
For instance, a monthly fee might correspond to a quota of hundreds of millions of tokens per week. When converted, it might equal hundreds or thousands of dollars at standard pay-as-you-go rates, meaning the plan’s unit price is roughly 30% to 50% off. Whether this discount actually benefits you depends on two prerequisites:
- Can you max out the quota? Subscriptions operate on a “use it or lose it” model. If your actual usage is only a third of the quota, the equivalent unit price might be higher than pay-as-you-go.
- Does the quota’s time distribution match your needs? Some plans offer weekly quotas, others monthly. You also need to check if peak-hour quotas are restricted.
A sound decision process is: use pay-as-you-go for 1–2 billing cycles to gather real weekly/monthly average token consumption and hit rate data. Then, reverse-calculate the plan’s equivalent discount and choose the lower-cost option with adequate redundancy.
6. An Actionable Cost Evaluation Checklist
Based on the above, follow these steps to finalize your LLM inference cost selection:
- Map your business traffic profile: cache hit rate, input/output ratio, and call time distribution.
- Use measured data in the total cost formula to conduct sensitivity analysis under different hit rate assumptions.
- Schedule off-peak tasks for valley hours and re-estimate the weighted average price after mixing peak and off-peak usage.
- Reverse-calculate subscription plans to confirm usage match before purchasing.
- Continuously monitor token consumption and hit rate post-launch, establish cost alerts, and review periodically.
Conclusion
The cost competition in LLM inference is essentially a game between “pricing model complexity” and “depth of understanding of business traffic.” Comparing surface-level unit prices is just the starting point. What truly determines your bill is the combination of cache hit rate, traffic structure, and billing mode. By mastering the calculation framework outlined here, you can quickly determine your actual costs in the face of any vendor’s new pricing policy and make data-driven, rational decisions.
