LLM API Pricing Logic and Cost Evaluation Methods
Comparing per-million-token prices is misleading because real bills depend on task structure, context reuse, concurrency peaks, and retries. This article breaks down LLM API pricing into unit pricing, capability output, context capacity, throughput and stability, and migration overhead. It explains sparse activation parameters, input-output cost asymmetry, and the hidden costs of long context, then shows how to estimate total cost of ownership with prefix caching and retry rates, apply tiered model routing, and build a practical checklist for cost observability and interface abstraction.
1. The Core Problem: Why “Unit Price Comparison” Almost Always Leads to the Wrong Conclusion
Whenever a new generation of models is released, the most popular approach in the community is to put the “input price per million tokens” and “output price per million tokens” of different models side by side in a table and rank them by number. The problem with this approach is that it compresses multidimensional engineering constraints into a one-dimensional numerical comparison, while the real bill is determined jointly by task structure, context reuse patterns, peak concurrency, and failure retries.
A more rigorous evaluation framework should cover at least five dimensions: unit pricing (input/output/cache), capability output (the number of tokens required for equivalent quality), context capacity, service throughput and stability, and migration and operations costs. Any conclusion based on only one of these should be treated as a clue rather than a conclusion.
2. Breaking Down the Pricing Structure: Three Frequently Overlooked Variables
2.1 Total Parameters and Activated Parameters Are Not the Same Thing
Modern large-scale models commonly adopt a sparse design, meaning the total parameter count is very large, but each forward pass activates only a small portion of it. The common “total parameters/activated parameters” notation in tables (for example, a ratio on the order of 671B/37B) reflects exactly this. Its impact on cost is indirect but critical: the activated parameter scale determines the compute overhead of a single inference, which in turn affects the vendor’s pricing room; the total parameter scale mainly affects memory footprint and deployment barriers. If you look only at total parameters during evaluation, you can easily overestimate or underestimate the actual cost-performance ratio.
2.2 Input and Output Costs Are Asymmetric
Autoregressive generation means the output stage cannot be highly parallelized the way the input stage can, so the output unit price is usually significantly higher than the input unit price, with a common industry gap of several times. This leads to a practical implication: the task profile matters more than the unit price. Long-document summarization, codebase understanding, and retrieval-augmented question answering are “input-heavy, output-light”; long-form generation and complex reasoning-chain output are “output-heavy.” The bill for the former is sensitive to the input price, while the latter is sensitive to the output price. Using a single mixed ratio to evaluate all scenarios will inevitably distort the conclusion.
2.3 Context Length Is Capacity, Not Free Quota
Increasing context from the 128K level to the 1M level creates value by allowing an entire repository, volume, or log to be fed in at once, reducing chunking and retrieval pipelines. But longer context brings two hidden costs: first, attention overhead grows with length, and long-context requests usually have higher latency and failure rates; second, the phenomenon of “middle information being ignored” still exists, and the position of key information affects recall quality. Therefore, long context should be viewed as “a means to reduce engineering complexity,” not “a resource that can be filled without thinking.”
3. The Correct Cost-Performance Calculation: From Unit Price to Total Cost of Ownership
It is recommended to use a simple estimation script to bring the discussion back from “feels expensive” to “calculable”:
def estimate_cost(input_mtok_price, output_mtok_price,avg_in_tokens, avg_out_tokens, requests,cache_hit_ratio=0.0, retry_rate=0.0):in_tokens = avg_in_tokens * requests * (1 + retry_rate)out_tokens = avg_out_tokens * requests * (1 + retry_rate)cached_in = in_tokens * cache_hit_ratiobilled_in = in_tokens - cached_inreturn (billed_in * input_mtok_price + out_tokens * output_mtok_price) / 1e6
The cache hit ratio and retry rate are the two items most easily missed. In scenarios with stable system prompts, tool definitions, and knowledge base prefixes, prefix caching can significantly reduce repeated input charges; the retry rate directly amplifies all consumption. Once these two items are included in the model, many intuitions of “6x more expensive” will fall back into an acceptable range, and vice versa.
The real decision metric should be “cost per unit of effective output,” meaning the cost required to complete a qualified task (passing evaluation or manual acceptance), rather than the price per million tokens. If a model is more capable and has a higher first-attempt success rate, it consumes fewer tokens and fewer retries, and the total bill may well be lower than a lower-unit-price option.
4. Tiered Selection Strategy: Replace Either-Or with Routing
Mature engineering practice usually does not choose one model, but builds tiered invocation:
- Lightweight tier: handles high-concurrency, short-output tasks such as classification, extraction, format conversion, and intent recognition, pursuing low unit price and low latency;
- Main tier: handles regular question answering, code completion, and document understanding, balancing capability and cost;
- Heavy reasoning tier: enabled only for complex planning, difficult troubleshooting, and long-chain reasoning, triggered by rules or confidence thresholds.
Combined with semantic caching, batching, and asynchronous queues, average costs can be reduced without sacrificing quality. The illustrative logic is as follows:
def route(task):if task.estimated_output_tokens < 200 and task.risk == "low":return "light"if task.requires_long_context or task.risk == "high":return "reasoning"return "main"
5. Supply Constraints: The Real Source of Throughput and Price Cuts
When high-end compute supply is tight, flagship-tier models often adopt limited-service strategies, manifested as strict rate limits, obvious peak queuing, and prices that remain high. This pricing is not purely commercial markup, but a price signal for scarce compute. As new-generation accelerator cards and supernode forms of compute come online in volume, unit compute costs decline, and there is considerable room for price cuts in the flagship tier.
This gives buyers a clear strategy: put price-sensitive, deferrable workloads in the main tier, and make experimental needs that strongly depend on flagship capabilities into switchable capabilities, waiting for supply to ease before scaling up. At the same time, establish usage baselines through monitoring alerts and logging services, and drive scaling decisions with data rather than expectations.
6. If You Want to Implement This on Your Own Platform: A Checklist
- Build a task profile table: record average input/output length, input-to-output ratio, peak concurrency, and acceptable latency;
- Establish an evaluation baseline: use a fixed evaluation set plus manual spot checks as dual criteria to quantify “first-attempt success rate”;
- Enable prefix caching and batching: extract repeated prefixes into stable templates to reduce repeated charges;
- Design a fallback path: automatically switch to a backup tier when the main model is unavailable to avoid business interruption;
- Make costs observable: tag token consumption by business line to form monthly trends and anomaly alerts;
- Abstract the interface layer: uniformly encapsulate model invocations so that changing the underlying tier does not intrude into business code.
In related practices at Baidu AI Cloud, such capabilities are typically implemented by combining general product categories such as model services, container platforms, object storage, message queues, and monitoring alerts, with the same core idea of “abstracted interface + observable cost + tiered routing.”
7. Conclusion
Faced with the price table of a new generation of models, the correct response is not to judge “expensive or not,” but to first confirm three things: Is my task input-heavy or output-heavy? Can my business tolerate queuing and rate limiting? What is my cost per unit of effective output under my evaluation criteria? Once these three points are calculated clearly, price fluctuations turn from a source of anxiety into an operational metric that can be reviewed quarterly.
