LLM API Pricing Structure and Cost Optimization Practices
This article breaks down how LLM API billing works beyond simple per-token rates, covering asymmetric input/output pricing, context caching economics, and high-speed tier trade-offs. It presents a reusable cost model, break-even calculations for cache reuse, and a practical optimization checklist with a sample call skeleton, helping teams control spending through prefix normalization, output limits, model tiering, and observability.
1. Why Pricing Structure Matters More Than Unit Price
When integrating LLM capabilities into production systems, teams often fixate on a single number—cost per million tokens—only to see bills deviate sharply from expectations. Real cost is determined by several dimensions together: the price ratio between input and output, the hit and write strategy for context caching, whether a high-speed tier is used, and the concurrency pattern of requests. A set of pricing data from the original source happens to surface all of these dimensions: the standard tier charges 13 CNY per million input tokens and 68 CNY per million output tokens; the high-speed tier charges 26 CNY for input and 136 CNY for output, exactly double the standard tier; the cache hit price is 1.30 CNY, roughly one-tenth of the input price; cache writes are split into 5-minute and 1-hour tiers at 13 CNY and 26 CNY respectively; and the previous-generation model charges 20 CNY for input, 100 CNY for output, with a 2.00 CNY cache hit price.
Three general rules can be distilled from this data, and they apply to the vast majority of commercial token-based model services:
- Output is usually more expensive than input, by a factor of 4 to 6, so “making the model say less” is the highest-leverage optimization direction;
- The cache hit price is significantly lower than the regular input price, making reuse of a stable prefix a cost-reduction lever;
- The high-speed tier is purely a performance purchase that doubles the overall price, and should be enabled per scenario rather than by default.
2. An Abstract Model of Three Billing Dimensions
1. Base Tokens: Asymmetric Pricing for Input and Output
Writing the cost of a single request as a formula makes it more intuitive:
Cost per request = input tokens × P_in + output tokens × P_out
Since P_out is roughly 5 times P_in, for a request with 2000 output tokens and 500 input tokens, about 94% of the cost comes from output. This means the objective function for prompt optimization is not “shorter” but “input kept as lean and reusable as possible, output strictly controlled.” In engineering terms, this overhead can be reduced by enforcing structured output, setting a maximum output length, and breaking open-ended generation into small-step tasks.
2. Context Caching: The Time Value of Hits and Writes
Caching splits cost into two parts: writes and hits. The write price equals the regular input price (double for the 1-hour tier), and the hit price is about one-tenth of the input price. Whether it pays off depends on the number of reuses and the survival time, which can be judged with a break-even point:
For the 5-minute tier: required hits > 1 / (1 - 0.1) ≈ 1.11, meaning reuse twice to break evenFor the 1-hour tier: required hits > 2 / (2 - 0.1) ≈ 1.05, likewise reuse twice to break even
The conclusion is that caching is extremely friendly to workloads with “long prefixes and repeated calls,” while it is a net loss for one-off short requests. Content suitable for caching includes system instructions, tool and function definitions, domain knowledge manuals, a few examples, and full long documents; content unsuitable for caching includes fragments with timestamps, random IDs, or user session state—they change the prefix every time and drive the hit rate to zero.
3. High-Speed Tier: Paying for a Latency Budget
The high-speed tier doubles input, output, and cache writes, while the cache hit price stays unchanged. This detail has engineering implications: the portion served from cache no longer pays twice for speed, so the combination of “high reuse plus low latency” actually offers better value on the high-speed tier. Whether to enable it should be based on a clear latency budget—for example, interactive completion and real-time conversation can enable it, while offline batch processing, data cleaning, and log summarization should not.
3. An Actionable Optimization Checklist
- Prefix normalization: place invariant instructions and knowledge at the front and dynamic content at the back, keeping the prefix byte-for-byte stable.
- Cache tier selection: use the short tier when call intervals are stable at the minute level, and the long tier for knowledge bases reused across sessions.
- Output constraints: use structured formats and length limits to control spending on the P_out side.
- Model tiering: route simple classification, extraction, and rewriting to small models or a rules engine, and reserve the flagship model for complex reasoning.
- Batching and off-peak scheduling: merge requests for offline tasks to avoid paying the high-speed premium for low-priority traffic.
- Observability: tag and measure tokens and cache hit rates by business dimension, and set cost thresholds with monitoring and alerts.
A skeletal call structure is shown below:
STATIC_PREFIX = load_knowledge_pack() # Stable and invariant, suitable for cachingdef ask(question: str, need_fast: bool = False):payload = {"model": "flagship-pro-highspeed" if need_fast else "flagship-pro","messages": [{"role": "system", "content": STATIC_PREFIX},{"role": "user", "content": question},],"max_tokens": 512,}return call_api(payload) # Refer to the model service documentation of your cloud platform for the specific API
4. Common Pitfalls
The first is treating caching as free storage while ignoring write costs and invalidation risk; the second is enabling the high-speed tier everywhere, doubling the overall bill while optimizing only a few interactive paths; the third is making selection decisions based on unit price alone, overlooking scenarios where the previous-generation model may have an advantage in cache hit price; the fourth is lacking token-level attribution, making it impossible to locate the source of cost anomalies. In model service practice on platforms such as Baidu AI Cloud, it is generally recommended to first establish a small-scale baseline load test, then decide the tier and channel combination based on the measured input/output ratio and cache hit rate, driving cost decisions with data rather than intuition.
