Demystifying LLM Cost Calculation: Cache Hits, Discounts, and Blended Unit Prices
This article explains how to calculate LLM call costs when pricing separates cached input, uncached input, and output tokens. It covers how to define a blended unit price, convert between cache hit rates and token weights, handle discounts and add-on fees, and estimate budgets. It also explains why cost per successful task is a better decision metric than price per million tokens.
1. Why Comparing Input Prices Alone Is Not Enough
In LLM applications, the cost of a single request usually comes from several components: uncached input, cached input, and model-generated output. Some billing plans also include cache write fees, storage fees, long-context tiers, or other add-on charges. Check the actual billing documentation for the exact items that apply.
Comparing input prices alone ignores the structure of your traffic. For example, an application with a long, fixed prompt that is reused many times may find that cache read prices have a much larger effect on total cost. An application that generates long reports may find that output prices are the main cost driver.
The useful question is therefore not “Which price is lowest?” in isolation. Instead, ask three questions:
- At the same input and output volume, how much will the workload cost?
- At a realistic cache hit rate, does the plan still offer an advantage?
- Given your quality, latency, and stability requirements, how much does it cost to complete one business task?
The blended unit price answers part of the first question. A complete cost decision also requires real traffic data and task success rates.
2. Define the Three Billed Quantities and Their Units
To keep the calculations consistent, this article uses the following variables:
- (T_r): Input tokens billed at the cache read price.
- (T_u): Input tokens that miss the cache and are billed at the standard input price.
- (T_o): Output tokens billed at the output price.
- (P_r): Cache read unit price.
- (P_u): Standard input unit price.
- (P_o): Output unit price.
A token is the unit a model uses to process text. Do not equate tokens directly with Chinese characters, characters, or words. Different tokenizers can produce different billed counts for the same text. When comparing plans, check actual token usage instead of assuming that identical text produces identical billed quantities.
If all three prices are quoted in currency per million tokens, the base cost is:
[
C_{\text{base}}=
\frac{T_rP_r+T_uP_u+T_oP_o}{10^6}
]
This formula holds only if the three quantities use clearly defined, non-overlapping billing bases. Cached input tokens must not also be charged at the standard input price in the base cost, unless the bill lists them as a separate line item.
If there are additional fees, add them separately:
[
C{\text{total}}=C{\text{base}}+C_{\text{additional}}
]
Additional costs may include cache write fees, storage fees, or other service fees that actually apply. Do not ignore these items to simplify a comparison, and do not assume they exist without evidence.
3. Interpreting the “80% Read, 10% Input, 10% Output” Assumption
For quick comparisons, one useful assumption is that 80% of all billed tokens are cache reads, 10% are uncached input, and 10% are output.
Under this assumption, the blended unit price is:
[
P_{\text{blend}}=0.8P_r+0.1P_u+0.1P_o
]
This metric is the average cost per million total billed tokens for the mixed structure above. It is not the cost per million input tokens, and it is not the cost per request.
Note that an 80% share of cache-read weight is not the same as an 80% input cache hit rate.
In this assumption, input tokens make up 90% of all billed tokens, and cache reads make up 80%. The input cache hit rate measured by token count is therefore:
[
h=\frac{T_r}{T_r+T_u}
=\frac{0.8}{0.8+0.1}
\approx 88.89\%
]
The ratio of output tokens to input tokens is:
[
q=\frac{T_o}{T_r+T_u}
=\frac{0.1}{0.9}
\approx 11.11\%
]
This conversion matters. If “80% of all tokens come from cache reads” is mistaken for “an 80% input cache hit rate,” the traffic structure used in the model will be wrong, and the cost results will differ.
4. A General Model Based on Cache Hit Rate and Output Ratio
Fixed weights work well for quick estimates, but real cache and output volumes change over time. A more practical approach is to use the input cache hit rate (h) and the output-to-input ratio (q) directly.
Let (T_{\text{in}}) be the total input volume. Then:
[
Tr=hT{\text{in}}
]
[
Tu=(1-h)T{\text{in}}
]
[
To=qT{\text{in}}
]
Substituting these into the base cost formula gives:
[
C{\text{base}}=
\frac{T{\text{in}}}{10^6}
\left[hP_r+(1-h)P_u+qP_o\right]
]
This produces two metrics for different purposes.
1. Normalized per Million Input Tokens
[
P_{\text{per input}}=hP_r+(1-h)P_u+qP_o
]
This metric spreads the related output cost across the input volume. It suits budgeting from historical input volume. Reports using this metric must state that the figure includes the corresponding output cost, so readers do not mistake it for a standard input price.
2. Normalized per Million Total Billed Tokens
[
P_{\text{per total}}=
\frac{hP_r+(1-h)P_u+qP_o}{1+q}
]
This metric matches the fixed-weight blended unit price. It works for comparing weighted average costs across different traffic structures.
Both metrics are valid, but do not mix them. Every cost report should state whether its denominator is input volume, total input and output volume, or request count.
5. Checking the Calculation with an Illustrative Example
The following figures only illustrate the formulas. They do not represent any actual service price.
Assume a billing plan has these three prices:
| Billing category | Illustrative unit price, CNY per million tokens |
|---|---|
| Cache read | 0.20 |
| Uncached input | 2.00 |
| Output | 8.00 |
Using the fixed weights of 80%, 10%, and 10%:
[
P_{\text{blend}}
=0.8\times0.20+0.1\times2.00+0.1\times8.00
=1.16
]
If a statistical period has 10 million total billed tokens, and the mix matches these weights exactly, the base cost is:
[
C_{\text{base}}=10\times1.16=11.60\text{ CNY}
]
You can cross-check this with actual quantities:
- 8 million cache-read tokens cost 1.60 CNY.
- 1 million uncached input tokens cost 2.00 CNY.
- 1 million output tokens cost 8.00 CNY.
The three items add up to the same 11.60 CNY.
The example shows that output accounts for only 10% of total tokens but contributes most of the cost because of its higher unit price. Cache optimization and output length management should be evaluated together, not only on the input side.
6. Keep Reference Prices and Actual Settlement Prices Separate
Cost assessments should clearly separate published reference prices from actual settlement prices. The two can differ because of promotion periods, eligible scope, time windows, usage quotas, or contract terms.
If every billing item uses the same discount factor (d), where (d=0.1) means paying 10% of the reference price, then:
[
P{\text{settlement}}=dP{\text{reference}}
]
In this case, the blended unit price can also be multiplied by (d) directly.
If different items have different discounts, calculate each item separately:
[
P_{\text{blend settlement}}
=0.8d_rP_r+0.1d_uP_u+0.1d_oP_o
]
Here, (d_r), (d_u), and (d_o) are the actual discount factors for cache reads, uncached input, and output.
Do not assume that a headline discount applies at the same rate to every item. If there are fixed quotas, capped discounts, or tiered rules, settlement cost may be a nonlinear function of usage. In that case, calculate the cost piecewise according to the actual rules.
Your price ledger should record at least:
- The source of each price and the date it was verified.
- The billing unit and currency.
- Context ranges and the price for each range.
- Effective time periods and promotion expiration dates.
- The conditions that apply to each billing item.
- Any additional fees or minimum spending requirements.
Mark missing prices as “unverified” rather than entering zero. Plans whose costs cannot be fully calculated should not be included in a ranking on the same basis.
7. Why a Single Ranking Is Not Reliable
A ranking by blended unit price holds only under specific assumptions. If the cache hit rate or output ratio changes, the ranking may change too.
1. Changes in Cache Hit Rate
When total input volume and output ratio stay the same:
[
\frac{\partial C{\text{base}}}{\partial h}
=\frac{T{\text{in}}}{10^6}(P_r-P_u)
]
If the cache read price is lower than the standard input price, a higher hit rate usually reduces base cost. Actual savings, however, must account for new cache write fees, storage fees, and similar charges. Counting only the savings on reads is not enough.
Also, a hit rate measured by request count differs from one measured by token count. Many short requests hitting the cache do not mean that most input tokens were read at the lower price.
2. Changes in Output Ratio
With input volume unchanged, longer outputs usually increase cost. When you evaluate report generation, code generation, or multi-turn explanation applications, use the actual output distribution instead of a single average.
Output limits should not be reduced without considering the effects. Answers that are too short can prompt follow-up questions or system retries, which can raise the total cost of completing a task.
3. Changes in Time Windows and Context Tiers
If a billing plan uses time-of-use prices, weight the cost by the billed volume in each period. Do not average by the length of each period. If prices depend on context size, first assign each request to the correct context tier, then add up the costs.
A sounder approach is to model several scenarios. Consider low, typical, and high cache reuse, along with short, typical, and long outputs. Calculate costs for each scenario, then check whether the ranking stays the same.
8. Turning Blended Unit Prices into Business Budgets
Assume (N) requests per day, an average input size of (I) per request, an average output size of (O) per request, and a token-weighted input cache hit rate of (h). The daily base cost can then be estimated as:
[
C_{\text{day}}=
\frac{N}{10^6}
\left[IhP_r+I(1-h)P_u+OP_o\right]
]
This formula suits initial planning. More precise estimates should sum costs by business type or by actual request logs. Averages can hide the correlation between long requests, high-output requests, and cache hits.
Production budgets should also cover retries, failed calls that are still billed, and multiple model calls within a single business task. You can define:
[
C_{\text{per successful task}}
=\frac{\text{total related spending in the period}}{\text{number of successfully completed tasks}}
]
This metric is closer to business value than price per million tokens. A plan with a low price per call that often needs several rounds of correction may not have a lower cost per successful task.
9. Applying Cost Tracking to Monitoring and Engineering Optimization
Include request volume, cache read volume, output volume, retry counts, and billing data in a unified monitoring system. Basic logs should focus on metering fields. Avoid storing full sensitive text just to calculate costs.
Reports can show:
- Daily and monthly total costs.
- Cost per request for each business category.
- Token-weighted cache hit rate.
- Output-to-input ratio.
- Average cost per successful task.
- Budget burn rate and unusual fluctuations.
For optimization, keep reusable prefixes
