LLM API Cost Accounting: Cache Hit Rate, Time-Based Pricing, and Plan Selection
This article explains why low token unit prices do not necessarily mean lower real costs for LLM APIs. Using cache-hit-rate scenarios, it shows how cost conclusions can reverse when hit rates change, examines how peak and off-peak pricing definitions affect usable low-price windows, provides a break-even method for comparing pay-as-you-go pricing with monthly plans, and summarizes engineering practices for reducing production costs.
LLM API Cost Accounting: Cache Hit Rate, Time-Based Pricing, and Plan Selection
Introduction: Why a Lower Unit Price Does Not Mean a Lower Total Cost
In engineering practice for LLM applications, cost evaluation is often a key part of architecture decisions. Many teams instinctively compare the published token unit prices of different services, but this ignores a central fact: the real cost of an LLM API is a function of invocation patterns, cache hit rate, time-of-day distribution, and payment method, not a static number.
This article starts with a typical cost comparison scenario: two services with different pricing strategies under the same invocation pattern, and the actual spending difference between them. From there, it derives a general cost-accounting methodology that developers can reuse as an evaluation framework.
1. Understanding the Basic Structure of LLM API Billing
The cost of a single model call usually consists of three parts:
Cost per call = cache-hit input volume × cache unit price+ cache-miss input volume × input unit price+ output volume × output unit price
Several engineering facts deserve attention:
- The cache unit price is much lower than the regular input unit price. Mainstream providers generally offer context caching. The price of input tokens that hit the cache is usually a fraction of the regular input price, sometimes far lower.
- The output unit price is usually higher than the input unit price, which is determined by the computational characteristics of autoregressive generation.
- The same service may use time-based pricing: off-peak prices may be around half of peak prices.
This means that two services with clearly different unit-price tables may have completely reversed actual costs under different load characteristics. The following example illustrates this.
2. Example: How Cache Hit Rate Can Overturn a Cost Conclusion
Suppose we need to estimate the cost per 100 million tokens in a high-reuse prompt scenario, typically an intelligent coding assistant where a large amount of code context is repeatedly carried. Assume the input/output ratio is: cached hits account for 98%, new input accounts for 1.5%, and output accounts for 0.5%.
2.1 High Cache Hit Scenario (98%)
In this scenario, the cache unit price becomes the dominant factor. Assume Service A has a cache unit price of CNY 0.115 per million tokens, and Service B has an off-peak cache unit price of CNY 0.05 per million tokens. After applying the full weighted input/output calculation:
- Service A: approximately CNY 12.57 per 100 million tokens
- Service B (off-peak price): approximately CNY 9.40 per 100 million tokens
The conclusion seems clear: when the cache hit rate is very high, the difference in cache unit price is amplified by the 98% weight, so the side with the lower cache unit price wins, even if its pricing in other dimensions may be higher.
2.2 Reversal After the Cache Hit Rate Drops (95%)
Now lower the hit rate from 98% to 95%. It looks like a change of only 3 percentage points, but it means cache-miss input rises from 1.5% to 4.5%, so cache-miss input triples. Because the regular input unit price is much higher than the cache unit price, this part rapidly gains weight. Recalculating:
- Service A: approximately CNY 14.92 per 100 million tokens
- Service B (off-peak price): approximately CNY 18.25 per 100 million tokens
The conclusion is completely reversed: Service A becomes the more cost-effective option.
2.3 General Rule Drawn from the Example
This example reveals a frequently overlooked rule:
The higher the cache hit rate, the more cost-sensitive the result is to the cache unit price; the lower the hit rate, the more cost-sensitive the result is to the regular input unit price.
In engineering terms, you can use a simplified sensitivity analysis to locate your own scenario. First, measure the cache hit rate distribution of real production traffic. Coding assistant applications can often exceed 90%, while multi-turn chat or RAG scenarios may be significantly lower. Then apply the weighted calculation using each provider’s price table instead of looking only at a single line item.
Also note that Service B in the comparison above uses the off-peak price. If traffic is concentrated during peak hours, you need to switch to the peak price and recalculate, and the conclusion may change again.
3. Time-Based Pricing: How Peak Hours Are Defined Directly Affects Usability
Time-based pricing is a common cost-control measure, but “how peak hours are defined” is itself a key parameter. For example:
- Some services treat the nighttime period of the calendar day as off-peak, and the off-peak window may cover the early morning through dawn.
- Some services limit peak hours to four hours on weekday afternoons (for example, 14:00–18:00), and all other times are billed as non-peak.
The latter offers a clearly more generous low-price window in practice: across seven days a week, only four hours on workdays are peak, leaving more than 80% of the time eligible for low-price billing. For scheduled batch tasks such as nighttime code review or offline data labeling, scheduling them into off-peak windows can directly cut input costs by roughly half. For interactive applications, you should weight by the actual traffic distribution across peak and off-peak periods.
Engineering recommendation: include “peak traffic share” as a variable in the cost model instead of assuming that all traffic enjoys the lowest price.
4. Pay-as-You-Go vs. Monthly Plans: How to Find the Break-Even Point
In addition to pay-as-you-go billing, monthly subscription models are also popular among developers, especially in intelligent coding scenarios. To evaluate whether a plan is worthwhile, the core task is to convert the plan quota into an equivalent API cost.
Consider a three-tier plan structure as an example (quota is measured by available tokens per week):
| Tier | Monthly fee | Weekly quota (off-peak, 98% cache-hit assumption) | Equivalent API value at list price |
|---|---|---|---|
| Entry | ~CNY 118 | ~320 million tokens | ~CNY 160 |
| Advanced | ~CNY 538 | ~1.9 billion tokens | ~CNY 955 |
| Flagship | ~CNY 1,078 | ~4.4 billion tokens | ~CNY 2,229 |
Two patterns are visible:
- The plan unit price is roughly 50%–70% of the pay-as-you-go price, indicating a clear volume discount.
- The higher the tier, the deeper the discount; the equivalent discount rate of the flagship tier is about 48%.
However, three implicit assumptions of monthly plans need attention:
- Quota usually resets weekly and does not roll over. Sudden large traffic bursts may trigger rate limiting.
- Quota is tied to cache hit rate and time-of-day assumptions. Official quota numbers are often based on ideal assumptions such as 98% hit rate and off-peak usage, so the actual usable amount will vary with individual usage patterns.
- Peak-hour quota often shrinks. For some plans, the usable quota during peak hours may drop to about half of the off-peak amount.
Therefore, the selection process should be: first measure your own token consumption and time-of-day distribution over the past month → if monthly consumption is stable and below 70% of a tier’s quota, choose that tier; if consumption fluctuates widely or often exceeds the quota, pay-as-you-go is safer; if consumption far exceeds the flagship tier, return to pay-as-you-go and focus on optimizing cache hit rate.
5. Engineering Practices for Reducing Real Costs
Price comparison is only static analysis. What truly separates cost outcomes is optimization at the architecture level:
- Maximize cache hits: place stable system prompts, tool definitions, and project context at the front of the request and keep them unchanged; put dynamic content later. Avoid inserting volatile fields such as timestamps into the prefix.
- Schedule tasks away from peak hours: use message queues and scheduled jobs to run offline batch processing, code index construction, and similar tasks in off-peak windows.
- Compress useless input: summarize very long contexts and use retrieval-based filtering instead of injecting everything in full.
- Build cost observability: use general logging, monitoring, and alerting capabilities to track token consumption and hit rates by business line, set anomaly alerts, and continuously calibrate the cost model.
Conclusion
LLM API cost comparison is never simply a question of “whose unit price is lower.” It is a question of “under my load characteristics, whose total cost is lower.” Cache hit rate, time-of-day distribution, and consumption volume are enough to reverse the conclusion between two price tables multiple times. Build a quantitative cost-accounting habit, combine it with cache optimization and off-peak scheduling, and model costs can be kept within a range that is predictable in engineering terms.
