· CostMyTokens · Guides · 3 min read

How to estimate your LLM API costs before the bill arrives

The exact formula behind every LLM API bill, a worked example, and the three mistakes that make estimates worthless.

Most LLM API bills are surprises only because nobody did the arithmetic beforehand. The arithmetic is not hard — every provider bills the same way — but there are three places where naive estimates go wrong. Here is the formula, a worked example, and the traps.

The formula

For one API call:

Cost = (input tokens × input price + output tokens × output price + cached input tokens × cached price) ÷ 1,000,000

Multiply by your number of calls per day or month. Prices are quoted per million tokens, which is why the division matters — and why a misplaced decimal makes an estimate off by 10x.

A worked example

Take OpenAI’s GPT-6.1 Sol at $2 input / $10 output per 1M tokens. A support-chat call with 1,000,000 input tokens would be unusual, but scale makes the math visible:

  • 1,000,000 input tokens × $2 = $2.00
  • 500,000 output tokens × $10 = $5.00
  • Per call: $7.00 · At 100 calls a day: $700 a day

Now the same formula at realistic chat scale — 2,000 in / 500 out — gives $0.009 per call. The formula does not change; only the token counts do. That is the whole skill: getting honest token counts.

Mistake 1: Guessing token counts from word counts

A token is not a word. English prose runs roughly 0.75 words per token, code and JSON are denser, and some providers’ tokenizers produce up to 30% more tokens for the same text. Paste a real sample of your prompt and a real sample output into a token counter, using the tokenizer of the provider you will actually call — counts from a different provider’s tokenizer can be off by a fifth.

Mistake 2: Forgetting the invisible tokens

System prompts, tool definitions, retrieved documents and conversation history are all input tokens, on every call. On Gemini models, output price also includes the model’s internal thinking tokens, which you never see in the response. An estimate built only on “what the user typed and what they read” systematically undercounts both ends.

Mistake 3: Pricing the wrong tier

The list price is not always the price you pay. Anthropic and Google halve rates on batch tiers. Prompts that cross a size threshold can jump tiers entirely — Claude Haiku 5.5 bills a prompt over 100K tokens at five times the base rate. And promotional prices expire: Gemini 4 Argon doubles on December 1, 2026. Date your estimate and re-check it when a price changes.

The 10-minute routine

  1. Take 5–10 real requests from logs or a prototype.
  2. Count input and output tokens with the right provider’s tokenizer.
  3. Apply the formula at your expected daily volume.
  4. Add cached and batch effects only if you will genuinely use them.
  5. Re-run the numbers whenever a provider changes prices.

Our homepage calculator does steps 3–4 from verified official prices — every figure is stamped with the date it was last checked.

Share:
Back to Blog

Related Posts

View All Posts »