LLM API Cost Estimation and Selection: A Practical Guide
This article presents a reusable framework for estimating large language model API costs and comparing candidates under a unified methodology. Instead of comparing specific vendors or models, it abstracts three typical pricing structures, defines consistent billing assumptions, and models token usage across three business scenarios: customer support replies, batch content generation, and long-document analysis. Readers will learn why the lowest per-token price does not always produce the lowest bill, how time-of-day pricing, input-length tiers, caching, batch processing, and reasoning mode affect the final ranking, and how to build a reproducible budget table. It also includes a practical checklist for reducing costs without sacrificing quality.
1. Why the Lowest Unit Price Is Often Not the Lowest Bill
When teams integrate LLM APIs for customer support replies, batch content generation, or long-document analysis, the most common mistake is focusing on a single number: the price per million tokens. The actual bill is determined by several variables working together, including:
- The ratio of input to output tokens
- Whether reasoning (thinking) mode is enabled
- Whether a single request’s input length crosses a pricing tier
- Whether the call falls in a peak or off-peak period
- Whether a cache hit occurs
- Whether batch or asynchronous endpoints are used
- Extra consumption caused by failed-request retries
A change in any one of these variables can reverse the ranking of candidates.
For this reason, this article does not compare any specific vendor or model. Instead, it abstracts a general model of “three candidate APIs” and performs the estimation under a unified methodology, helping readers build a reusable cost evaluation framework.
2. Set the Rules First: A Unified Estimation Methodology
Without a consistent methodology, conclusions are meaningless. It is recommended to fix the following assumptions during the budgeting stage:
- The unit is CNY per million tokens, with input and output priced separately.
- Output tokens are billed as the combined total of the reasoning process and the final answer.
- All candidates are compared under the same mode (reasoning enabled) to isolate mode differences.
- Assume no cache hits and use standard synchronous calls.
- Do not use batch processing, free quotas, or promotional discounts.
- Do not call extra tools such as web search or optical character recognition (OCR).
- Count only one request per task; do not include retries or manual fallback costs.
It is important to emphasize that fixing token usage is only a means of isolating the price factor. It does not imply that different models have the same tokenization, reasoning depth, or task completion rate. Real-world selection must layer in quality dimensions.
Illustrative methodology configuration (pseudocode):
billing_assumptions:unit: CNY_per_million_tokensoutput_counts_reasoning: truemode: thinking_oncache_hit: falsebatch: falsefree_quota: falseextra_tools: falseretries: 0
3. Usage Settings for Three Business Scenarios
To keep the estimation close to real workloads, define three scenarios (the values are calculation assumptions, not measured consumption):
- Customer support replies: about 1.2k input tokens and 0.3k output tokens per request, 30,000 requests per day.
- Batch content generation: about 0.8k input tokens and 1.5k output tokens per request, 10,000 requests per day.
- Long-document analysis: about 200k input tokens and 2k output tokens per request, 200 requests per day.
Converted to monthly token volume:
- Customer support: about 1,080 million input tokens and 270 million output tokens.
- Content generation: about 240 million input tokens and 450 million output tokens.
- Long-document analysis: about 1,200 million input tokens and 12 million output tokens.
4. Modeling the Price Structure: Write Conditions into the Formula
The pricing structures of the candidate APIs can be abstracted into three typical forms:
- Form A: A single input price, but differentiated by time period (two sets of prices for peak and off-peak).
- Form B: The input price is tiered by the input length of a single request (whether it exceeds a certain length threshold), while the output price is fixed.
- Form C: Both input and output have a single price, but there are differentiated rules for cache writes and cache hits (the cache write price is usually the same as the corresponding input price and is not added on top of it).
Unified cost formula:
Cost = InputTokens/1e6 * P_in(condition) + OutputTokens/1e6 * P_out
Here, P_in(condition) is the conditional input price. The conditions include time period, single-request input length tier, and whether a cache hit occurs.
Illustrative implementation:
def cost(input_tokens, output_tokens, p_in, p_out):return input_tokens / 1e6 * p_in + output_tokens / 1e6 * p_out# Form B: select the tier by single-request input lengthdef p_in_tiered(single_input_tokens, tiers):for limit, price in tiers:if single_input_tokens <= limit:return pricereturn tiers[-1][1]
5. Plugging In the Numbers and Interpreting the Results
Under the unified assumptions of no caching, no batching, and no discounts, plugging the usage above into the three forms yields the following structural conclusions (for illustrating the method only, not pointing to any real product):
- Off-peak periods: Form A is the cheapest for the content generation scenario, where output takes a high share, because its single input price is amortized.
- Peak periods: After Form A’s input price doubles, short-input scenarios (customer support) are overtaken by Form B.
- Long-document scenario: Regardless of peak or off-peak, input volume dominates absolutely, so the lowest input unit price always wins.
- Form C, under this article’s assumptions (no cache hits), can only lead when the input share is extremely high and the unit price is low enough; overall it stays at the high end.
Key takeaway: The ranking is not global. It is a function of “scenario × time period × input length.” Any “lowest price” conclusion detached from conditions does not hold.
6. A Reproducible Budget Table Structure
It is recommended to fix the budget table with the following fields for easier review and verification:
| Scenario | Daily Calls | Input per Call | Output per Call | Peak Ratio | Input Price | Output Price | Monthly Cost |
|---|---|---|---|---|---|---|---|
| Customer support | 30000 | 1200 | 300 | 30% peak | Conditional | Fixed | Computed |
| Content | 10000 | 800 | 1500 | Mostly off-peak | Fixed | Fixed | Computed |
| Long document | 200 | 200000 | 2000 | Any | Tiered | Fixed | Computed |
Verification script skeleton:
scenarios = [{"name": "customer_support", "calls": 30000, "in": 1200, "out": 300, "peak_ratio": 0.3},{"name": "content", "calls": 10000, "in": 800, "out": 1500, "peak_ratio": 0.1},{"name": "long_document", "calls": 200, "in": 200000, "out": 2000, "peak_ratio": 0.5},]# For each candidate form, plug in p_in(condition) and p_out and sum them up
7. Optimization Checklist: Cutting Costs Without Sacrificing Quality
- Time-of-day scheduling: Move deferrable batch jobs to off-peak periods and keep only real-time paths during peak hours.
- Input slimming: In retrieval-augmented scenarios, compress context, deduplicate, and pre-summarize to directly reduce input tokens.
- Tier avoidance: Trim or split requests that are close to a length threshold to avoid a unit price jump caused by crossing a tier.
- Caching strategy: Design stable prefixes for high-frequency repeated content to improve cache hit probability (note the difference between cache write rules and hit prices).
- Batch and asynchronous processing: Route offline tasks through asynchronous or batch channels first, which are usually significantly cheaper than synchronous real-time prices.
- Mode tiering: Disable reasoning mode for simple intent recognition and enable it only for complex reasoning, avoiding output inflation from “reasoning on everything.”
- Quality guardrails: Build a small-sample evaluation set, monitor completion rate and manual fallback rate, and factor rework costs into the total cost.
8. Conclusion
LLM API cost evaluation should be treated as a conditional modeling problem, not a unit price comparison. The unified methodology, three-form price model, scenario-based usage, and budget table structure provided in this article can be directly applied to the evaluation of any candidate API. To implement this on Baidu AI Cloud, you can combine general capabilities such as object storage, message queues, container platforms, log services, and monitoring alerts to build a closed loop of “task scheduling - invocation - metering - alerting,” enabling continuous observability and optimization of costs.
