Skip to content
Guides

How to estimate AI API costs, with a worked example

AI APIs charge per token, not per message. Learn how input and output tokens are priced and estimate your bill with a worked example you can check.

By Hassan Mamoon · · 5 min read
Illustration: How to estimate AI API costs, with a worked example

AI chatbots feel free, or cost one flat fee a month. Build AI into an app, a website or an automation and the pricing changes: you pay for each token that goes in and comes out. That makes the bill easy to underestimate, because it depends on things that are not obvious at the start, like how long your prompts are and how much of a conversation is sent again with every message. This guide shows how to estimate it properly before you build.

Prices, plan names and limits change often, so check your provider's pricing page for current figures. Every price in this article is a made-up example, not a quote.

Which kind of AI pricing are you looking at?

TypeHow you payWho it is for
Free planNothing, with usage limitsAnyone trying a chatbot
Chat subscriptionA flat monthly fee for higher limits and extra featuresPeople who use a chatbot every day
Team or business planA monthly fee per userCompanies that want shared admin and data controls
APIA charge per token used, billed to a developer accountAnyone building AI into an app or automation

A chat subscription and API access are usually billed separately, so paying for one does not normally give you credit for the other. This guide is about the last row.

How API pricing works

An API call has two parts, and each is priced per million tokens:

  • Input tokens are everything you send: your instructions, the user's message, any documents and the earlier messages in the conversation.
  • Output tokens are what the model writes back. They usually cost more per token than input tokens.

The cost of one request is:

  • Cost per request = (input tokens × input price + output tokens × output price) ÷ 1,000,000

Different models from the same provider can be priced very differently, with the larger models costing a lot more per token than the smaller ones. Picking the right model for the job is often the biggest saving. If tokens are new to you, start with What is a token in AI?.

Estimate your bill in five steps

  1. Describe one typical request. What goes in (instructions, user message, any documents) and what comes out (a short answer, a long draft)?
  2. Measure real examples. Paste 5 to 10 real prompts and answers into the Token Counter and average them. This is far more reliable than guessing.
  3. Add the hidden input. Your standing instructions and any retrieved text count on every request, and so does the earlier conversation if you send it again.
  4. Multiply by your volume. Work out requests per day, then multiply by 30 for a month.
  5. Add a safety margin. Real usage is rarely tidy, so budget for more than the estimate, for example 25 to 50% extra, until you have seen a few real bills.

A worked example: a shop's FAQ chatbot

A small online shop adds a chatbot that answers customer questions. Each conversation has 5 questions. The standing instructions are 400 tokens, each customer question is about 100 tokens, and each answer is about 200 tokens. The example prices are $2 per million input tokens and $10 per million output tokens.

The chatbot is sent the earlier messages again each time, so the input grows with every turn:

TurnInput tokensOutput tokens
1500200
2800200
31,100200
41,400200
51,700200
Total5,5001,000

Turn 2 is 400 (instructions) + 300 (the first question and answer) + 100 (the new question) = 800. Each turn adds another 300 tokens of history.

The cost of one conversation:

  • Input: 5,500 × $2 ÷ 1,000,000 = $0.011
  • Output: 1,000 × $10 ÷ 1,000,000 = $0.010
  • Total: $0.021

With 500 conversations a day, that is $10.50 a day and $315 for a 30-day month.

Now see what happens if you forget the conversation history and assume every request is just the instructions plus one question (500 input and 200 output tokens). That gives $0.003 a request, $0.015 a conversation and $225 a month. The real bill is 40% higher than that estimate.

You can check the real figure in the AI Cost Calculator. Enter 1,100 input tokens and 200 output tokens (the averages per request), 2,500 requests a day (500 conversations × 5), and the two example prices. It shows $10.50 per day and $315 per month.

What makes the bill grow

  • Long conversations. The longer the chat, the more history is sent on every turn.
  • Long answers. Output tokens usually cost more than input tokens.
  • Big pasted documents. A large document on every request adds up quickly.
  • A bigger model than you need. Many tasks work well on a smaller, cheaper model.
  • Retries and loops. An automation that retries on every error, or an AI agent that loops, can use many requests before anyone notices.
  • Extras. Images, audio, web search and tool calls may be priced separately.

Keep the bill under control

  1. Pick the smallest model that does the job. Test a smaller one on 20 real examples before you assume you need the biggest.
  2. Cap the answer length. Ask for a limit in the prompt, and set a maximum output length in the API settings.
  3. Trim the history. Send the last few messages plus a short summary instead of the whole conversation.
  4. Check for caching and batch options. Some providers charge less for repeated input or for work that can wait. Read your provider's pricing page.
  5. Set a spending limit. Many providers let you set a budget or an alert in the dashboard. Turn it on before you launch.
  6. Compare your estimate with real usage. Most APIs return the token counts with every response. Log them from day one and check them against your estimate after a week.

Where to go next

Use the Token Counter to measure your own requests, then run the numbers in the AI Cost Calculator. If any of the terms here are new, look them up in the AI Glossary, or see more tools worth trying in 10 free AI tools that save you hours every week.

Keep reading

Get the Weekly AI DigestNew lessons, 5 fresh prompts and the AI news worth knowing, once a week.