How to estimate LLM API costs: tokens, retries and caching
Build a monthly API budget from a real workload, and compare cost per successful task instead of a headline token price.
Start with a representative task
Choose 30–100 examples from the work you actually want to automate: a short support reply, a document summary or a code edit. Record billed input tokens, billed output tokens, latency and whether the result passed your acceptance check. Keep system prompts, conversation history and tool responses in the input count.
A million tokens is a billing unit, not a million requests. Two models may tokenize the same text differently. Use each provider’s usage response or tokenizer rather than converting characters into tokens with a fixed ratio.
Calculate the basic monthly bill
- Token cost per callInput tokens × input rate + output tokens × output rate
- Monthly token bill× requests ÷ 1,000,000; rates per million tokens in one currency
- Retries and agent loopsCount all billed API calls
- Separate chargesCache reads, writes, storage and extra features
Add fixed subscriptions separately; compare spending per accepted result.
Monthly token cost = requests × (average input tokens × input price + average output tokens × output price) / 1,000,000. Both prices must be in the same currency per million tokens. For an illustrative workload of 10,000 requests, 2,000 input tokens and 500 output tokens per request, hypothetical rates of $1 input and $4 output give $20 + $20 = $40.
These numbers are a worked example, not a provider quote. Enter the rates from the exact model, tier, region and billing mode you plan to use into the calculator. Add fixed subscriptions separately.



Account for retries and agent loops
Count API calls, not just user actions. An agent that plans, searches, revises and verifies may make several model calls for one task. Failed outputs and retries can still incur charges. If 10% extra calls have the same average token size, the illustrative $40 token bill becomes $44.
Compare total spending divided by accepted results. A lower token rate can lose its advantage if it needs longer prompts or more retries. Set a maximum number of steps and an output-token limit, then check quality before tightening those limits.
Treat caching and extra features separately
Only apply a cached-input discount to tokens that actually qualify. Distinguish cache reads, cache writes and storage duration. Search grounding, images, audio, sandbox execution and reasoning tokens can use other billing units; a text-only calculation does not cover them.
Review a normal month and a traffic-spike scenario. Configure alerts, rate limits and application-side spending controls. Verify whether the provider’s budget setting is an alert or an enforced stop before relying on it.

Your next steps
- Record actual billed tokens and success rate.
- Match model, currency, tier and billing units.
- Budget for retries, tools, cache storage and fixed fees.
Related services
Listing order is not a recommendation or quality ranking. Confirm plans and terms on the official sites.