CCalclabhub

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.

SymbolMeaning
t_inPrompt tokens
p_inInput price
t_outCompletion tokens
p_outOutput price
cCost per request

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.

SymbolMeaning
p_inInput price
mOutput multiple
p_outOutput price

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.

SymbolMeaning
cCost per request
n_mRequests per month
C_mMonthly cost

How To Calculate AI API Costs

  1. 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. 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. 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. 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. 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
StepCalculationResult
Input pricetier price0.15
Output price$0.15 x 40.60
Input cost per request800 / 1,000,000 x $0.150.00012
Output cost per request400 / 1,000,000 x $0.600.00024
Cost per request$0.00012 + $0.000240.00036
Monthly cost$0.00036 x 10,0003.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
StepCalculationResult
Input pricetier price2.50
Output price$2.50 x 25.00
Input cost per request12,000 / 1,000,000 x $2.500.03
Output cost per request1,500 / 1,000,000 x $5.000.0075
Cost per request$0.03 + $0.00750.0375
Monthly cost$0.0375 x 4,000150.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. [1]OpenAI, Token pricing documentation — https://platform.openai.com/docs/pricing
  2. [2]Anthropic, Token counting and pricing — https://docs.anthropic.com/en/docs/build-with-claude/token-counting
  3. [3]Anthropic, Prompt caching and its discounts — https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching