LLM Inference Cost Calculation and Plan Selection: A Practical Guide
Comparing per-token prices alone often leads to wrong conclusions about LLM inference costs. This article shows how to build a weighted cost model based on cache hit rate, input/output ratio, and peak-hour distribution, how to find the break-even point between pricing schemes, how to evaluate subscription plans, and provides a decision checklist for choosing the most cost-effective setup.
1. Why Comparing Unit Prices Leads to Wrong Conclusions
When evaluating LLM inference services, the most common mistake is to compare two price numbers directly. For example, one cached-read price might be 0.115 CNY per million tokens while another is 0.05 CNY, leading to the conclusion that one is “more than twice as expensive.” That conclusion is mathematically correct but practically meaningless, because it treats a single variable as the whole picture.
A real bill is determined by four types of tokens: cached reads, uncached input, output, and possible cache-write overhead. The cached-read price applies to only one of them. When the cache hit rate is high, the largest share of traffic goes through the cheapest tier, significantly narrowing the total cost gap between two options. When the hit rate drops and the uncached-input share rises, the price structure reverses.
The right way to compare costs is therefore: first build a weighted per-token cost model, then plug in the real distribution of your own workload, and only then discuss which option is cheaper.
2. Building a Reusable Cost Model
Let the cache hit rate be h, the input share be a, and the output share be b (a + b + h = 1), with unit prices P_cache, P_in, and P_out. The cost per unit token is:
C = h * P_cache + a * P_in + b * P_out
Using 100 million tokens as the unit of measurement, simply multiply the unit price by 100 (since 100 million = 100 × 1 million).
Plugging in a typical set of parameters (cached read 0.115 CNY, input 1.2 CNY, output 6 CNY, in CNY per million tokens):
- h=98%, a=1.5%, b=0.5%: C ≈ 12.57 CNY per 100 million tokens
- h=95%, a=4.5%, b=0.5%: C ≈ 14.92 CNY per 100 million tokens
Compare with another set of parameters (cached read 0.05 CNY, input 1.2 CNY, output 6 CNY):
- h=98%: C ≈ 9.40 CNY per 100 million tokens
- h=95%: C ≈ 18.25 CNY per 100 million tokens
The conclusion is clear: at a 98% hit rate, the low cached-read price option is about 25% cheaper; at a 95% hit rate, the high cached-read price option is about 18% cheaper instead. The cached-read price is not the conclusion; the hit rate is the dividing line. The crossover point of this curve is what selection should really focus on.
3. What Determines the Cache Hit Rate
The hit rate is not a configuration item but a natural result of the workload and how requests are made. In practice, the following scenarios tend to achieve high hit rates:
- Long system prompts, fixed tool descriptions, and repeated Q&A over long documents;
- Multi-turn conversations with a stable prefix where content is only appended at the end;
- Batch tasks that share the same context template.
Conversely, the hit rate drops noticeably when: every request prepends volatile content such as timestamps, random IDs, or usernames; models or context templates are switched frequently; or concurrency is too low, causing cache entries to be evicted.
A practical approach is to make the prefix “cache-friendly”:
[Stable prefix: system instructions + tool definitions + reference documents] ← keep unchanged as much as possible[Volatile part: time, user identifier, current question] ← put at the end
The hit rate should also be treated as a first-class monitoring metric, placed alongside P95 latency and error rate, wired into logging and alerting, and observed per business line.
4. Peak Hours: The Underestimated Multiplier
Pay-as-you-go billing usually distinguishes peak and off-peak periods, and off-peak unit prices may be only a fraction of peak prices. This means the same token volume can produce bills that differ by several times. For capacity planning, treat the “share of traffic carried during peak hours” as an independent variable rather than assuming an all-day average price.
More importantly, services define peak hours very differently: some split the day into two periods, while others compress peak into a few hours on workdays. The shorter the peak window and the closer it sits to the real trough of your workload, the easier it is to shift load out through scheduling.
Actionable scheduling strategies include: staggering offline batch jobs, code-completion warmups, and evaluation and regression tasks; reserving peak quota for interactive requests; and setting up queues that run non-real-time tasks “off-peak only.”
5. How to Evaluate Subscription Plans
The appeal of subscription plans is that they turn variable costs into fixed costs, but they must be converted to a common basis before comparison. The conversion has three steps:
- Multiply the usable quota given by the provider (such as the total tokens consumable per cycle) by the corresponding unit price to get the “equivalent amount at original API prices”;
- Divide the plan price by that equivalent amount to get the discount rate;
- Use your real monthly token volume and peak share to judge whether the plan quota is sufficient or largely wasted.
Across a set of common tiers (roughly 118 CNY/month for the low tier, 538 CNY/month for the mid tier, and 1078 CNY/month for the high tier), converted under high hit rate and off-peak conditions, the effective plan unit price is roughly 50%–70% of the pay-as-you-go original price. In other words, a plan is like a 30%–50% discount, but it also introduces quota caps and time-window constraints.
def plan_effective_price(plan_fee, quota_tokens, unit_price_per_m):origin = quota_tokens / 1_000_000 * unit_price_per_mreturn plan_fee / origin # discount rate; lower is better
6. Decision Checklist
- Measure the hit rate first: replay a week of real traffic to get a distribution of h rather than a single value;
- Then calculate the crossover point: sweep h from 90% to 99% to find the critical value where the two options cost the same;
- Assess time flexibility: measure the share of tokens that can be shifted to off-peak periods;
- Compare plans last: subscriptions only win when steady usage falls within the plan quota and the peak share is manageable;
- Keep an exit option: prefer solutions that let you switch back to pay-as-you-go at any time, avoiding long-term lock-in.
7. Conclusion
The essence of cost optimization is upgrading “unit price comparison” to “structural modeling.” Cache hit rate, input/output ratio, and time-of-day distribution together determine the bill, and no single price point is enough to support a decision. Only by turning this model into a script and connecting it to monitoring can you keep costs under control as workloads fluctuate. If you need elastic compute along with supporting data and monitoring capabilities, you can combine them on demand from general cloud product categories offered by Baidu AI Cloud.
