How to Calculate the Real Cost of LLM APIs: Cache Hit Rates and Subscription Plans
LLM API bills consist of cached tokens, regular input tokens, and output tokens, so a low cached-token price alone does not guarantee lower total cost. This article builds a mixed-token cost model, runs sensitivity analysis across different cache hit rates, converts subscription plan fees into per-unit costs, accounts for peak/off-peak windows and overflow charges, and provides monitoring metrics, a selection workflow, and sample code for reproducible cost estimation.
Why Nominal Unit Prices Cannot Be Compared Directly
An LLM API bill is made up of three parts: cached tokens, regular input tokens, and output tokens. The cached-token unit price is usually the lowest, which makes it tempting to conclude that “a cheaper cache price means a cheaper bill.” That conclusion only holds when the cache hit rate is very high. Once the hit rate drops, the regular input and output prices determine the bill, and the ranking of two candidate plans can flip entirely.
To judge real cost, you need to consider three things at the same time: the cache hit rate, the input-to-output ratio, and the subscription quota together with peak/off-peak windows. The following sections expand on these three dimensions with reproducible example parameters.
Mixed-Token Cost Model and Sensitivity Analysis
Let the total token volume be T, the cache hit ratio be h, the regular input ratio be i, and the output ratio be o, where the three ratios sum to 1. The three unit prices are p_c, p_i, and p_o (yuan per million tokens). The total cost is:
C(T) = T / 10^6 × (h × p_c + i × p_i + o × p_o)
To convert this into the cost per 100 million tokens, note that 100 million tokens equal 100 × 1 million tokens, so:
C_100M = 100 × (h × p_c + i × p_i + o × p_o)
This shows that the cached-token price p_c only affects the first term. When h is very high, that term dominates and the plan with the cheaper cache price has a clear advantage. As h falls, the input and output terms take over, and the plan ranking may reverse.
To illustrate the method, we construct two example plans with the parameters below. In both plans, the ratio of regular input to output is fixed at 3:1 — among non-cached tokens, input accounts for 75% and output for 25%.
| Plan | Cache price p_c | Input price p_i | Output price p_o | Weighted non-cache price |
|---|---|---|---|---|
| Plan A | 0.115 yuan / 1M tokens | 8 yuan / 1M tokens | 12 yuan / 1M tokens | 9 yuan / 1M tokens |
| Plan B | 0.05 yuan / 1M tokens | 10 yuan / 1M tokens | 14 yuan / 1M tokens | 11 yuan / 1M tokens |
The weighted non-cache price is calculated as 0.75 × p_i + 0.25 × p_o.
At a 98% cache hit rate, regular input accounts for 1.5% and output for 0.5%. When the hit rate drops to 95%, input accounts for 3.75% and output for 1.25%, still keeping the 3:1 ratio. The cost per 100 million tokens is shown below.
| Cache hit rate | Plan A cost per 100M tokens | Plan B cost per 100M tokens | Cheaper plan |
|---|---|---|---|
| 98% | 29.27 yuan | 26.90 yuan | Plan B |
| 95% | 55.93 yuan | 59.75 yuan | Plan A |
Taking Plan A at 98% as an example: 0.98 × 0.115 + 0.015 × 8 + 0.005 × 12 = 0.2927, multiplied by 100, gives 29.27 yuan. Plan B is computed the same way.
When the hit rate drops from 98% to 95%, Plan A’s cost rises to about 1.9× and Plan B’s to about 2.2×. The non-cached share grows from 2% to 5%, and because its unit price is far higher than the cache price, total cost climbs quickly.
The two plans break even when the non-cached share is about 3.1%, corresponding to a hit rate of roughly 96.9%. Above that hit rate, Plan B is cheaper; below it, Plan A is cheaper.
These numbers are only for demonstrating how rankings change and do not represent any real pricing. In actual selection, you should replay real traffic, measure the distribution of cache hit rates, input/output ratios, and long-tail requests, and then plug the actual billed prices into the model. Do not make decisions based on a single average unit price.
Subscription Plan Cost Conversion and Peak/Off-Peak Effects
Subscription plans typically trade a monthly fee for a weekly or monthly token quota, often distinguishing between peak and off-peak windows. Let the monthly fee be M and the weekly quota be Q (in 100 million tokens per week). Approximating a month as 4 weeks, the plan cost per 100 million tokens is:
Plan cost per 100M = M / (Q × 4)
The three tiers below are example data.
| Tier | Monthly fee | Weekly quota | Cost per 100M (4 weeks) | Cost per 100M (4.33 weeks) |
|---|---|---|---|---|
| Basic | 118 yuan | 317M | 9.31 yuan | 8.60 yuan |
| Pro | 538 yuan | 1.90B | 7.08 yuan | 6.54 yuan |
| Flagship | 1078 yuan | 4.433B | 6.08 yuan | 5.62 yuan |
Whether you use 4 or 4.33 weeks per month changes the result by about 8%. Use the actual billing cycle when evaluating.
To judge whether a plan is worthwhile, compare it against pay-as-you-go pricing. Here we use Plan A’s 29.27 yuan per 100 million tokens at a 98% hit rate as the pay-as-you-go reference. Define:
Plan cost ratio = plan cost per 100M / pay-as-you-go cost per 100M
Savings rate = 1 - plan cost ratio
| Tier | Plan cost per 100M | Plan cost ratio | Equivalent to | Savings rate |
|---|---|---|---|---|
| Basic | 9.31 yuan | 31.8% | ~32% of pay-as-you-go | ~68% |
| Pro | 7.08 yuan | 24.2% | ~24% of pay-as-you-go | ~76% |
| Flagship | 6.08 yuan | 20.8% | ~21% of pay-as-you-go | ~79% |
These ratios hold only on one premise: the quota is fully consumed. If actual usage falls below the quota, the effective cost per 100 million tokens is higher than the table shows — the effective cost equals the monthly fee divided by actual usage.
Usage beyond the quota is usually billed at pay-as-you-go prices. Monthly total cost can be written as:
Monthly total cost = M + overflow tokens (in 100M) × pay-as-you-go cost per 100M + peak-hour surcharges
For example, the Basic tier provides about 1.268 billion tokens per month. If actual usage is 1.4 billion tokens, the overflow is 132 million tokens. At 29.27 yuan per 100 million tokens, the overflow fee is about 38.64 yuan, and the monthly total is about 156.64 yuan.
Peak/off-peak windows affect how usable a plan is. In this example, peak hours are Monday to Friday, 14:00–18:00, totaling 20 hours per week — about 11.9% of the 168-hour week. Deferrable tasks such as batch processing, offline indexing, and log analysis should be scheduled into off-peak windows. Interactive requests need an assessment of throttling, queuing, and extra billing rules during peak hours, with a 20%–30% capacity buffer reserved.
Engineering Observability and the Selection Workflow
Cost optimization starts with observability. Each request should record cached tokens, regular input tokens, output tokens, request time window, retry count, and response latency, aggregated by business line. General-purpose cloud capabilities such as log services, monitoring and alerting, and object storage can handle sampling, archiving, and budget alerts.
The table below lists the key metrics worth monitoring. Thresholds and review cadence should be adjusted to your business scale.
| Metric | Collection method | Suggested alert threshold | Review cadence |
|---|---|---|---|
| Overall cache hit rate | Aggregate cached tokens vs. total tokens across requests | 3 percentage points below target | Weekly |
| Per-business-line hit rate | Grouped statistics by business-line label | A single business line declines for two consecutive days | Weekly |
| Input/output ratio | Ratio of regular input tokens to output tokens | Output share rises noticeably vs. last month | Monthly |
| Peak-hour request share | Statistics by request time window | Peak share exceeds 80% of the plan’s peak-window capacity | Weekly |
| Quota consumption speed | Compare used quota against period progress | At current pace, the quota will run out early | Daily |
| Pay-as-you-go overflow cost | Fees for usage beyond the quota | Monthly overflow fees exceed 10% of budget | Monthly |
A practical selection process has four steps. First, replay real traffic to compute the mixed-token cost of candidate plans. Second, run sensitivity analysis at multiple cache hit rates such as 95%, 90%, and 80%. Third, incorporate plan quotas, peak/off-peak limits, and overflow prices into a monthly budget model. Fourth, set up quota consumption alerts and review the choice quarterly.
For workloads with high, stable hit rates, prioritize plans with lower cache prices. For workloads with volatile hit rates or high output shares, focus on regular input and output prices. For workloads heavy on batch jobs with flexible scheduling, a subscription plan combined with off-peak scheduling usually makes budget control easier.
Sample Calculation Code
The following pseudocode plugs billing parameters into the model.
def mixed_cost(total_tokens, cache_ratio, input_ratio, output_ratio,p_cache, p_input, p_output):# Prices: yuan per 1M tokens; total_tokens: tokensratios = (cache_ratio, input_ratio, output_ratio)if any(r < 0 for r in ratios):raise ValueError("Ratios must not be negative")if abs(sum(ratios) - 1.0) > 1e-9:raise ValueError("Ratios must sum to 1")return total_tokens / 1_000_000 * (cache_ratio * p_cache +input_ratio * p_input +output_ratio * p_output)def package_cost_per_yi(monthly_fee, weekly_quota_yi, weeks_per_month=4):# weekly_quota_yi: 100M tokens per week; returns yuan per 100M tokensmonthly_quota_yi = weekly_quota_yi * weeks_per_monthreturn monthly_fee / monthly_quota_yi# Plan A, 98% hit rate, per 100M tokensprint(round(mixed_cost(100_000_000, 0.98, 0.015, 0.005, 0.115, 8, 12), 2)) # 29.27# Plan cost conversion examplesprint(round(package_cost_per_yi(118, 3.17), 2)) # 9.31print(round(package_cost_per_yi(538, 19.00), 2)) # 7.08print(round(package_cost_per_yi(1078, 44.33), 2)) # 6.08
In real usage, the input and output prices should come from your actual bill. The point of the examples is to show how hit rate, input/output mix, time windows, and plan quotas interact — not to draw a fixed conclusion.
Conclusion
The real cost of an LLM API cannot be judged by the cached-token price alone. When the cache hit rate is high, plans with lower cache prices win. Once the hit rate falls, regular input and output prices determine the ranking, and the conclusion can reverse.
Subscription plans create discounts through a monthly fee and a weekly quota, but evaluating them requires factoring in quota consumption speed, peak/off-peak restrictions, and overflow fees.
Developers and enterprises should build a mixed-token cost model, run sensitivity analysis on real traffic, and continuously calibrate through logging, monitoring alerts, and budget thresholds. Turning billing rules into observable, computable, and reviewable metrics is the only way to make sound trade-offs among performance, stability, and cost.
