Large Language Model API Cost Comparison and Selection: A Practical Guide
This guide explains why comparing per-token list prices alone leads to inaccurate budgets, and how to calculate a blended unit cost that makes different LLM APIs comparable. It covers the four pricing tiers of model services, how to derive cache-hit, input-miss, and output ratios from your own request logs, and how to use P50 and P95 samples to set budget bounds. It also outlines four selection dimensions beyond cost, a tiered routing decision workflow, and six practical cost-optimization levers.
1. Why the Lowest Unit Price Is Often the Most Expensive Choice
When evaluating LLM APIs, many teams simply compare a single price tier, such as the input or output price per million tokens. In engineering practice, this often produces distorted budgets for three reasons:
- Different call structures: Some workloads use long context with short output (codebase Q&A, document review), while others use short input with long output (copywriting, report generation). Their cost structures are entirely different.
- Caching has a large impact: When a request prefix is reused, the cached portion is usually billed at a price significantly below the standard input rate, which can substantially lower the real average cost.
- Time-of-day and tier differences: Some services distinguish peak from off-peak pricing, and some price by context-length bands.
A more rigorous approach is to define a blended unit price: break a typical call into three parts (cached reads, uncached input, output), multiply each by its corresponding price, sum the results, and divide by the total token count to get a single scalar that can be compared across models.
def blended_price(p_read, p_input, p_output, r_hit, r_in, r_out):"""p_read/p_input/p_output: unit price for each of the three token typesr_hit/r_in/r_out: share of each token type in a single call (sums to 1)"""return p_read * r_hit + p_input * r_in + p_output * r_out
Only by fixing the same set of ratio assumptions can the ranking between models be meaningfully compared. This is the premise for all the tiered conclusions below.
2. The Four Cost Tiers
Under a unified measure, model services on the market fall into roughly four tiers (prices are indicative relative magnitudes; refer to the official pages for actual figures):
- Tier 1 (extreme cost-efficiency): Lowest blended unit price range, suited to high-concurrency, low-complexity tasks such as intent recognition, format conversion, and batch summarization.
- Tier 2 (balanced): Roughly several times the price of Tier 1, but more reliable in inference stability and instruction following, making it a sensible default production option.
- Tier 3 (capability-oriented): Prices in the double digits, suited to complex reasoning, multi-step tool calls, and structured extraction from long documents.
- Tier 4 (flagship): Prices can reach more than a hundred times Tier 1, economical only where the cost of errors is extremely high.
The boundaries between tiers are not fixed. Cache hit rates, context-length bands, and time-of-day policies can all place the same model in different tiers for different workloads.
3. Mapping Your Workload to Ratio Parameters
To make the blended unit price actually usable, the key is measuring the three ratios for your own workload. The recommended approach is instrumented sampling:
Suggested log fields:request_id, model, tsprompt_tokens, cached_tokens, completion_tokenslatency_ms, error_code
From these logs you can compute: r_hit = cached_tokens / prompt_tokens, r_in = (prompt_tokens - cached_tokens) / prompt_tokens, and r_out = completion_tokens / (prompt_tokens + completion_tokens). Take P50 and P95 parameter sets over one week to produce conservative and optimistic blended prices for the upper and lower budget bounds.
In practice, services with a stable system prompt and fixed tool descriptions can achieve very high cache hit rates, so the blended unit price ends up clearly lower than an estimate based on full-price input. Conversely, workloads that concatenate large amounts of dynamic context on every request see almost no caching benefit and must be evaluated at full input price.
4. Selection Is Not About Cost Alone
Cost is only one constraint. Evaluate four dimensions alongside it:
- Quality: Run accuracy and format-compliance rates on your own evaluation set (100-300 real samples) rather than relying on public leaderboards.
- Latency: Distinguish time to first token from overall throughput; interactive products are more sensitive to the first token.
- Context capability: Long context changes the ratio structure, so the blended unit price must be recalculated.
- Stability and rate limits: Price and availability fluctuate at peak times and should be absorbed through retry and fallback strategies.
A practical decision workflow: route all traffic to a Tier 1 model first and sample results for human review; route failed samples to a higher-tier model; continuously track the “escalation ratio,” and when it exceeds a threshold (such as 15%), the default model choice is set too low and should be raised across the board.
5. Six Levers for Cost Optimization
- Fix the prompt prefix: Put the invariant part first to improve cache hit rates.
- Constrain output length: Specify word count and structure explicitly; output tokens are usually the most expensive segment.
- Tiered routing: Send simple requests to low-cost models and escalate complex ones.
- Batching and asynchrony: Run offline jobs off-peak to avoid peak pricing.
- Context trimming: In retrieval-augmented scenarios, control the number of retrieved items and snippet length.
- Close the observability loop: Bring token usage, cache hit rate, and per-call cost into monitoring and alerting, integrate with common cloud capabilities such as object storage and log services, and build a cost dashboard.
If the workload runs on a container platform or function-compute service on Baidu AI Cloud, you can land the instrumentation data in object storage and log services, then use scheduled jobs to generate daily reports, achieving cost attribution by model and by business line.
6. Summary
The value of the blended unit price is that it puts cached-read price, uncached input price, and output price on the same ruler, making cross-model comparison and budget planning reproducible. Three things are worth doing immediately: define the ratio measure, sample with instrumentation for one week, and use P50/P95 to compute the upper and lower cost bounds, then layer in quality and latency to finalize the selection.
