LLM API Cost Planning: A Practical Pricing Method
Core idea: a model's advertised token price is only one input. A useful budget also includes request volume, input/output mix, cache behavior, retries, tool loops, and the share of requests routed to each model.
LLM price tables are easy to compare and easy to misuse. A cheaper input-token rate does not guarantee a cheaper workflow: one model may produce longer answers, require more retries, or need more agent steps. Conversely, an expensive model can be economical when it completes a difficult task in one call. This guide provides a reproducible way to estimate cost without pretending the estimate is a guarantee.
Start with a unit-cost equation
For a simple text request, estimate the provider charge as:
request cost =
uncached input tokens × input rate
+ cached input tokens × cache-read rate
+ cache-write tokens × cache-write rate
+ output tokens × output rate
Convert per-million-token prices to per-token prices before multiplying. Then add any provider-specific charges for tools, search, images, audio, storage, batch processing, or long-context tiers. Rates and billing rules change, so store the source URL and verification date with every price in your model registry.
Measure a representative traffic sample
Do not build a budget from one hand-written prompt. Capture a privacy-safe sample of real or realistic requests and record at least:
- input, cached-input, and output token counts;
- model and API endpoint used;
- number of model calls and tool calls per user task;
- retry, timeout, refusal, and fallback rates;
- latency percentiles and whether the task passed evaluation;
- traffic segment, such as interactive, background, or batch.
Use medians for a typical case and high percentiles for capacity planning. Averages can hide a small number of long-context requests that dominate the bill.
Separate request cost from task cost
| Layer | What to count | Why it matters |
|---|---|---|
| Single request | Input, cached input, output, provider features | Useful for API-level comparison |
| Agent step | Planning call, tool result, validation call | A tool loop can multiply requests |
| User task | All steps, retries, and fallbacks until outcome | The fairest unit for product economics |
| Monthly service | Task volume, peaks, free usage, abuse, monitoring | Connects engineering to a budget |
The task should be the main comparison unit. If Model A costs twice as much per call but needs half as many calls and succeeds more often, its cost per accepted result may be lower.
Use scenarios, not a single forecast
Create low, expected, and high cases. Vary traffic, output length, cache-hit rate, retry rate, and model routing. A simple monthly formula is:
monthly model cost =
tasks per month
× average calls per task
× average cost per call
× (1 + retry rate)
Model fallbacks separately rather than blending them into the primary-model rate. Include a contingency for price changes and unexpected long outputs, but do not present that contingency as a provider fee.
Where caching helps—and where it does not
Prompt or context caching can reduce repeated-prefix cost when many requests share a large stable prefix. It is not a universal discount. Some providers distinguish cache writes, reads, retention, and minimum eligible context. A low hit rate or frequently changing prefix can erase the expected benefit. Measure billed cache tokens from usage metadata and compare the full write-plus-read cost with ordinary input cost. See the prompt caching guide for an implementation checklist.
Control output before downgrading quality
Output tokens are often priced differently from input tokens. Before switching models, tighten response formats, set appropriate maximum output limits, stop generating duplicate explanations, and use structured outputs for machine consumers. Do not set limits so low that responses truncate and trigger retries; test completion rates on representative tasks.
Route by task difficulty
A practical system may send extraction, classification, or formatting to a lower-cost model and reserve a more capable model for complex planning or failed cases. Routing creates its own costs: a classifier call, extra latency, and new failure modes. Evaluate the whole route against a single-model baseline. Keep an explicit fallback budget and prevent unbounded escalation loops.
Include costs outside the model API
- Retrieval: embeddings, vector storage, reranking, and document processing.
- Tools: search, browsing, code execution, databases, and third-party APIs.
- Operations: logs, traces, evaluations, rate-limit handling, and on-call work.
- Local inference: hardware amortization, electricity, idle capacity, deployment, and maintenance.
- Quality failures: human review, refunds, support, or incorrect automated actions.
These costs do not need to be forced into a token-price table. Keep them visible in a separate service-cost model.
A defensible comparison workflow
- Define the task and an acceptance test.
- Collect a representative evaluation set without unnecessary personal data.
- Run candidate models with the same tools and constraints.
- Record usage metadata, latency, task success, and retries.
- Calculate cost per accepted task, not only cost per request.
- Stress-test long inputs, tool failures, and traffic peaks.
- Recheck official prices before a procurement or launch decision.
Common estimation errors
- Multiplying a chat message's character count by a fixed token ratio.
- Ignoring system prompts and prior conversation history.
- Assuming every repeated prefix will receive a cache hit.
- Comparing models with different output limits or quality thresholds.
- Ignoring failed requests, retries, and agent loops.
- Publishing a price without a currency, unit, source, or verification date.
A worked, auditable cost example
Illustrative workload—not production telemetry: imagine an internal support assistant handling 12,000 accepted tasks per month. A representative trace suggests 2.4 model calls per task, 6,000 input tokens and 900 output tokens per call, and an 8% retry allowance. Thirty-five percent of input tokens belong to an eligible repeated prefix.
To keep the arithmetic reusable, this example uses hypothetical rates rather than implying a provider quote: $1.50 per million uncached input tokens, $0.15 per million cache-read tokens, and $7.50 per million output tokens. There is no cache-write or storage charge in this simplified example. Replace every rate with the current terms for the exact model and endpoint you use.
| Step | Calculation | Monthly result |
|---|---|---|
| Base calls | 12,000 tasks × 2.4 calls | 28,800 calls |
| Calls including retries | 28,800 × 1.08 | 31,104 calls |
| Total input | 31,104 × 6,000 | 186.624M tokens |
| Cached / uncached input | 35% / 65% of input | 65.3184M / 121.3056M |
| Total output | 31,104 × 900 | 27.9936M tokens |
uncached input = 121.3056 × $1.50 = $181.96
cached input = 65.3184 × $0.15 = $9.80
output = 27.9936 × $7.50 = $209.95
---------------------------------------------
illustrative monthly model cost = $401.71
cost per accepted task = $0.0335
With the same token volume but no cache discount, the estimate is $489.89. The illustrative cache benefit is therefore $88.18, or about 18%. That is not a savings promise: a write charge, retention charge, lower hit rate, or prefix invalidation would change the result.
Sensitivity: agent loops dominate quickly
Keep all other assumptions fixed and vary only calls per accepted task. This isolates the cost of planning, tool, validation, and retry loops.
| Calls per task | Calls including 8% retries | Illustrative monthly cost | Cost per accepted task |
|---|---|---|---|
| 1.4 | 18,144 | $234.33 | $0.0195 |
| 2.4 | 31,104 | $401.71 | $0.0335 |
| 3.8 | 49,248 | $636.04 | $0.0530 |
The model rate did not change, yet the high-loop design costs 2.7 times the low-loop design. This is why request-level unit prices are not enough for an agent product.
Capture evidence in a task-level trace
A forecast becomes auditable when each accepted or rejected task can be reconstructed from privacy-safe usage records. Store provider request identifiers separately from user content, and avoid logging prompts unless there is a documented need and retention policy.
{
"task_type": "support_summary",
"task_result": "accepted",
"model": "provider/model-version",
"calls": 3,
"input_tokens": 18240,
"cached_input_tokens": 6400,
"output_tokens": 2210,
"tool_calls": 1,
"retries": 0,
"latency_ms": 6840,
"price_snapshot": "2026-08-10"
}
Aggregate these records by task type and result. Report median and p90 tokens, calls, latency, and cost per accepted task. Keep rejected and abandoned tasks in the denominator of spend: removing them makes the workflow look cheaper without improving it.
Forecast validation before launch
- Freeze a price snapshot: record model ID, endpoint, region, units, cache terms, long-context tiers, and source URL.
- Replay a representative set: include routine, long-context, tool-failure, and refusal cases.
- Reconcile usage: compare locally recorded tokens with provider usage fields and a small billing export.
- Inspect outliers: find tasks above p95 cost and explain whether length, retries, tools, or routing caused them.
- Set guardrails: cap calls per task, output tokens, retry count, and expensive fallbacks.
- Review weekly after launch: compare forecast and actual cost per accepted task, not only the total invoice.
Use the calculator with explicit assumptions
Our LLM cost calculator uses the currently reviewed public model rates in this site's data file. It is an estimator, not an invoice predictor. Enter realistic input and output sizes, then save your traffic and retry assumptions separately.
Primary references
Bottom line
Budget by accepted user task. Measure real token mix, retries, caching, tool loops, and quality; keep dated primary sources beside every rate; and compare scenarios before committing to a model route.