Large Language Model API Cost: A Practical Benchmark and Selection Guide
Choosing a large language model API based on price per million tokens is misleading because billing dimensions differ across providers. This guide explains why the cost per successful task is the only comparable metric, how to model prompt caching discounts and multi-round self-consistency, and how to run a reproducible, time-overlapped A/B test on real traffic. It also covers cost governance for batch offline workloads through prefix pinning, structured output, tiered routing, off-peak scheduling, and idempotent retries, plus the observability and budget guardrails needed to keep spending under control.
1. The Real Argument Is Cost per Completed Task, Not Unit Price
Whenever a new model launches, the discussion starts with price: dollars per million input tokens, dollars per million output tokens. Putting those unit prices side by side leads nowhere, because models are not billed along the same dimensions. Some charge separately for input and output, some vary pricing by time of day, some offer significant discounts on cache hits, and some count system prompts, tool call results, and retrieved snippets as input. Poor comparability means a model that looks twice as expensive may produce a bill only a dozen or so percent higher.
The more rigorous metric is the cost per unit of effective output: the cost of completing one task the business will accept, such as a single Q&A, a summary, or a code review. Four variables determine it:
- Input tokens per task, including system prompt, context, and retrieved content;
- Output tokens per task;
- Retries and self-consistency rounds needed to hit the target accuracy;
- The cache hit rate and the discount that actually applies.
Multiply those four together and you get a comparable basis. Ignore any one of them and the comparison is distorted.
2. Model Multi-Round Self-Consistency in the Cost Equation
Some models improve final answer accuracy through multiple samples and cross-validation: generate several candidates for the same question, then pick the best in a judging step. This does improve stability, but token consumption grows roughly linearly. Let the single-round cost be C; n rounds of self-consistency cost about n×C, or (n+1)×C if a final aggregation judgment is included.
Illustrative pseudocode:
def cost_per_task(c_in, c_out, in_tok, out_tok, rounds, cache_ratio, cache_discount):# c_in/c_out: price per million tokensbase = (in_tok * c_in + out_tok * c_out) / 1_000_000effective = base * (1 - cache_ratio * cache_discount) * roundsreturn effective
The key point: cache discounts only apply to reusable prefixes (system prompt, fixed instructions, long documents), while the repeated computation from self-consistency rounds often cannot all hit the cache. So the real gap between “high cache discount plus few rounds” and “low cache discount plus many rounds” is much smaller than the unit price table suggests.
3. A Reproducible A/B Test: One Week of Real Traffic
The most effective way to end a pricing argument is to measure. Run a controlled experiment with overlapping time windows inside the same production environment rather than sequential time slots, because traffic composition and request length distribution drift over time.
Experiment design:
- Fixed dataset: sample 1,000–2,000 real requests covering long context, short Q&A, and structured output;
- Fixed scoring: dual-track grading with rule-based validation (valid format, complete fields) plus a model judge, recording pass rate;
- Record the bill: tally input, output, and cache-hit tokens and cost separately;
- Control variables: keep temperature, max output length, and retry policy identical;
- Report conclusions: give both pass rate and cost per thousand successful tasks.
Illustrative test loop:
for sample in dataset:resp = call_model(sample.prompt, temperature=0.2)ok = validate(resp, sample.gold_schema)metrics["pass" if ok else "fail"] += 1metrics["tokens_in"] += resp.usage.input_tokensmetrics["tokens_out"] += resp.usage.output_tokens
A switch is justified only when cost is lower and pass rate does not drop beyond an agreed threshold (such as 1 percentage point).
4. Cost Governance for Batch Offline Jobs
Take a prompt library case as an example: generating titles, summaries, and tags for hundreds of samples is a typical high-throughput, latency-insensitive workload. Here cost governance matters more than model selection:
- Prefix pinning: put the unchanging system instructions and output spec at the front to raise cache hit rate;
- Output constraints: use structured output or strict templates to compress redundant phrasing and cut output tokens directly;
- Tiered routing: send simple samples to a lightweight model and escalate complex ones to a larger model;
- Off-peak scheduling: run scheduled jobs in discounted billing windows, moving deferrable work to the trough;
- Idempotency and resume: record state per sample so only failed items are rerun.
Illustrative scheduling logic:
def schedule(batch):for item in batch:if item.status == "done":continuemodel = "light" if item.difficulty < 0.5 else "strong"try:item.result = call_model(item.prompt, model=model)item.status = "done"except RateLimitError:enqueue_retry(item, delay=backoff())
5. Observability and Budget Guardrails
Cost overruns are usually not a unit price problem but a missing guardrail problem. Build at least three layers of monitoring: token consumption trend (by day, by business line), cache hit rate, and failure and retry rate. Add hard budget caps and alert thresholds so that when cost per task rises beyond a set percentage period over period, batch jobs are automatically downgraded or paused. General-purpose logging and monitoring alerting capabilities are enough to close this loop; no proprietary interface is required.
6. Conclusion
When facing pricing arguments about a new model, the right approach is: first unify on the cost per successful task, modeling cache discounts and self-consistency rounds together; then run a time-overlapped A/B test and let real bills do the talking; finally, use prefix reuse, structured output, tiered routing, and off-peak scheduling to push cost into an acceptable range. Unit price is only the starting point; engineering capability determines the final bill.
