LLM API Cost Accounting: Cache Hit Rate and Effective Input Price
This guide explains why list prices alone cannot estimate the real cost of an LLM API that offers input caching. It shows how to calculate effective input price as a weighted average, why cache hit rate must be measured in tokens, and how prompt structure, monitoring, and billing checks affect actual spending.
1. Why Standard Input Prices Do Not Reflect Actual Cost
When evaluating a large language model API, developers usually start with the listed price per million input and output tokens. They then multiply those prices by expected usage to estimate a budget. This works for an initial comparison, but it cannot describe the real cost of a business that uses input caching.
In multi-turn conversations, document Q&A, and complex task orchestration, requests often repeat the same system instructions, background material, or conversation history. If a service supports input caching and charges less for the cache-hit portion of eligible input, the same number of input tokens can cost different amounts depending on how many of them hit the cache.
Cost evaluation therefore needs to separate at least three quantities:
- Standard input tokens: input tokens billed at the standard input price, without the cache-hit discount.
- Cache-hit input tokens: input tokens billed at the cache-hit price.
- Output tokens: tokens generated by the model and billed at the output rate.
This discussion covers the billing change from input caching, not result caching, which returns a previously generated answer directly. The two mechanisms target different costs. Input caching may reduce the cost of processing repeated context, but the model usually still generates a new answer. Result caching returns an existing answer when conditions allow. Their costs and effects should not be treated as the same.
2. Calculating the Effective Input Price as a Weighted Average
Within a given statistical period, define the following:
- total input tokens: (T);
- cache-hit input tokens: (T_h);
- standard input price: (P_s);
- cache-hit price: (P_h).
Both prices are in CNY per million tokens. The cache hit rate, measured by input token count, is:
[
h=\frac{T_h}{T}
]
If no other input-related fees apply and both input types are billed at the prices above, the input cost is:
[
C_{in}=\frac{T-T_h}{10^6}P_s+\frac{T_h}{10^6}P_h
]
The corresponding effective input price is:
[
P_{eff}=(1-h)P_s+hP_h
]
The effective price is a weighted average of the standard price and the cache-hit price. A higher hit rate moves the effective price closer to the cache-hit price, but it does not drop the price to zero.
A worked example with labeled assumptions
The following figures only illustrate the calculation method. They do not reflect any service’s current pricing, and they do not guarantee a cache hit rate.
Assumptions:
- standard input price: 4 CNY per million tokens;
- cache-hit price: 0.7 CNY per million tokens;
- input token cache hit rate: 90%;
- total input: 1 million tokens.
The cache-hit portion costs:
[
0.9\times0.7=0.63\text{ CNY}
]
The uncached portion costs:
[
0.1\times4=0.4\text{ CNY}
]
The total input cost is 1.03 CNY. Compared with 4 CNY if every token were billed at the standard price, the ratio is:
[
\frac{1.03}{4}=25.75\%
]
Input cost falls by about 74.25%. In Chinese pricing language, this ratio is often called “2.6 tenths” (2.6折), meaning the price is about 26% of the list price. For a rough description, “about 2.6 tenths” is acceptable. A rigorous cost calculation should keep the exact result instead of treating a rounded promotional phrase as an exact bill.
This reduction applies only to input cost. It does not reduce the total cost of a single request or an entire business.
3. The 90% Hit Rate Requires a Defined Basis
A “90% cache hit rate” sounds straightforward, but the calculation depends on what the denominator is.
1. Request hit rate is not token hit rate
Request hit rate describes how many requests included a cache hit. For example, if 90 of 100 requests hit the cache for part of their input, the request hit rate is 90%.
Those 90 requests may each hit only a short shared instruction while most of their input is still billed at the standard price. A 90% request hit rate therefore does not mean that 90% of input tokens receive the cache-hit price.
The weighted formula requires this value:
[
\frac{\text{total cache-hit input tokens}}{\text{total input tokens}}
]
If the service returns verifiable cache usage data, use that data first and check it against the bill. If you can only observe whether a request hit the cache, you cannot derive an accurate effective price from it.
2. Aggregate statistics do not represent a specific business
Context structures vary widely between businesses. A service that runs ongoing Q&A over a fixed long document may reuse a large share of its input. Another service that submits different short texts each time may have little stable repeated content.
Other samples or aggregate statistics can serve as references, but they should not be used directly for budgeting a specific business. A better approach is to measure a representative set of requests under conditions that resemble real traffic patterns.
3. Averages can hide changes over time
Cold starts, updates to shared instructions, long idle periods, and cache expiration can all change the hit rate. The actual impact depends on the caching mechanism the service supports.
Measuring only peak hours can overestimate the all-day hit rate. A short, concentrated load test may also miss how the system behaves during low-frequency access. Cost tracking should cover normal operation, low-traffic periods, and context updates.
4. How Sensitive Price Is to Cache Hit Rate
Using the same assumed prices, the results are:
| Input token cache hit rate | Effective input price (CNY per million tokens) | Cost as a share of standard price |
|---|---|---|
| 0% | 4.00 | 100% |
| 50% | 2.35 | 58.75% |
| 80% | 1.36 | 34% |
| 90% | 1.03 | 25.75% |
| 95% | 0.865 | 21.625% |
All values in this table depend on the assumed prices. They cannot be generalized to other pricing plans.
The formula also shows that each one-percentage-point increase in hit rate lowers the effective price by:
[
0.01(P_s-P_h)
]
In this example, each point reduces the effective price by 0.033 CNY per million tokens. The economic value of caching depends not only on the hit rate but also on the gap between the standard and cache-hit prices, and on total input volume.
If the two prices are close, the savings from caching will be small. If input volume is low but the engineering work is complex, the savings may not cover the maintenance cost.
5. Organizing Context to Increase Reusable Input
Whether caching takes effect depends on the service’s actual rules. Common implementations may require a repeated prefix, a minimum input length, or a specific cache lifetime. Before optimizing on the application side, confirm these conditions. Do not assume that the API supports a particular caching parameter or retention period.
1. Place stable content first when the semantics allow
For caching mechanisms based on a repeated prefix, put stable shared instructions, task specifications, and common background at the beginning. Put the current user input and frequently changing data at the end.
For example, the context could be ordered as follows:
Public behavior constraints → Fixed task description → Reusable reference material → Current user input
This reduces unnecessary changes at the start of the prompt. Do not change the priority of key instructions or break the task’s meaning to make caching work. After optimization, check answer quality and instruction following again.
2. Avoid dynamic fields that break repeated content
Some caching mechanisms identify reusable content by exact input match. In those cases, a timestamp, random identifier, or frequently changing description at the start of the input can prevent later content from being reused.
Fields needed only for log correlation can stay in the request logs instead of the model context. Dynamic information that the model actually needs for reasoning should remain in the prompt, placed where it does not affect the semantics.
Stable serialization, consistent field order, and uniform text formatting also help avoid changes that carry no business meaning. Confirm which differences actually affect caching through the documentation and testing.
3. Do not keep unnecessary context just to get cache hits
Cached input is usually still billed. Attaching large amounts of irrelevant material to every request can increase total cost, even if the hit rate rises.
The goal is:
Lower the total cost of each successful task while meeting the quality requirements.
First decide whether each input is necessary, then decide how to reuse the necessary parts. Removing irrelevant paragraphs, limiting conversation history, and providing reference material only when needed often matter as much as caching.
6. Extending from Input Price to Total Business Cost
The effective input price is only one part of the total cost model. A complete budget should also include output costs and any other fees the service actually charges:
[
C{total}=C{in}+C{out}+C{other}
]
Here, (C_{other}) covers only fees that actually apply, such as explicitly billed cache writes, storage, or other resource charges. Do not assume such fees exist or do not exist without confirmation.
At the business level, also track retries, regeneration after failures, unusually long outputs, and duplicate tasks. Even a clear drop in input cost can be offset by more output tokens or more retries.
Monitor the following:
- actual cost per million input tokens;
- average cost per call;
- cost per successful task;
- answer quality and task completion rate;
- latency distribution and error rate.
Cost per successful task matters most because it brings quality into the comparison. A cheap option that fails often may not be more economical.
7. Building a Verifiable Testing and Monitoring Process
Before launch, complete the following steps.
Step 1: Establish an unoptimized baseline.
Select representative tasks and record input volume, output volume, cost, quality, and latency. Identify where the current cost comes from.
Step 2: Confirm the billing and caching rules.
Verify the conditions for cache recognition, the usage data you can observe, the cache lifetime, and any additional fees. Do not infer capabilities that the documentation does not state.
Step 3: Change one variable at a time.
Adjust the position of shared context or remove unnecessary input first. Avoid changing the prompt structure, reference material, and output requirements at the same time, or you will not know which change produced the result.
Step 4: Cover different operating phases.
Test cold starts, continuous access, low-frequency access, and behavior after context updates separately. Do not estimate long-term cost using only ideal conditions.
Step 5: Reconcile against the bill.
Put total input volume, cache-hit volume, and applicable prices into the formulas, then compare the estimated cost with the actual cost. If the two differ, check the billing basis, the measurement boundaries, and whether other fees apply.
In long-term monitoring, aggregate data by business type and time window. Do not simply average the hit percentage per request. Requests with different input lengths must be weighted by token count to obtain the true hit rate used for cost accounting.
8. Conclusion: Caching Is a Cost Variable, Not a Fixed Discount
A high cache hit rate can significantly reduce input cost. That benefit holds only when enough input is reusable, the cache-hit price is actually lower, the measurement basis is correct, and other fees do not offset the savings.
When evaluating an LLM API, move from comparing list prices to calculating total cost under your actual request structure. Use the weighted formula to explain the effective input price, validate the hit rate with real business data, and then make decisions that also account for output costs, task quality, and engineering maintenance.
Only results verified against actual usage and bills should serve as a budget basis. A “about 2.6 tenths” figure under specific assumptions can show the economic value of caching, but it cannot replace measuring and accounting for a specific business.
