How to Calculate AI API Costs
AI pricing guide · updated 2026-08-07
Estimating AI API cost is straightforward arithmetic that most people get wrong in the same four places. The formula takes a line; the accuracy comes from being honest about volume, output length, conversation growth and retries.
The formula
Cost per request = (input tokens ÷ 1,000,000 × input rate) + (output tokens ÷ 1,000,000 × output rate). Multiply by requests per day, then by 30, for a monthly figure.
That is genuinely all of it. Rates are published per million tokens, so the division is the only fiddly part, and one token is roughly four characters or 0.75 words if you need to convert from text you already have.
A worked example
Say a support assistant sends 2,000 input tokens per request (system prompt plus a couple of retrieved articles) and returns 300 output tokens. On a model priced at $2.00 input and $12.00 output per million tokens, that is 0.002 × $2.00 = $0.004 of input, plus 0.0003 × $12.00 = $0.0036 of output. About $0.0076 per request.
At 5,000 requests a day that is $38 a day, or roughly $1,140 a month. Note that output is 47% of the bill despite being 13% of the tokens, the asymmetry doing its work.
Now move the same workload to a model at $0.20 / $1.20 and it costs about $0.0008 per request: roughly $114 a month. Same arithmetic, a tenth of the bill, and for a well-scoped support task the cheaper model may well be sufficient.
The four mistakes
Underestimating output length. People estimate what they hope the model writes, not what it does. Measure it on real traffic rather than assuming, and remember that reasoning models generate billable tokens you never see.
Forgetting that conversations grow. Each turn resends the whole transcript, so turn ten costs far more than turn one. If you are pricing a chat product, model a full session rather than a single exchange.
Ignoring retries and failures. Timeouts, validation failures and agent loops that need a second pass all bill normally. A 10% retry rate is a 10% cost increase that no estimate ever seems to include.
Pricing the happy path only. Evaluation runs, prompt experiments and the traffic your own tests generate all appear on the invoice. During active development these are often larger than production.
Sanity-check against a real bill
Once you are live, divide your actual monthly spend by your request count and compare with your per-request estimate. A gap of more than about 20% means one of the four assumptions above is wrong, and it is usually output length.
Most providers report per-request token usage in the API response, so this reconciliation is a query rather than a research project. Doing it once, early, is worth more than any amount of upfront modelling.
Frequently asked questions
How do I estimate LLM API costs before building?
Write a representative prompt, count its tokens, estimate the output length, then multiply each by the model's respective per-million rate and scale by your expected request volume. Be deliberately pessimistic on output length and add a margin for retries; those are the two places estimates usually fall short.
How many tokens are in a word?
For ordinary English prose, roughly 1.33 tokens per word, so 1,000 tokens is about 750 words. Code, rare words, other languages and heavy punctuation all tokenize into more tokens per word, so count your actual text rather than relying on the average when precision matters.
Why is my AI bill higher than I estimated?
In order of likelihood: output is longer than you assumed, conversation history is being resent on every turn, retries and failed calls are billing normally, or development and evaluation traffic is landing on the same account as production. Divide real spend by real request count and compare with your per-request estimate to find which.
See it in the data
Related guides
Terms used in this guide
Published by Tokenando. Last updated 2026-08-07. Figures in this guide are computed from our own pricing index and dated where they can move; see the methodology and corrections policy.