Investing
How To Calculate AI API Costs
A language model bill is two multiplications and a scale factor. The token counts drive the input side and the output side separately, because they are priced differently.
Quick Answer
cost = (prompt tokens / 1M x input price) + (completion tokens / 1M x output price)
- t_in
- Prompt tokens sent, including any system prompt
- t_out
- Completion tokens the model returns
- p_in
- Price per million prompt tokens
- p_out
- Price per million completion tokens
800 prompt tokens and 400 completion tokens at $0.15 and $0.60 per million is $0.00036 a request. At 10,000 requests a month that is $3.60, and $100 buys about 277,778 requests.
What Is AI API Costs?
A language model API is priced per token, which is a fragment of a word rather than a word or a request. Both the prompt sent and the completion returned are counted, and they are counted at different rates.
A token is roughly three quarters of an English word, so a 100-word prompt is around 130 tokens. Pricing per million tokens keeps the quoted figures readable even though individual calls use only hundreds of them.
Output is almost always the more expensive side, commonly two to five times the input price. That is because generating tokens is sequential work while reading them is parallel work.
A request's cost is the sum of two products. Prompt tokens divided by a million times the input price, plus completion tokens divided by a million times the output price.
A system prompt is charged on every request even though it never changes. A 600-token system instruction on 10,000 requests is six million tokens of pure overhead.
The bill scales linearly with volume, so the per-request figure is the only thing worth computing carefully. Once it is known, monthly and annual figures are one multiplication away.
A fixed monthly budget converts into a request count by division, which is the more useful direction when planning. Knowing that $100 buys 277,000 requests is more actionable than knowing a request costs a third of a cent.
Context length is the hidden multiplier. A model with a 128,000-token window can process a whole book in one request, and the prompt side of that request costs 160 times what a 800-token prompt costs.
Retrieval-augmented designs send retrieved passages with every request, so the prompt grows with the knowledge base rather than with the question. The cost is driven by what is retrieved, not by what was asked.
Caching changes the arithmetic where it is offered. A cached prompt prefix is charged at a discount, typically a tenth of the input price, which makes a long unchanging system prompt nearly free after the first call.
Streaming does not change the cost. The price is per token emitted, and streaming only changes when the tokens arrive rather than how many are charged.
Fine-tuned models usually carry a premium on both rates. The training cost is amortised into the per-token price, so a fine-tune only pays back at volume.
Batch and asynchronous endpoints often price at a discount because the provider can schedule the work. The same tokens cost less when the answer is not needed immediately.
The calculator takes a pricing tier, an output multiple, both token counts and a monthly volume, and reports the cost per request, per month, per year and per thousand requests, plus the request count a fixed budget buys.
Formula
cost = (t_in / 1,000,000) x p_in + (t_out / 1,000,000) x p_out
Each token count is divided by a million to convert it into units of the quoted price, then multiplied by that price. The two sides are added because both are billed.
| Symbol | Meaning | Unit | Notes |
|---|---|---|---|
| t_in | Prompt tokens | tokens | Tokens sent with the request. |
| p_in | Input price | currency | Cost per million prompt tokens. |
| t_out | Completion tokens | tokens | Tokens returned by the model. |
| p_out | Output price | currency | Cost per million completion tokens. |
| c | Cost per request | currency | The full cost of one call. |
output price = input price x output multiple
Most providers quote the output rate as a multiple of the input rate. Multiplying by the multiple gives the output price in the same per-million units.
| Symbol | Meaning | Unit | Notes |
|---|---|---|---|
| p_in | Input price | currency | Cost per million prompt tokens. |
| m | Output multiple | multiplier | How many times the input rate output costs. |
| p_out | Output price | currency | Cost per million completion tokens. |
monthly cost = cost per request x requests per month
The per-request cost multiplies linearly by the number of requests, and the annual figure is twelve times the monthly one. Nothing compounds in an API bill.
| Symbol | Meaning | Unit | Notes |
|---|---|---|---|
| c | Cost per request | currency | The full cost of one call. |
| n_m | Requests per month | requests | How many calls are made in a month. |
| C_m | Monthly cost | currency | The bill for the month. |
How To Calculate AI API Costs
- 1
Convert both token counts into millions
Divide the prompt and completion token counts by a million. This converts them into the units the price is quoted in, which is per million tokens rather than per token.
- 2
Multiply by the two prices
Prompt millionths times the input price and completion millionths times the output price. The output multiple converts the input price into the output price first.
- 3
Add the two sides
Both are billed on the same request, so the per-request cost is their sum. On an 800 and 400 token split at $0.15 and $0.60 it is $0.00036.
- 4
Scale by the request volume
Multiply the per-request figure by the monthly request count to get the monthly bill, and by twelve to get the annual figure.
- 5
Divide a budget by the per-request cost
A fixed budget converts into a request count by division. That figure is the one to compare against a product plan when deciding what a feature can afford.
Examples
Example 1: A small classifier at 10,000 requests a month
- Input pricing tier
- $0.15 per million
- Output multiple
- 4
- Prompt tokens
- 800
- Completion tokens
- 400
- Requests per month
- 10,000
| Step | Calculation | Result |
|---|---|---|
| Input price | tier price | 0.15 |
| Output price | $0.15 x 4 | 0.60 |
| Input cost per request | 800 / 1,000,000 x $0.15 | 0.00012 |
| Output cost per request | 400 / 1,000,000 x $0.60 | 0.00024 |
| Cost per request | $0.00012 + $0.00024 | 0.00036 |
| Monthly cost | $0.00036 x 10,000 | 3.60 |
Result: With 800 prompt and 400 completion tokens the per-request cost is $0.00036, split $0.00012 on input and $0.00024 on output. At 10,000 requests a month the bill is $3.60, or $43.20 a year, and $100 buys roughly 277,778 requests.
Example 2: A retrieval assistant with a long context
- Input pricing tier
- $2.50 per million
- Output multiple
- 2
- Prompt tokens
- 12,000
- Completion tokens
- 1,500
- Requests per month
- 4,000
| Step | Calculation | Result |
|---|---|---|
| Input price | tier price | 2.50 |
| Output price | $2.50 x 2 | 5.00 |
| Input cost per request | 12,000 / 1,000,000 x $2.50 | 0.03 |
| Output cost per request | 1,500 / 1,000,000 x $5.00 | 0.0075 |
| Cost per request | $0.03 + $0.0075 | 0.0375 |
| Monthly cost | $0.0375 x 4,000 | 150.00 |
Result: Retrieving twelve thousand tokens of context with every question costs $0.03 on the input side against $0.0075 on the output side, so $0.0375 a request. At 4,000 requests that is $150.00 a month, and 80% of it is the context the retrieval adds.
Calculator
Monthly cost
$3.60
- Cost per request
- 0.00036
- Cost per 1,000 requests
- $0.36
- Input cost per request
- 0.00012
- Output cost per request
- 0.00024
- Annual cost
- $43.20
- Requests per $100 of budget
- 277,777.7778
- Output price per million
- 0.6
Values update as you type. This calculator covers the single scenario its formula assumes — see Common Mistakes for what it leaves out.
Prefer a full-width tool? Open the AI API Costs calculator page.
Common Mistakes
Counting only the completion tokens
The prompt is billed as well, and on retrieval-heavy designs it is the larger half. A design that returns few tokens can still be expensive because of what it reads.
Using the input price for the output side
Output is commonly two to five times the input price, so using one rate for both understates the bill by however large the multiple is.
Forgetting the system prompt in the count
A system prompt is charged on every single request. A 600-token instruction on 10,000 requests is six million tokens of overhead that never changes.
Quoting the price per token instead of per million
Prices are quoted per million tokens. Applying $0.15 to a request rather than to a million tokens overstates the cost by six orders of magnitude.
Assuming the whole context window is free
The window is a maximum, not an allowance. Sending a short question to a long-context model still costs only the tokens actually sent.
Ignoring the available prompt cache discount
Where a provider offers caching, a repeated prefix is charged at roughly a tenth of the input price. Not using it leaves a large discount on the table for a stable system prompt.
Treating the monthly figure as fixed
The bill is linear in volume, so a viral feature doubles the cost. The per-request figure is the one to keep an eye on, because everything else follows from it.
FAQ
How is an AI API priced?
Per token, quoted per million tokens. The prompt sent and the completion returned are billed separately, and the completion rate is usually higher than the prompt rate.
How many tokens is a prompt?
Roughly three quarters of a word in English, so a 100-word prompt is about 130 tokens. Code and non-English text produce more tokens per unit of meaning.
Why is output more expensive than input?
Because generating a token requires a sequential step while reading a prompt can be done in parallel. That asymmetry is built into the hardware cost, so it shows up in the price.
Does streaming change the cost?
No. Streaming changes when the tokens arrive, not how many are charged. The bill is the same whether the answer arrives in one piece or drips out.
How do I lower an AI API bill?
Shorten the prompt, shorten the context that is retrieved with each request, cap the maximum completion length, and use prompt caching for the unchanging prefix. Each of those reduces a different term.
What is the cheapest way to run a simple classification task?
The smallest model that is accurate enough, with a short prompt and a capped output length. Small models differ in price by more than an order of magnitude, so the model choice dominates everything else.
References
- [1]OpenAI, Token pricing documentation — https://platform.openai.com/docs/pricing
- [2]Anthropic, Token counting and pricing — https://docs.anthropic.com/en/docs/build-with-claude/token-counting
- [3]Anthropic, Prompt caching and its discounts — https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching