How to Evaluate and Choose LLM API Pricing
A practical guide to evaluating LLM API pricing beyond the headline per-token rate. It breaks down the real cost formula, explains how input caching, output tokens, and model tiers affect your bill, and shows how context window size and API compatibility influence total cost. You will also find scenario-based selection advice and a simple load-testing approach to validate pricing before committing.
1. Why a Low Unit Price Doesn’t Mean a Low Bill
When evaluating a model service’s price, developers most often make one mistake: fixating on a single number, such as the cost per million output tokens. The real bill is determined by four variables working together: input token volume, output token volume, cache hit ratio, and request repetition. Unit price is only one coefficient among them.
A cost formula that better reflects engineering reality looks like this:
Cost per request ≈ uncached input volume × uncached input unit price+ cached input volume × cached input unit price+ output volume × output unit priceMonthly total cost ≈ cost per request × daily call volume × 30 + retry overhead from failures
The formula makes one thing clear: for long-context and multi-turn conversational applications, the input side usually accounts for the overwhelming majority of tokens, and that is exactly the part that caching can significantly reduce. So any conclusion about whether pricing is high or low, drawn without considering the call pattern, is almost certainly misleading.
2. Breaking the Price into Three Layers
2.1 Input Side: Cache Hits Are the Real Dividing Line
Most mainstream services split input into two tiers, “cache hit” and “cache miss,” with the hit price typically only a fraction of the miss price. The logic behind this design is that when a request’s prefix (system prompt, tool definitions, fixed knowledge snippets) matches previous requests, the server can reuse already-computed intermediate state, saving compute, and passes that benefit on to the caller.
For developers, this means the focus of cost optimization is not compressing prompt length but improving prefix stability: put fixed content first and dynamic content last, and avoid inserting volatile fields such as timestamps or random IDs into a long prefix, otherwise the cache will keep invalidating.
2.2 Output Side: Tied Directly to Business Value
Output tokens cost more to compute than input tokens, so the output unit price is usually several times the uncached input price. Generative tasks (long-form writing, code generation, report summarization) should focus their accounting on the output side, while extraction, classification, and moderation tasks produce very short outputs and are driven mainly by input cost.
2.3 Tier Selection: Lightweight and Flagship Coexist
The same model family often offers a lightweight tier and a flagship tier. The lightweight tier suits high-concurrency, low-complexity, short-output scenarios; the flagship tier suits long-chain reasoning, complex code comprehension, and high-quality generation. Routing simple requests to the flagship tier is a common cause of budget overruns.
3. How Spec Capabilities Affect Cost
Context window size and maximum output length are a form of “capability-based cost.” Million-token context combined with output in the hundreds of thousands can ingest a contract, a code repository, or a long report in a single pass, reducing the number of times you split, summarize, and make multiple round trips. The unit price may not look low, but once you factor in the hidden cost of “chunked processing + multiple calls + result stitching,” a long-context approach is often cheaper.
Keep in mind that ultra-long context is not inherently free: input volume grows linearly with document length, and if an unstable prefix causes cache misses, cost can balloon quickly. In engineering practice, this should be paired with retrieval so that only the truly relevant snippets are sent to the model.
4. The Hidden Value of API Compatibility
When a service is compatible with both of the two mainstream API styles common in the industry (Chat Completions style and Messages style), the marginal cost of migration and load testing is extremely low: the business layer only needs to swap the base URL and API key to run an A/B cost comparison on the same set of prompts. This “replaceability” is itself an economic value. It avoids lock-in to a single vendor and makes it easy to route different tasks to services at different price points.
A schematic abstract client wrapper:
# Unified wrapper that hides differences between API styles, making side-by-side cost comparison easydef call_model(client, system_prompt, user_input, max_tokens):messages = [{"role": "system", "content": system_prompt},{"role": "user", "content": user_input},]resp = client.create(messages=messages, max_tokens=max_tokens)usage = resp.usage # watch prompt_tokens / cached_tokens / completion_tokensreturn resp.text, usage
5. Constraints to Confirm in Advance
- Thinking mode: reasoning-style output enabled by default can significantly increase output tokens, so simple tasks should explicitly disable or downgrade it.
- Completion mode restrictions: code completion capabilities are often available only in non-thinking mode, so routing by scenario at the gateway layer is necessary.
- Rate limits and quotas: high-concurrency scenarios need to evaluate requests per minute and token quotas, and design backoff retries.
- Retry overhead from failures: timeout and rate-limit retries are billed repeatedly and must be counted in the budget.
6. Scenario-Based Selection Advice
- RAG / document Q&A / customer service bots: the prefix is highly repetitive, so prioritize tiers with aggressive cache discounts. Hit rates can usually be kept high, and actual cost is far below the surface unit price.
- Code review and repository-level comprehension: long context is required, so choose a long-window configuration on the lightweight tier and disable thinking mode to control output.
- Random short queries and low-repetition text: caching yields almost no benefit, so choose a lightweight tier with low input and output unit prices and avoid the flagship tier.
- Complex reasoning and high-quality generation: use the flagship tier, and control cost by limiting maximum output length and applying structured output constraints.
7. Putting It into Practice: Load Test First, Then Negotiate Pricing
It is advisable to build a small cost load-testing script that replays real traffic and tracks three metrics: average input length, cache hit rate, and average output length. Once you have the data, you can model the budget, which is more reliable than any official unit price table. If your organization has stable high-volume traffic, you can use this as a basis to discuss tiered pricing and resource packages with the cloud provider. Platforms such as Baidu AI Cloud typically also offer general-purpose monitoring, alerting, and logging services, making it easier to continuously observe and attribute call volume and cost.
