LLM API Cost Estimation: Cache Hit Rate and Subscription Break-Even Point
This article explains how to estimate LLM API costs beyond list prices. It covers cache hit rate, the mix of input and output tokens, peak-hour billing, and quota utilization. It also includes a Python function for calculating blended cost and a method for finding the break-even point of a monthly subscription.
1. Why Comparing List Prices Directly Can Be Misleading
LLM service prices are usually quoted in CNY per million tokens. However, the same unit price can produce very different actual costs depending on usage patterns. Comparing the list prices of two services directly, while ignoring variables such as cache hit rate, the input-to-output ratio, time-of-day pricing, and subscription quotas, often leads to unreliable conclusions.
A more accurate approach is to place the unit price in the full business scenario, calculate the “blended cost per million tokens,” and then compare options on that basis. The blended cost depends on the workload profile, not on the list price alone.
2. Three Components of Token Billing
Most pay-as-you-go pricing schemes can be broken down into three categories:
- Cache-hit input tokens: The request prefix matches recent requests, so the server reuses previously computed intermediate results directly. This category has the lowest unit price, but not all services offer it.
- Cache-miss input tokens: Input tokens that must be fully computed. Their unit price is higher than that of cache-hit tokens.
- Output tokens: The content generated by the model. Their unit price is usually the highest.
Let $p_h$, $p_m$, and $p_o$ denote the unit prices of the three categories, and let $r_h$, $r_m$, and $r_o$ denote their shares of total tokens. The blended cost per million total tokens is:
$C = r_h \cdot p_h + r_m \cdot p_m + r_o \cdot p_o$
where $r_h + r_m + r_o = 1$.
3. How Cache Hit Rate Affects Cost
The following values are illustrative assumptions for the calculation and do not correspond to any actual price list: cache-hit input at 0.2 CNY per million tokens, cache-miss input at 2 CNY per million tokens, output at 8 CNY per million tokens, and output making up 0.5% of total tokens.
| Cache hit rate | Cache-hit input share | Cache-miss input share | Cost per 100M tokens (CNY) |
|---|---|---|---|
| 98% | 98% | 1.5% | 26.6 |
| 95% | 95% | 4.5% | 32.0 |
Reducing the hit rate from 98% to 95% raises the cost by about 20%. The cache-miss share of input increases by only 3 percentage points, but the cost rises noticeably because a cache-miss input token costs 10 times as much as a cache hit. Therefore, optimizing the prompt structure and keeping system instructions and common prefixes stable often lowers costs more than reducing the output length of individual calls.
4. Cost Calculation Code Example
The function below converts any set of unit prices and hit rates into a blended cost. You can replace the example prices with your own quotes to run comparisons:
def blended_cost(total_tokens_m: float,hit_rate: float,cache_price: float,miss_price: float,out_price: float,out_ratio: float = 0.005) -> float:"""Calculate the cost for a given total token volume.total_tokens_m: total tokens (unit: million)Price unit: CNY per million tokens"""if not 0 <= hit_rate + out_ratio <= 1:raise ValueError("The sum of the hit rate and the output ratio must be between 0 and 1")hit_tokens = total_tokens_m * hit_rateout_tokens = total_tokens_m * out_ratiomiss_tokens = total_tokens_m - hit_tokens - out_tokensreturn (hit_tokens * cache_price+ miss_tokens * miss_price+ out_tokens * out_price)if __name__ == "__main__":for rate in (0.98, 0.95):cost = blended_cost(100, rate, cache_price=0.2,miss_price=2.0, out_price=8.0)print(f"Hit rate {rate:.0%}: about {cost:.1f} CNY per 100M tokens")
The output matches the table above. After you replace the parameters with actual price quotes, you can compare the costs of different options under the same workload.
5. Break-Even Point for Monthly Subscription Plans
Monthly subscription plans may look cheaper per unit, but the actual cost depends on quota utilization. The calculation has three steps:
- Convert to an equivalent unit price: Use the function above to get the blended pay-as-you-go cost. This example assumes 0.266 CNY per million tokens.
- Find the break-even usage: Divide the monthly fee by the equivalent unit price. For a monthly fee of 300 CNY, the break-even usage is about 300 ÷ 0.266 ≈ 1,128 million tokens, or roughly 1.13 billion tokens.
- Compare with actual usage: If actual monthly usage is above the break-even point, the subscription is more cost-effective. If it is below, pay-as-you-go is cheaper.
Utilization also matters. If you use only 40% of the subscription quota, the effective unit price becomes 1 ÷ 0.4 = 2.5 times the nominal price. A subscription’s price advantage appears only when most of the quota is used.
6. Peak Hours and Quota Consumption
Many services apply different billing multipliers during peak hours, or they limit how much of a subscription quota can be used at those times. This has two effects:
- Uneven quota consumption: A workload concentrated in peak hours may exhaust a weekly quota faster than a workload with the same total volume spread evenly over time.
- Shifting workloads off-peak can reduce costs: Offline batch processing, data labeling, and nightly report generation can run during low-demand periods. Keeping request prefixes stable during these runs also helps raise the cache hit rate.
To decide whether a task suits off-peak scheduling, first analyze the distribution of its call times. Then decide whether to adjust the scheduling strategy.
7. Practical Recommendations
- Instrument your calls first: Record each call’s input, output, cache hit status, and timestamp to build a realistic workload profile.
- Fix the prompt prefix: Place system instructions, examples, and knowledge snippets at the beginning of each request, and keep their order stable to improve the cache hit rate.
- Choose a billing model based on your workload: Use the break-even formula to compare monthly usage. Consider a subscription when usage is stable and high. Keep pay-as-you-go when usage fluctuates widely or stays low.
- Recalculate regularly: Prices, hit rates, and workload volumes all change. Rerun the same functions every month.
Cost optimization depends on replacing price intuition with real data. Modeling hit rate, time-of-day effects, and quota utilization together gives a more accurate picture of actual spending than comparing list prices alone.
