LLM Inference Cost Estimation and Plan Selection: A Practical Guide
Comparing per-million-token prices is usually misleading because LLM billing is multi-dimensional, spanning cached input, uncached input, and output tokens. This article shows how to build a cost model around cache hit rate and output ratio, add peak and off-peak pricing factors, convert subscription coding plans into equivalent pay-as-you-go costs, and run a repeatable estimation workflow while avoiding common pricing mistakes.
1. Why “Price-per-Token Comparison” Almost Always Leads to the Wrong Conclusion
In discussions about selecting an LLM service, the most common argument is that “this provider is cheaper per million tokens, so it saves more money.” This comparison is unreliable because it treats the billing model as a single scalar, when a real billing model is at least three-dimensional: cached input, uncached input, and output. The unit prices of these three often differ by an order of magnitude. Any conclusion based on just one of them is equivalent to hiding the distribution behind an average.
What makes this worse is that the actual share of these three dimensions is determined by the workload, not by the provider. A workload centered on code completion, long-document Q&A, or multi-turn agents has highly repetitive prefixes and therefore a naturally high cache hit rate. A batch job that assembles entirely new context every time may have a hit rate close to zero. Cost estimation must therefore start from a clear workload profile; otherwise, even precise numbers are meaningless.
2. Breaking the Pricing Structure into Three Token Classes
Mainstream inference pricing can generally be abstracted into three tiers:
- Cached input: tokens that hit the prefix cache, the cheapest tier, typically one-tenth to one-twentieth of the uncached input price;
- Uncached input: context tokens that must be recomputed in attention;
- Output: the autoregressively generated portion, the most expensive tier, with compute cost growing linearly with generation length.
Let $p{in}$ be the uncached input unit price, $p{cache}$ the cached input unit price, $p_{out}$ the output unit price, $h$ the cache hit rate, $N$ the total number of input and output tokens, and $r$ the output share. The actual spend per $N$ tokens is:
Cost(N) = N * [ (1 - r) * ( h * p_cache + (1 - h) * p_in ) + r * p_out ]
This formula is the core of the whole discussion. It turns the vague question of “who is cheaper” into a computable one: “under my $h$ and $r$, whose bracketed term is smaller.”
3. Hit-Rate Sensitivity: The Tipping Point Where Conclusions Reverse
Plugging in a set of illustrative numbers (all in CNY per million tokens, used only to demonstrate the method and not representing any real quote): Plan A’s cached input price is about one-tenth of its uncached input price, Plan B’s cached input price is about one-fortieth of its uncached input price, but B’s uncached input price is clearly lower.
- At $h = 98\%$, with an input/output mix of 1.5% input and 0.5% output, the two plans land in the same cost range per hundred million tokens, within about 30% of each other, and B, with the lower cache price, has a slight edge;
- When $h$ drops to $95\%$, the uncached portion grows from 2% to 5%, weight shifts rapidly toward $p_{in}$, and A becomes cheaper, with the gap widening to more than 20%.
The conclusion is clear: a low cache unit price does not mean a low total cost; it only pays off in an extremely high hit-rate range. A drop in $h$ from 98% to 95% looks like just three points, but the uncached tokens more than double, and the cost curve is steepest right here. Engineering teams should treat “raising and stabilizing the hit rate” as an independent optimization goal rather than a given premise.
4. A Second Variable: Peak and Off-Peak Pricing
Beyond caching, another common cost lever is time-of-day pricing: some platforms charge the standard rate during business peak hours and offer discounts during off-peak hours. The cost function then needs an additional time-window factor:
Cost_effective = Cost(N) * [ α * 1 + (1 - α) * (1 - d) ]
where $\alpha$ is the share of requests falling in peak hours and $d$ is the off-peak discount rate. The key point is that peak-window definitions vary widely: some platforms limit peak to about four hours per weekday, while others cover the entire weekday. The narrower the window, the easier it is to schedule workloads into off-peak periods, the smaller $\alpha$ becomes, and the closer the effective discount gets to its theoretical maximum.
A practical recommendation is to place batch workloads (offline evaluation, batch summarization, code-base index rebuilding) uniformly in off-peak windows, keep interactive requests in peak hours, and separate the two traffic types with queues and priorities.
5. Converting Subscription Coding Plans into Equivalent Tokens
Subscription plans follow a completely different pricing logic from pay-as-you-go: what they actually sell is “a quota over a period of time,” so the right way to evaluate them is to convert them into an effective discount rate.
Equivalent list price = weekly quota (tokens) * Cost(per token)Discount rate = plan monthly fee / equivalent list price
Converting the common three-tier plans (monthly fees in an approximately 1:4.5:9 ladder) under a 98% hit rate and off-peak conditions, the equivalent list prices of the three tiers land roughly between 1.4x and 2x the monthly fee, meaning the plan price is about 50% to 70% of the pay-as-you-go list price. This implies:
- The entry tier suits individual developers and lightweight trials: the shallowest discount but the lowest barrier;
- The mid and high tiers offer deeper discounts, but only hold up when the quota is genuinely used up; idle quota is a total loss;
- Once the hit rate slips or a large share of requests falls into peak hours, the equivalent list price shrinks accordingly and the discount rate worsens.
6. A Practical Estimation Workflow
- Sample: use real request logs to measure $h$, $r$, and the peak-request share $\alpha$, covering at least one full business cycle;
- Normalize: convert all quotes to a common “per million tokens” basis to avoid order-of-magnitude errors from mixed units;
- Substitute: compute the effective cost of each option with the two formulas above instead of comparing unit prices;
- Load test: run a small-traffic validation at the target hit rate to confirm the cache is not invalidated by changing context prefixes;
- Review: recompute monthly, since business growth changes $r$ and marketing campaigns change $\alpha$.
7. A Checklist of Common Mistakes
- Comparing only cache prices: this ignores that uncached input is the amplifier when the hit rate fluctuates;
- Ignoring the output share: output has the highest unit price, and $r$ rising from 0.5% to 2% is enough to change the ranking;
- Treating peak quota as normal quota: plan conversion must be based on sustainable usage;
- Overlooking cache invalidation: dynamically inserting timestamps, random IDs, or variable ordering all break prefix caching;
- Failing to normalize units: mixing “per million” with “per thousand” is the most common order-of-magnitude error.
8. Unified Cost Governance on Baidu AI Cloud
If you already use Baidu AI Cloud capabilities, you can turn the method above into a standing mechanism: use the log service to collect call details and compute $h$ and $r$, use monitoring and alerting to set thresholds for cost deviations from baseline, use a message queue and container platform to host deferrable batch jobs so they fit off-peak windows, and use object storage to reuse stable prefixes and knowledge-base material. This turns cost optimization from a one-time price comparison into an engineering practice of continuous observation and tuning.
