LLM Inference Cost Estimation and Plan Selection: A Practical Guide
Comparing per-million-token prices across vendors is misleading because the real bill is driven by cache hit rate, input-to-output token ratio, and request timing. This article presents a reusable four-part cost model, shows how to convert subscription plans into equivalent pay-as-you-go credit, and offers a decision checklist for choosing between metered billing and subscriptions. It also covers practical ways to raise cache hit rates, control output costs, and run sensitivity analysis before committing to a billing model.
1. Why “Unit Price Comparison” Almost Always Leads to the Wrong Conclusion
In LLM application cost evaluation, the most common mistake is subtracting one vendor’s per-million-token price from another’s and declaring a winner. A real bill is never a linear function of unit price. It is the product effect of three variables: cache hit rate, the input-to-output token ratio, and the time distribution of requests. If any one of these shifts, the ranking can flip.
The original material describes a representative case. Under an extreme read-heavy, write-light scenario with a cache hit rate around 98%, input at 1.5%, and output at 0.5%, the cost per 100 million tokens for two candidate options was roughly CNY 12.57 and CNY 9.40 respectively, so the option with the cheaper cache strategy won. But when the hit rate fell to about 95%, the two became roughly CNY 14.92 and CNY 18.25, and the ranking completely reversed. The takeaway is not “which one is cheaper.” It is that a low cache unit price only pays off at a high hit rate, and the hit rate is precisely the least controllable variable.
2. Building a Reusable Cost Model
Abstracting the bill into a four-part structure is the prerequisite for a correct decision:
total cost = cache-hit input × cache unit price+ cache-miss input × input unit price+ output tokens × output unit price+ time-of-day factor effects
Here, “cache-hit input” refers to the context portion whose prefix is fully reused and needs no recomputation. “Cache-miss input” refers to newly added system prompt changes, conversation increments, retrieved snippets, and so on. In engineering terms, the hit rate should be treated as an independent monitored metric, not an estimated constant.
A minimal working estimation function looks like this (all parameters are placeholders and must be replaced with the actual billing rules):
def cost_per_100m(cache_hit=0.98, in_ratio=0.015, out_ratio=0.005,p_cache=0.00115, p_in=0.010, p_out=0.030):total = 100_000_000hit = total * cache_hitmiss_in = total * in_ratioout = total * out_ratioreturn hit * p_cache + miss_in * p_in + out * p_out
Moving the hit rate from 0.98 to 0.95 often changes the output by more than the unit price gap between options, which shows that optimizing the hit rate takes priority over comparing unit prices.
3. Cache Hit Rate: The Biggest Lever in the Cost Structure
The hit rate is determined by how requests are constructed, not by platform capability. Practical ways to improve it include:
- Prefix stability: keep the system prompt, tool definitions, and few-shot examples fixed at the very front of the request, and never place volatile fields such as timestamps, random IDs, or user nicknames in the prefix.
- Segmented caching: split long documents into a “stable part + changing part” so that only the changing part is billed as a cache miss.
- Route tiering: converge high-frequency similar requests onto the same template to reduce prefix divergence.
- Observability: log cache-hit and cache-miss tokens for every request in a logging service, build a hit-rate dashboard broken down by business line, and set thresholds with monitoring alerts.
Note that caches usually have capacity and time-to-live constraints, so the hit rate fluctuates with traffic patterns. Capacity planning must therefore leave headroom.
4. Input-Output Ratio: The Underrated Cost Amplifier
Output tokens typically cost significantly more than input tokens. In long-form generation workloads, even a rise in output share from 0.5% to 5% can double the total cost. Optimization paths include capping maximum generation length, using structured output to compress redundancy, applying tiered generation for summarization tasks, and using a batch API in offline scenarios (if available) in exchange for a lower unit price.
5. Time-of-Day Differences and How to Convert Subscription Plans
The time dimension in the material matters just as much. One subscription plan restricts peak hours to roughly 4 hours per workday, while some windows under pay-as-you-go billing have wider discount periods. This means whether a plan is more or less expensive must be judged against the team’s actual request time histogram. If the business peak falls exactly inside the restricted window, the plan’s effective usable volume shrinks noticeably.
The general approach to plan conversion is to translate the plan quota into “equivalent original-price API credit” and then take the ratio:
equivalent credit = total tokens available per week (under a given hit rate assumption)plan discount rate = plan price / original price of the equivalent credit
By the figures in the material, the three plan tiers correspond to roughly CNY 160, CNY 955, and CNY 2229 in original-price credit, priced at CNY 118, CNY 538, and CNY 1078, giving discount rates in the 50%–70% range. The core value of a subscription is not a lower unit price but converting volatile costs into predictable fixed spending. It suits teams with stable, forecastable workloads. For sparse or highly volatile workloads, pay-as-you-go is more economical instead.
6. Decision Checklist
- Sample real traffic for one week and measure three metrics: hit rate, input-output ratio, and time distribution.
- Use the model above to compute a cost range per 100 million tokens for pay-as-you-go, not a single point value.
- Convert the plan quota into original-price credit under the same hit rate assumption, then compare the discount rate with the overflow unit price after the quota is exceeded.
- Run sensitivity analysis: under two stress cases, hit rate ±3% and doubled output share, see which option holds up better.
- Keep the ability to switch, and avoid tight coupling to a single billing model.
In related practice at Baidu AI Cloud, the common approach is to link model calls, logging services, and monitoring alerts into a closed loop, letting observability data drive the choice of billing model rather than relying on vendor marketing claims. Ultimately, the order of cost optimization should be: first raise the hit rate, then compress output, and only then arbitrage between billing models.
