Cost engineering · Reviewed August 10, 2026

LLM API Cost Planning: A Practical Pricing Method

By AI Agent Hub Editorial Desk · Review method · Corrections

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:

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

LayerWhat to countWhy it matters
Single requestInput, cached input, output, provider featuresUseful for API-level comparison
Agent stepPlanning call, tool result, validation callA tool loop can multiply requests
User taskAll steps, retries, and fallbacks until outcomeThe fairest unit for product economics
Monthly serviceTask volume, peaks, free usage, abuse, monitoringConnects 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

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

  1. Define the task and an acceptance test.
  2. Collect a representative evaluation set without unnecessary personal data.
  3. Run candidate models with the same tools and constraints.
  4. Record usage metadata, latency, task success, and retries.
  5. Calculate cost per accepted task, not only cost per request.
  6. Stress-test long inputs, tool failures, and traffic peaks.
  7. Recheck official prices before a procurement or launch decision.

Common estimation errors

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.

StepCalculationMonthly result
Base calls12,000 tasks × 2.4 calls28,800 calls
Calls including retries28,800 × 1.0831,104 calls
Total input31,104 × 6,000186.624M tokens
Cached / uncached input35% / 65% of input65.3184M / 121.3056M
Total output31,104 × 90027.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 taskCalls including 8% retriesIllustrative monthly costCost per accepted task
1.418,144$234.33$0.0195
2.431,104$401.71$0.0335
3.849,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

  1. Freeze a price snapshot: record model ID, endpoint, region, units, cache terms, long-context tiers, and source URL.
  2. Replay a representative set: include routine, long-context, tool-failure, and refusal cases.
  3. Reconcile usage: compare locally recorded tokens with provider usage fields and a small billing export.
  4. Inspect outliers: find tasks above p95 cost and explain whether length, retries, tools, or routing caused them.
  5. Set guardrails: cap calls per task, output tokens, retry count, and expensive fallbacks.
  6. 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.