A Practical Guide to Calculating the Real Cost of LLM Inference
Comparing per-token prices alone often leads to wrong conclusions about LLM inference costs. This guide breaks down a reproducible cost model based on cache hit rates, peak-hour rules, and input-output ratios, and shows how to convert subscription plans into API-equivalent pricing for more reliable procurement decisions.
1. Why Per-Token Price Comparisons Often Lead to Wrong Conclusions
When evaluating LLM inference services, the most common mistake is treating a single per-token price as the basis for total cost. A real bill is usually the sum of several billing dimensions: the cached portion, the uncached input portion, and the output portion, all multiplied by call volume. If the share of any one dimension changes, the conclusion can flip.
The core phenomenon discussed in the original article is this: one platform’s cache price is roughly twice that of another option, yet in high-cache-hit scenarios the total cost gap narrows significantly. When the cache hit rate drops, the conclusion may reverse again. This shows that unit price is only one parameter and cannot support a purchasing decision on its own.
Therefore, this article does not focus on any specific product. Instead, it frames the problem as a general technical question: how to build a reproducible inference cost model.
2. The Basic Structure of the Cost Model
Let:
C_hit: cache hit unit priceC_in: uncached input unit priceC_out: output unit priceh: cache hit rater_in: share of uncached input in total tokensr_out: share of output in total tokensN: total token volume
The unit cost can be written as:
Cost = N * ( h * C_hit + r_in * C_in + r_out * C_out )
Example code:
def estimate_cost(n, h, c_hit, c_in, c_out, r_in, r_out):return n * (h * c_hit + r_in * c_in + r_out * c_out)# Example: per 100 million tokensprint(estimate_cost(1e8, 0.98, 0.115, 12.0, 30.0, 0.015, 0.005))
The value of this model is that it turns “feels expensive” into “verifiable numbers”.
3. How Three Key Variables Affect the Conclusion
3.1 Cache Hit Rate
A cache hit is the result of reusing long contexts, repeated system prompts, and fixed knowledge snippets. Raising the hit rate from 95% to 98% may look like a difference of only 3 percentage points, but because the unit price of the cached portion is usually far lower than that of uncached input, the overall cost changes non-linearly. In engineering practice, you can improve the hit rate by keeping prompt prefixes stable and reducing unnecessary variable fields.
3.2 Definition of Peak Hours
Different platforms define peak hours differently. Some use a fixed number of hours per day, while others count the entire workday. The shorter and more concentrated the peak window, the easier it is to avoid through task scheduling. The practical recommendation is to run batch jobs, offline evaluations, and log summarization outside peak windows.
3.3 Input-Output Ratio
The output unit price is usually the highest. If the workload is mainly long-form generation, a rise in r_out will quickly drive up costs. If the workload is mainly retrieval-based question answering or code completion, the input share is higher, and the benefits of a caching strategy are more obvious.
4. Converting Subscriptions to Pay-as-You-Go
Subscription plans commonly provide a “token allowance per billing cycle” and then convert it into an equivalent amount at the original API price. The general conversion formula is:
Plan unit price = Plan price / Converted original API allowance
The range given in the original article is that the plan unit price is about 50% to 70% of the original price. This means a plan has a cost advantage under stable usage, but if actual usage falls below the allowance, the unit cost can actually rise. The key decision point is to estimate your average weekly token consumption and then judge whether you will fully use the allowance.
5. Implementation Checklist
- Establish a baseline: first measure the real token distribution over one week, including the cached, input, and output portions;
- Run a sensitivity analysis: calculate at both 95% and 98% hit rates and check whether the conclusion holds;
- Optimize scheduling: move deferrable tasks out of peak windows;
- Govern prompts: fix prefixes and compress redundant context to improve cache reuse;
- Control output: cap the maximum generation length to avoid runaway output costs;
- Review regularly: recalculate the model once a month to prevent business changes from invalidating the conclusion.
6. Conclusion
The essence of cost evaluation is not finding “the cheapest vendor”, but building a calculation framework that matches your own traffic structure. As long as you bring cache hit rate, peak-hour rules, and input-output ratio into a unified formula, you can make more robust decisions when choosing between options.
