LLM APIs

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.

4 sections · 4 official screenshots

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

From tokens to a monthly budget
  1. Token cost per callInput tokens × input rate + output tokens × output rate
  2. Monthly token bill× requests ÷ 1,000,000; rates per million tokens in one currency
  3. Retries and agent loopsCount all billed API calls
  4. 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.

DeepSeek pricing table listing model prices per million tokens, with separate lower prices for cache hits.
Screenshot of DeepSeek (2026-10-18). Check the official page for current prices and terms. Open the official page ↗
DeepSeek pricing table listing model prices per million tokens, with separate lower prices for cache hits.
Gemini 4 Argon pricing table showing input, output and context caching rates per million tokens.
Screenshot of Google AI (2026-10-18). Check the official page for current prices and terms. Open the official page ↗
Gemini 4 Argon pricing table showing input, output and context caching rates per million tokens.
Anthropic pricing table for Claude models with input, output, cache write and cache read prices per million tokens.
Screenshot of Anthropic (2026-10-18). Check the official page for current prices and terms. Open the official page ↗
Anthropic pricing table for Claude models with input, output, cache write and cache read prices per million tokens.

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.

Groq pricing page listing per-model token prices.
Screenshot of Groq (2026-10-18). Check the official page for current prices and terms. Open the official page ↗
Groq pricing page listing per-model token prices.

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.

Calculate API costs →

Related services

Listing order is not a recommendation or quality ranking. Confirm plans and terms on the official sites.

LLM APIs →

Official pricing and terms to check

How we check prices and ordering →