How to Compare Multi-Model API Costs: Methodology and Engineering Practice
Comparing large language model API costs by input price alone often produces conclusions that contradict actual monthly bills. This article presents a practical methodology for building a unified, reproducible cost model across providers, covering input/output asymmetry, caching economics, time-based pricing, batch discounts, context limits, and an estimation framework with pseudocode, monitoring fields, and a decision matrix for model selection.
Why Price Lists Alone Don’t Tell the Real Story
The most common mistake in multi-model API cost comparison is ranking models by “input price per million tokens.” Real bills are shaped by many variables: uncached input tokens, cached input tokens, output tokens, cache writes and storage, batch discounts, time-of-use pricing tiers, request retries, context length, and the distribution of your actual traffic. Ranking on a single field can produce an ordering that is the opposite of your monthly invoice.
Cost comparison should therefore start with a unified methodology: abstract each provider’s official price list into a set of computable fields, then weight them with your real request distribution. The price list is an input of parameters, not the final cost. This article does not list any specific vendor’s prices; instead, it discusses how to convert any platform’s billing rules into a cost model that is comparable, reproducible, and monitorable.
A practical unified formula looks like this:
Cost per request = uncached input cost + cached input cost + output cost + cache storage cost + other billable items, then adjusted by discount rules.
“Other billable items” may include cache writes, long-context surcharges, batch processing flags, and duplicate calls from retries. If a platform bills by request completion time, queuing and generation duration must also be factored into tier determination. Only by breaking these fields apart does cross-model comparison become meaningful.
Input/Output Asymmetry: Output Ratio Drives Effective Pricing
Most model services price output significantly higher than input, yet output-to-input ratios vary widely across workloads. Summarization, classification, and extraction tasks produce short outputs; code generation, long-form writing, and multi-turn dialogue produce proportionally more output tokens. Comparing input prices alone will underestimate output costs.
Define an “input-equivalent cost”:
Effective cost = input price + (output/input ratio × output price).
When the output/input ratio rises from 0.1 to 0.5, the output component rapidly dominates total cost. Before selecting a model, sample your workload to measure three distributions: input tokens, output tokens, and cache hit rate. Without these distributions, any price list supports only rough ranking—never budgeting.
Cache Economics: Beyond the Hit Price
Cache hit pricing is usually below uncached input pricing, but caching is not free. You must also account for cache write costs, storage billed as “token count × residency duration,” cache TTL tiers, and how often caches expire and get rebuilt. If your prefixes are stable and multi-turn sessions repeat heavily, caching can cut costs substantially; if requests are one-off and prefixes vary, write and storage costs can erase the savings.
A simplified break-even check:
Savings from hits ≈ hit rate × (uncached price − cached price)
Extra cost from caching ≈ write cost + storage price × residency duration
Caching only pays off when savings exceed the extra cost. On the engineering side, pay attention to cache granularity: system prompts, tool descriptions, and fixed knowledge snippets make good stable prefixes; dynamically assembled content should be placed as late in the prompt as possible to avoid breaking prefix stability. A higher hit rate is not always better—the goal is balancing hit savings, storage cost, and invalidation risk.
Time-Based Pricing: Completion Time Changes Scheduling Strategy
Some platforms apply peak/off-peak pricing based on when a request completes. This means a long-context, long-output, or heavily queued request may start during an off-peak window but finish in a peak tier. Cost optimization cannot focus only on when requests are sent—it must also consider when they complete.
In practice, classify workloads into three categories: real-time interactive tasks, near-real-time tasks, and offline batch tasks. Real-time tasks prioritize latency; near-real-time tasks can set a latest acceptable completion time and be scheduled within off-peak windows; offline batch tasks can be deferred to off-peak hours. You also need to handle holidays, weekends, time zones, and local holiday rules—don’t assume “weekends are fully off-peak” applies everywhere.
If a request may straddle tiers, estimate its budget conservatively at the higher tier, and log the start time, completion time, tier, and retry count. Otherwise, monthly bills will show the puzzling pattern of “same unit price, higher cost.”
Batch and Cache Discounts: Verify Whether They Stack
Batch discounts typically serve high-throughput offline scenarios; cache discounts serve repeated-prefix scenarios. The key point: some platforms’ billing rules make batch and cache discounts mutually exclusive—they cannot simply be multiplied together. When modeling costs, compute the effective cost of a “batch plan” and a “cache plan” separately, then pick the better one, rather than assuming discounts stack.
Express both candidates:
Plan A cost = base cost × batch discount
Plan B cost = uncached input × uncached price + cached input × cached price + output × output price + cache storage
With a high cache hit rate, the cache plan may beat batching; with a low hit rate and deferrable tasks, batching may win. Also factor in the queuing latency, failure retries, and result retrieval costs that batching introduces. Under mutual-exclusion rules, “compute which is cheaper” matters more than “assume they stack.”
Context Limits and Request Splitting: Long Context Isn’t Free Expansion
Model services impose a per-request context limit. Near the limit, common approaches are splitting requests, summarization-based compression, retrieval augmentation, or segmented processing. Splitting may duplicate system prompts and fixed instructions, inflating input tokens; merging may pull in irrelevant content, increasing output noise and cost. The right trade-off depends on the task.
Concrete cost-control tactics include: compressing system prompts, removing redundant examples, retrieving on demand instead of concatenating everything, capping output length, using structured output to reduce verbosity, and summarizing long documents in segments before aggregation. For multi-turn dialogue, periodically compress history and retain key state rather than replaying everything. Context length is both a capability boundary and a cost boundary.
A Reusable Estimation Model with Pseudocode
Below is a platform-agnostic estimation pseudocode. Fill in the price parameters from any official price list; the values represent field structure only, not any real product’s pricing.
function estimate_cost(request, price):cached_in = request.input_tokens * request.cache_hit_rateuncached_in = request.input_tokens - cached_inbase = uncached_in * price.input_uncached+ cached_in * price.input_cached+ request.output_tokens * price.outputif request.is_batch:base = base * price.batch_discountstorage = request.cache_storage_tokens* request.cache_hours* price.storage_per_token_hourretry = base * request.expected_retry_ratereturn (base + storage + retry) / 1000000
When using this model, output three business metrics alongside the estimate: cost per thousand requests, cost per task, and cost per ten thousand characters processed. Comparable units differ across workloads; only after normalizing to business metrics can you compare across models. For platforms where batch and cache discounts are mutually exclusive, treat is_batch and cache hits as two independent scenarios and estimate each separately—never multiply the two discounts.
Monitoring and Governance: Making Cost an Observable Field
Cost optimization cannot stop at model selection. Record these fields in your invocation logs: model identifier, uncached input tokens, cached input tokens, output tokens, cache storage tokens and duration, request start time, completion time, pricing tier, batch flag, retry count, and business task identifier. Use these fields to build budget alerts, unit-cost trends, cache hit rate trends, and anomaly detection.
When deploying on a general-purpose model service platform such as Baidu AI Cloud, inference usage, logs, and alerts can be collected under a unified field schema, forming a closed loop of “unit price → usage → business metrics.” Governance actions include monthly reviews of price changes, cost allocation by business line, peak budget caps, degrading or cache-enabling high-cost tasks, and cleaning up low-hit-rate caches. The goal of cost governance is not to minimize unit price, but to keep the cost per unit of business output controllable and explainable.
A Selection Decision Matrix: Cost Is Only One Dimension
Final model selection should use a weighted matrix: quality fit, latency, reliability, cost, compliance and data governance, engineering effort, and ecosystem compatibility. Cost should be evaluated on a monthly budget basis, not a unit-price basis, and should include migration costs, cache management, retries, and operational overhead. Start with a small-scale canary rollout, replay the cost model against real request distributions, then scale up gradually.
The conclusion: multi-model API cost comparison should be treated as an engineering problem of “billing fields + traffic distributions + scheduling strategy + governance loop.” First unify the methodology, then break down caching, time-based pricing, batching, and context variables, and finally calibrate continuously with monitoring data. Only then can you avoid being misled by price lists and make selection decisions that are reproducible, auditable, and sustainable.
