LLM API Pricing Differences and Cost Optimization Practices
This article explains why per-token price lists alone cannot predict LLM API costs, breaks down four common billing mechanisms, and presents a reusable cost model. It also outlines a four-step vendor comparison process, five practical cost-reduction techniques, and architecture-level recommendations for making billing observable and optimizable.
1. The Starting Problem: Why a Price List Alone Cannot Determine Cost
When evaluating LLM API costs, many teams look at unit prices first: whoever charges less per million tokens is assumed to be the better deal. In real workloads, that judgment often fails, for three reasons.
First, pricing dimensions are not standardized. Some platforms price input and output separately, with output typically costing several times more than input. Others tier pricing by the context length of a single request, so the more tokens involved, the higher the unit price. Some also apply a separate discount to input tokens that hit a cache.
Second, billing definitions are not standardized. How tokens are split, whether system prompts are billed, how multimodal input is converted into billable units, and whether failed retries are billed — these details can significantly change the final bill.
Third, workload structures differ. For a task centered on long-document summarization, input may account for more than ninety percent of the tokens; for a code generation task, the output share rises noticeably. The same price list applied to different workloads can lead to completely opposite conclusions.
The correct approach, therefore, is to build a workload profile first, then a pricing model, and only then compare total costs.
2. How Four Common Billing Mechanisms Work
2.1 Asymmetric Input/Output Pricing
The mainstream approach prices input and output separately, with output being more expensive. The reason is that the generation stage requires token-by-token forward computation, which costs more compute per unit than the prefill stage. The engineering implication is direct: controlling output length often saves more money than compressing input.
2.2 Tiered Pricing by Context Length
Some platforms tier pricing by the input size of a single request — for example, different unit prices for up to 32K, 32K to 128K, and above 128K. The purpose of this design is to make long-context requests bear the higher resource cost they consume. The engineering implication is that splitting one very long request into several shorter ones can sometimes lower the total price, but this trade-off must be weighed against quality loss and the increased number of requests.
2.3 Context Caching and Hit Discounts
When multiple requests share the same prefix (typically a fixed system prompt, a long document, or knowledge base snippets), the platform can reuse already-computed intermediate results and discount the portion that hits the cache, usually with different prices for the initial write and subsequent hits. This is the single largest cost-reduction lever for long-document, multi-turn conversation, and batch extraction scenarios.
2.4 Free Quotas, Tiered Quotas, and Committed Plans
Beyond pay-as-you-go, the industry also commonly offers resource packages, reserved throughput, and quota tiers. Teams with stable, predictable workloads usually save more with a reserved approach than with pure pay-as-you-go; teams with highly variable workloads get more flexibility from pay-as-you-go plus caching.
3. A Reusable Cost Estimation Model
Let the input tokens be Tin, the output tokens be Tout, the cache hit ratio be h, the input unit price Pin, the output unit price Pout, and the cache-hit input unit price Phit. The cost of a single task is then:
Cost = Tin * (1 - h) * Pin + Tin * h * Phit + Tout * Pout
Take a batch task of realistic scale as an example: about 509.8K input tokens and about 8.1K output tokens, of which roughly 467.3K tokens are a cacheable repeated prefix. With flat unit pricing and a hit discount of about one tenth of the input price:
Uncached input: 42.5K * 2.0 / 1e6 ≈ 0.085Cached input: 467.3K * 0.2 / 1e6 ≈ 0.093Output: 8.1K * 8.0 / 1e6 ≈ 0.065Total ≈ 0.24 (billing units)
Now switch to tiered pricing where 509.8K falls into the highest tier (input unit price roughly three times the previous example, output roughly three and a half times), with no cache discount. The same task then costs somewhere between about 0.8 and 1.0 — more than a threefold difference. This comparison shows that what determines the bill is not whether the unit price is low, but how well the billing mechanism matches the workload structure.
Note that the figures above are illustrative estimates meant to show the calculation flow; they do not represent the actual prices of any specific platform. For real costs, refer to the official billing documentation of the cloud service you choose.
4. How to Compare Four Providers Properly
The original “who is the best” question cannot be answered with a single price table. A more rigorous comparison follows four steps:
- Standardize the workload: use the same set of samples, the same prompts, and the same output length limit.
- Standardize the billing scope: clarify whether system prompts are counted, whether caching is enabled, and how failed retries are accounted for.
- Standardize the metrics: record cost, time to first token, throughput, task success rate, and manual review cost at the same time.
- Standardize the conversion: use “cost per thousand tasks” and “cost per qualified result” as the final comparison baseline.
Point 4 is the most often overlooked. If a provider has a low unit price but unstable output formatting that requires extra retries and manual fixes, its real cost may be higher. Quality cost must be included in the total.
5. Five Practical Cost-Reduction Techniques
- Prefix stabilization and cache-friendly design: put unchanging system instructions, tool descriptions, and examples at the front and the variable parts at the end, which can significantly raise the cache hit rate.
- Input slimming: remove repeated context and inject snippets on demand via retrieval instead of stuffing in entire documents.
- Output constraints: use structured output with explicit word and field limits to reduce useless generation.
- Tiered model routing: send simple tasks to smaller models and complex tasks to larger models, splitting traffic with rules or a lightweight classifier.
- Observability loop: log the input and output tokens, cache hit status, and cost of every call, aggregate them by business dimension, and build a cost dashboard that supports regression analysis.
Illustrative routing logic:
def route(task):if task.estimated_difficulty < 0.3 and task.max_output < 500:return "small_model"return "large_model"
6. Architecture-Level Recommendations
On cloud platforms such as Baidu AI Cloud, you can keep LLM capabilities in the application layer, use object storage for long documents, use a message queue for peak shaving, use a container platform to host the inference gateway, and use logging and monitoring with alerting for cost observability — turning “billing” from a black box into an attributable, optimizable engineering metric. The key is not picking one provider’s unit price, but making caching, routing, rate limiting, and retries all controllable and measurable.
7. Conclusion
Comparing model API costs should evolve from comparing unit prices to comparing mechanisms: first confirm the pricing dimensions and caching strategy, then benchmark with a standardized workload, and finally include quality and retry costs in the total. For the vast majority of teams, raising the cache hit rate, controlling output length, and implementing tiered model routing deliver far greater savings than hunting for the lowest number on a price list.
