Blog

How Much Does an AI API Call Cost? Token Billing Explained

How much does an AI API call cost? Input and output tokens are billed separately per million tokens. See a worked example, hidden costs and how to estimate a monthly bill.

If you are building on a model API, the first question is simple: how much does an AI API call cost, and how are tokens billed? The short version is that you pay for the text going in and the text coming out, counted in tokens, at a price set per million tokens. The details decide whether your product makes or loses money on each user.

This post walks through the billing model, a worked example with round numbers, the hidden costs that surprise people, and a way to estimate a monthly bill before you ship.

The short answer: how much does an AI API call cost?

There is no single price. A call costs the number of input tokens times the input rate, plus the number of output tokens times the output rate. Small models cost far less per token than large ones. On the provider pricing page we opened for this post, output tokens cost more per million than input tokens.

For a typical short request, the cost is a fraction of a cent to a few cents. That sounds tiny. It stops being tiny when a product makes thousands of calls a day, or when each call carries a lot of hidden text.

Prices change often and differ by provider and model. Every number in this post is an example chosen to make the math easy. Check your provider's current pricing page before you plan anything.

What is a token and how text becomes tokens

A model does not read letters or whole words. It reads tokens, which are chunks of text. A token can be a whole short word, part of a longer word, a number, or a piece of punctuation. If you want to see why models work this way, our post on how large language models work through next-token prediction covers it.

OpenAI's help page on tokens gives a rule of thumb for English: one token is about four characters, or about three quarters of a word. It calls these rough figures, and so should you. Each model family has its own tokenizer, so the same paragraph can count differently on different models. OpenAI's page also says the same text can give different counts depending on the model, its encoding and the language.

The practical point: you are billed for what the tokenizer counts, not for what you see on screen. Most providers return the token counts in each response, so you can log the real numbers instead of guessing.

How AI APIs bill you: input, output and cached tokens

Most model APIs split a call into parts and price each part separately.

  • Input tokens are everything you send: your instructions, the user's message, any earlier conversation, and any documents you attach.
  • Output tokens are everything the model writes back. These are priced higher per token on the pricing page we opened (Anthropic's), and other providers' pages are worth checking for the same split.
  • Cached input tokens are a discount some providers offer when the start of your prompt repeats from one call to the next. The repeated part is billed at a lower rate; on Anthropic's pricing page, cache hits cost far less per million tokens than base input. Not every provider or model offers this, and the rules differ, so read the docs.

Prices are quoted per million tokens. So 3 dollars per million input tokens means 0.000003 dollars per input token. You almost never think in single tokens. You think in thousands per call and millions per month.

A worked example: pricing a single API call

Say you build a support helper for a small product. Use these invented rates, chosen only to make the math easy:

  • Input: $3 per million tokens
  • Output: $15 per million tokens

One call looks like this:

  • System prompt (your instructions): 500 tokens
  • Retrieved help articles you attach: 1,300 tokens
  • The customer's question: 200 tokens
  • The model's answer: 500 tokens

Input is 500 + 1,300 + 200 = 2,000 tokens. Output is 500 tokens.

  1. Input cost: 2,000 / 1,000,000 x $3 = $0.006
  2. Output cost: 500 / 1,000,000 x $15 = $0.0075
  3. Total: $0.0135 per call
Diagram of one example API call: 2,000 input tokens cost $0.006, 500 output tokens cost $0.0075, total $0.0135
The same example call, with invented rates.

About a cent and a half. Notice that the customer's question is only 200 of the 2,500 tokens. The text you add around it drives most of the bill. Also notice that output is only 20 percent of the tokens but more than half the cost.

Hidden costs that inflate your bill: context, system prompts and retries

Three things catch new builders.

Conversation history is resent every turn

The model has no memory between calls. In a chat, your app sends the earlier messages again each time so the model can follow along. If every turn adds 300 tokens of question and answer, then turn 10 carries about 2,700 tokens of history before the new question. Long chats get more expensive per message, not just in total.

The system prompt is paid for on every call

A long set of instructions feels free because you write it once. It is not free. If it is 500 tokens, you pay for those 500 tokens on every single call. Trim it, or use caching if your provider supports it.

Retries and loops multiply calls

If your code asks the model again whenever the answer fails a check, a bad day can double your cost. Agents that loop through tools make several calls to finish one task, and each call may carry the growing history. Cap the number of retries and steps, and log how many calls each user action triggers.

How to estimate your monthly AI API cost

Do this before you launch, with a spreadsheet or a few lines of code.

  1. Write down the typical input tokens and output tokens for one call. Measure a few real calls rather than guessing.
  2. Compute the cost per call with the formula above.
  3. Count calls per user action, including retries and any extra steps.
  4. Estimate actions per user per month.
  5. Multiply by your expected number of users.

Using the earlier example at $0.0135 per call: 100 users making 10 calls a day is 1,000 calls a day. That is $13.50 a day, or about $405 over 30 days. Now compare that with what those 100 users pay you. If they pay 5 dollars each per month, you earn $500 and spend $405 on the model alone, before hosting or anything else.

That comparison is the heart of unit economics. If the idea is new to you, read what unit economics are, then see how customer lifetime value and churn tell you how much a customer is worth over time. Your model cost per user needs to sit well below that value.

Ways to cut your token spend without hurting quality

  • Use a smaller model for easy jobs. Sorting, extracting and short rewrites often work on a cheaper model. Save the large one for hard tasks.
  • Send less context. Attach only the few passages that matter, not whole documents.
  • Cap output length. Ask for a short answer and set a maximum output size. Output is the expensive side.
  • Shorten history. Summarize older turns, or drop ones that no longer matter.
  • Cache the repeated prefix. If your provider offers cached input pricing, put the stable part of the prompt first so it can be reused.
  • Cap retries and steps. Set hard limits so one bad request cannot run up a bill.
  • Test before you cut. Save a set of example questions and check answers before and after each change, so savings do not quietly hurt quality.

If you are still deciding what to build, keep version one small. Our guide to what an MVP is and how small version one should be pairs well with this. A small first version also keeps your early token bill small while you learn what customers do. Then getting your first 10 customers gives you real usage numbers to plug into the estimate above.

Frequently asked questions

How are tokens billed in an AI API?

You are charged for input tokens and output tokens separately, each at a rate quoted per million tokens. Some providers also discount repeated input through caching.

Why do output tokens cost more than input tokens?

Anthropic's pricing page lists output at a higher rate per million tokens than input. Check your provider's pricing page for the exact rates, since they vary by model.

How many tokens is a word?

For English, a rough rule is that one token is about four characters, or three quarters of a word. The real count depends on the model's tokenizer, so read the token counts returned in the API response.

Why is my API bill higher than I expected?

The usual causes are long system prompts, resending chat history on every turn, large attached documents, and retries or agent loops that make several calls per user action. Log tokens per call to see which one it is.

Get started

AI Entrepreneur is a free web app of short, hands-on lessons. The Intermediate course "The AI Product Stack" includes a lesson called "Model APIs, Tokens and What a Request Costs", and "Pricing AI Products" shows how to price without losing money on every user. Both are part of the 12 courses and 36 lessons, which take about 6 hours in all. They are about doing this math yourself, and they do not promise income or results.

Every lesson is free. Start learning with AI Entrepreneur: sign in on the home page and take your first short lesson today.