Skip to content
Spryhand

How to calculate AI API costs before they surprise you

Output tokens usually cost several times what input tokens do, so the cheapest way to raise a bill is to make the model talk more.

The short answer

Cost per call is input tokens times the input price plus output tokens times the output price, both usually quoted per million. Output is typically priced several times higher than input, so the length of the response drives the bill far more than the length of the prompt.

The formula

cost per call = (input tokens / 1,000,000 x input price) + (output tokens / 1,000,000 x output price)

daily cost = cost per call x calls per day

monthly cost = daily cost x 30 x (1 + retry rate)

Retries are not an edge case. Rate limits, timeouts and validation failures all cause a call to be paid for twice, and a few percent of retries is normal in production.

Worked example

A support ticket summariser at $3 per million input tokens and $15 per million output, averaging 2,400 input and 350 output tokens, running 1,000 times a day with a 4% retry rate:

input = 2,400 / 1,000,000 x 3 = 0.0072

output = 350 / 1,000,000 x 15 = 0.00525

cost per call = 0.01245 → daily = 12.45

monthly = 12.45 x 30 x 1.04 = 388.44

now let the model reason first: output 350 → 900

cost per call = 0.0072 + 0.0135 = 0.0207 → monthly = 645.84

A prompt change that made responses longer raised the bill 66% while the input stayed identical. Nothing about the change looked like a cost decision.

Where the token count is bigger than you think

System prompts are charged on every single call. A 900 token system prompt on a million calls a month is 900 million input tokens, and it is written once and then never thought about again.

Conversation history, in anything chat-shaped, grows the input on every turn. A ten turn conversation can cost several times a single question, and the growth is quadratic rather than linear because each turn resends everything before it.

Retrieved context. A retrieval step that pulls in eight documents to answer a question is paying for eight documents whether or not the answer needed them.

Caching changes the arithmetic more than model choice

Where a provider offers prompt caching, a large repeated system prompt can drop to a fraction of its cost on subsequent calls. On a workload with a long fixed preamble that is frequently the single largest saving available.

It also changes how you should structure the prompt. Stable content first, variable content last, so the cacheable prefix is as long as possible. That is an unusual reason to reorder a prompt and it is a real one.

Set a hard cap rather than an alert

Alerts arrive after the money is gone and are usually read the next morning. A spend cap is annoying exactly once, when it stops something, and that is a much cheaper way to discover a runaway loop than the invoice.

Track cost per unit of output as well as total: per ticket, per document, per generated image. Without it you cannot tell whether a rising bill is a problem or evidence that people are using something you wanted them to use.

What this leaves out

  • Prices are illustrative and change often. The structure of the calculation is stable; the numbers in it are not.
  • Token counts vary by tokeniser and by language. Text in languages with non-Latin scripts frequently costs more tokens for the same content.
  • Excludes fine-tuning, storage and any per-request minimum, which some providers apply.

Common questions

Why is my AI bill higher than my estimate?
Usually output length, retries or conversation history, in that order. Estimates are almost always built from a single clean call, and production has none of those properties.
Is a cheaper model always cheaper overall?
No. A weaker model that needs two attempts, longer prompts or a verification step can cost more than a stronger one that gets it right first time. Compare cost per successful output rather than cost per token.
How do I estimate before building anything?
Run fifty real examples through the intended prompt and measure the actual token counts rather than guessing. Fifty calls costs cents and the estimate it produces is worth more than any published benchmark.

Spreadsheets that do this

The formulas above, already built and checked — so you fill in your numbers rather than the arithmetic.

Related guides

Last reviewed 22 August 2026