LLM API Real Cost Calculation and Plan Selection Guide
A practical guide to estimating the real cost of large language model APIs beyond per-token list prices. It explains the four variables that drive actual bills, provides a reproducible cost formula, shows how cost rankings can reverse at different cache hit rates, and outlines how to evaluate peak-hour pricing and convert monthly plans into a comparable discount factor. Readers will also get a cost governance checklist for capacity and budget planning.
1. Why a “Low Unit Price” Rarely Matches the Real Bill
When evaluating LLM inference services, developers are most easily misled by the “price per million tokens.” The real bill is determined by four variables working together: the cache hit ratio, the input-to-output token ratio, whether calls fall inside peak-hour windows, and whether retries or extra-long contexts cause repeated billing. Comparing list prices alone means comparing only one coefficient in the formula.
So the first step in cost estimation is not reading the price sheet, but measuring the observable characteristics of your own workload. Run a sampling period of one to two weeks and establish three baseline metrics: cache hit rate, input/output token ratio, and the share of calls placed during peak hours. Without these three numbers, any selection conclusion is only a guess.
2. The Cost Model: Writing the Bill as a Reproducible Code Block
The mainstream billing logic in the industry can be abstracted as: cached portions are charged at a discounted rate, uncached input at full price, and output at full price. Expressed as illustrative code:
def cost_per_100m(cache_hit, in_ratio, out_ratio,p_cache, p_input, p_output):# Unit: CNY per 100 million tokensreturn 1e8 * (cache_hit * in_ratio * p_cache+ (1 - cache_hit) * in_ratio * p_input+ out_ratio * p_output)
Here cache_hit is the hit rate, and in_ratio + out_ratio = 1. The value of this function is that it turns “feels cheap” into an auditable number that anyone can recompute with the same set of parameters.
3. Cost Reversal Under Two Workload Profiles
Using a typical set of parameters (an extreme long-context caching scenario with 1.5% input and 0.5% output), a key phenomenon appears: when the hit rate is very high (around 98%), the per-100-million-token cost gap between the two billing strategies is compressed into a very narrow range, and the discounted cache price dominates almost all spending. When the hit rate falls back to around 95%, the full-price uncached input portion expands quickly, the cost ranking reverses, and the side that was originally more expensive becomes the better deal.
The conclusion is not “who is cheaper,” but rather: cost advantage is a function of the hit rate, not an attribute of a brand. Every percentage point the hit rate drops pushes uncached input spending up a step, and scenarios with long contexts and fixed system prompts are especially sensitive to this.
4. Time-of-Day Differences: The Overlooked Second Variable
Beyond caching, peak/off-peak pricing is the second largest variable. Some services define peak as the entire workday, while others restrict it to a narrow window of a few hours per day. The narrower the window, the more capacity is available off-peak, and the same monthly fee buys back more tokens. When evaluating, treat “peak window duration / total weekly hours” as an explicit parameter in the model rather than judging by impression.
5. How to Convert Subscription Plans
Subscription plan pricing usually converts quota under the ideal conditions of “off-peak, high hit rate.” The correct approach has three steps:
- Multiply the official weekly quota by the number of weeks in the month to get the monthly available tokens;
- Use the formula from Section 2 with your real hit rate and time distribution to calculate the original API cost those tokens correspond to;
- Divide the plan price by that original cost to get the “plan/list price” discount factor.
The empirical range is that under ideal conditions the discount factor is about 0.5 to 0.7, meaning the plan is roughly 50% to 70% of the original API price. But if your hit rate is significantly below the ideal value, or calls concentrate in peak windows, the effective discount degrades quickly and may even be worse than pay-as-you-go. Three tiers (light/advanced/heavy) usually correspond to different quotas and discounts, and selection should match team size and call curve rather than always buying the highest tier.
6. Cost Governance Checklist
- Keep system prompts and tool definitions in a stable position to improve prefix cache reuse;
- Schedule batch, offline, and deferrable tasks into off-peak windows;
- Cap output length, since output tokens usually get no cache discount;
- Build a cost dashboard per 10,000 calls, with attribution split by hit rate and time window;
- Keep pay-as-you-go as an overflow channel to avoid expensive retries after plan quota is exhausted.
7. Conclusion
Real cost = billing structure × hit rate × time distribution × token ratio. Measure these three sets of parameters clearly, then plug them into a unified formula, and selection turns from “listening to recommendations” into a reproducible engineering decision. In practice with general-purpose LLM services on platforms such as Baidu AI Cloud, the same advice applies: let observable data drive capacity and cost planning rather than intuition based on a price sheet.
