AI API pricing in 2026: calculate token usage and your budget
MarkdownAI API pricing with numbers: why output costs more than input, how to estimate tokens for a request and when the cache discount actually cuts the bill.
Read full article
You put money into an API account and almost immediately run into the question: how long will it last? You have something like “I’ve got ten thousand, input costs this much, output costs more, there’s some kind of cache discount too” in your head—and it’s unclear how to turn all that into one number. I’ll break it down in order, with numbers.
The main point up front: an API bill is calculated with one formula—number of tokens multiplied by the price per token. Input and output tokens are counted separately because they have different prices. Next, I’ll show how to use this to work out how long your budget will last and where caching comes into the calculation.
Information about using Ailoot is available in the documentation.
Attention
I’m quoting token prices from the official Anthropic, DeepSeek, and OpenAI pages as of early September 2026—they change, so check your own figures on the provider’s website before calculating. Plug your own numbers into the same formula.
How AI API pricing adds input and output token costs
Takeaway
An API bill has two parts: the charge for input and the charge for output. Input is everything you send to the model: your question, attached files, conversation history, and system instruction. Output is the response the model generated. Both are measured in tokens, and each type of token has its own price. The total for one request is input tokens times the input price, plus output tokens times the output price. Connecting to the API itself costs nothing; you pay only for tokens.
When you call a model through an API, you’re charged for the amount of text that passed through the model. That amount is measured in tokens. A token is a small piece of text; I’ll come back to it in the next section, but for now, think of it as the unit everything is measured in.
A single call has two sides. The first is what you sent to the model: the question itself, attached pieces of code or a document, previous messages in the conversation, and the system instruction at the beginning. This is input. The second is what the model wrote in response. This is output. DeepSeek says it directly in its pricing description: the bill is based on the total number of input and output tokens.
Input and output have different prices, so they’re counted separately. The formula for one request is simple:
cost = (input tokens × input price) + (output tokens × output price)
Prices are usually listed per million tokens—that’s more convenient because a single token costs a fraction of a monetary unit. All the arithmetic from here on revolves around this formula, and your budget covers exactly as many requests as fit within your available funds at that price.
A Token Isn’t a Word: How Can You Estimate How Many You’ll Use?
Takeaway
A token isn’t a word or a letter, but a piece of text that is usually several characters long. A rough estimate for English is about four characters per token, so a five- or six-letter word is one or two tokens. Russian text is split into smaller tokens, so the same phrase in Russian uses noticeably more tokens than in English. You can’t calculate the exact number in advance, but a rough estimate is enough for budgeting: take the approximate number of characters in your request and response, then divide by four for English or by two or three for Russian.
The first thing everyone trips over: a token is not the same as a word. The model splits text into chunks according to its own rules, and a chunk can be a whole short word, part of a longer one, a space with a letter, or a punctuation mark. So you can’t work out exactly in your head “how many tokens my request will take”—you can only estimate.
Here’s a rough guide. In English text, one token corresponds to about four characters; that’s a starting point from Anthropic and OpenAI themselves. Models split Russian text into smaller pieces: Cyrillic is broken into shorter chunks, so the same text in terms of meaning uses more tokens. How many more depends on the model, but you should allow for one and a half to two times as many as in English.
Here’s what that looks like in tokens. If you send the model a page of text and get a paragraph in response, that’s already thousands of input tokens and hundreds of output tokens. And if you attach a large file to a request or carry a long conversation history, input can grow to tens of thousands of tokens, with the lion’s share of the bill coming from that. The API response will show the exact figure—in its metadata fields, it returns how many tokens were actually used for input and output. But for estimating your budget in advance, a rough character-based estimate is enough.
Why Does Output Cost More Than Input, and How Does That Affect Your Bill?
Takeaway
All the major providers charge several times more for output than for input. Claude Opus 5 input costs $5 per million tokens, while output costs $25, five times as much. Claude Sonnet 5 has the same ratio: $2 versus $10. The reason is that generating a response is harder for the model than reading a request. The practical takeaway: a long response hits your bill harder than a long question. The same amount of text costs several times more as output than as input, so it’s cheaper to ask the model for a concise answer. “Explain it in as much detail as possible” directly inflates the most expensive part of the bill.
Here’s a table of official prices per million tokens as of early September 2026—you can see that output costs several times more than input across the board.
| Model | Input, per 1M | Output, per 1M | How much more output costs |
|---|---|---|---|
| Claude Opus 5 | $5 | $25 | 5 times |
| Claude Sonnet 5 | $2 | $10 | 5 times |
| Claude Haiku 4.5 | $1 | $5 | 5 times |
| GPT-5.6-terra | $2 | $12 | 6 times |
| DeepSeek V4 Pro | $0.66 | $1.98 | 3 times |
The price gap between providers is enormous: one million input tokens for Claude Opus 5 costs as much as about 7.58 million for DeepSeek Pro at the table’s input rates ($5 ÷ $0.66 ≈ 7.58). But within each pricing tier, one rule holds: output costs three to six times more than input. The reason is simple: it’s easier for the model to read your request than to write a response, and the more demanding work costs more.
That leads to a conclusion that directly affects your bill. A long response is more expensive than a long question. If you ask the model to “explain it in as much detail as possible,” you’re inflating the most expensive part of the bill yourself. The same meaning packed into a short answer costs several times less. This is one reason vibe coding is cheap for one person but burns through another person’s budget in a day—even with the same model.
How Can You Calculate How Long Your Budget Will Last?
Takeaway
To calculate how long your money will last, estimate the cost of a typical request and divide your budget by that amount. Take the average number of input and output tokens per request, multiply each by its own price, and add them together—that gives you the cost of a request. Then divide your budget by that cost to get the number of requests your money will cover.
Let’s put it all into a step-by-step calculation. Plug in your own prices, typical token volume, and budget.
- Estimate a typical request. Suppose one call uses 20,000 input tokens (the question plus a piece of code and some history) and 2,000 output tokens (the model’s response).
- Calculate input cost: divide the number of input tokens by one million and multiply by your input price per million tokens.
- Calculate output cost: divide the number of output tokens by one million and multiply by your output price per million tokens.
- Add the input and output costs.
- Divide your budget by the resulting cost per request.
Using the Opus 5 rates in this article’s table: 20,000 ÷ 1,000,000 × $5 = $0.10 for input, and 2,000 ÷ 1,000,000 × $25 = $0.05 for output. Total: $0.15 per uncached request. A $10 budget covers 66 whole requests ($9.90), assuming the same token counts and no other charges.
A real request is almost never “average”: attach a large file or stretch out a long conversation, and input grows from 20,000 tokens to 200,000. So calculate based on your usual way of working; an idealized request will give you the wrong answer. It’s also better to round up.
Devin, Claude Code, and any other AI agent use the same API and spend tokens according to the same formula—the only difference is that an agent uses more because it makes many calls behind the scenes. I covered separately why this makes vibe coding cost more than expected in the article about the hidden cost of vibe coding.
What Is the Cache Discount, and When Does It Apply?
Takeaway
Caching is when the model remembers a piece of input it has already read and doesn’t charge full price for processing it again next time. The cache discount applies only to input that repeats from one request to the next: a system instruction, large context, or attached document. Claude’s cache reads cost ten times less than regular input; DeepSeek’s cost more than thirty times less. The discount never applies to output: the model generates the response from scratch every time. One more detail: the first write to the cache costs slightly more than regular input, so savings begin with the second request.
Now for caching—the “up to 80 percent discount” that makes the calculation seem complicated. The mechanics are simple. Some input stays the same from one request to the next: the system instruction at the beginning, a large piece of context, or an attached document you work with over several calls. Caching lets the model avoid rereading that piece from scratch each time and retrieve it from memory at a much lower price.
How much lower depends on the provider. For Claude, rereading from cache costs ten times less than regular input: for Opus 5, regular input is $5 per million, while a cache read is $0.50. DeepSeek’s discount is even steeper: cached input for the flash model costs $0.007 versus $0.22 for regular input, more than thirty times less. So “up to 80 percent off” is a modest estimate; the actual discount can be greater.
Keep two conditions in mind, or your cache calculation will be off.
- The discount applies only to repeated input. The model generates output from scratch each time, and it gets no cache discount at all. If most of your bill comes from long responses, caching will save you very little.
- The first write to the cache costs slightly more than regular input. For short-term storage, Claude charges 1.25 times the regular input price for a cache write. Savings begin with the second request, which reads the piece that was already cached. Caching won’t help at all on a one-off request and will even cost slightly more.
How Do You Recalculate Your Budget to Account for Caching?
Takeaway
To account for caching, split the input into two parts: the repeated part, which is billed at the cache price, and the new part, which is billed at the full price. The rest of the formula stays the same.
Let’s return to the example request volume and add caching. The idea is to split input into two parts: the part that repeats and qualifies for the discount, and the part that is new in each request.
Take the same request with 20,000 input tokens and 2,000 output tokens. Let 15,000 input tokens be unchanged context and 5,000 be fresh. Use the Opus 5 prices already given above: $5 per million fresh input, $0.50 per million cache-read tokens, $6.25 per million short-term cache-write tokens (1.25 × $5), and $25 per million output tokens.
| Request | Input calculation | Output | Total |
|---|---|---|---|
| No cache | 20,000 / 1M × $5 = $0.10 | 2,000 / 1M × $25 = $0.05 | $0.15 |
| First cache write | 15,000 / 1M × $6.25 + 5,000 / 1M × $5 = $0.11875 | $0.05 | $0.16875 |
| Later verified cache hit | 15,000 / 1M × $0.50 + 5,000 / 1M × $5 = $0.0325 | $0.05 | $0.0825 |
The repeated request is 45% cheaper than the uncached $0.15 request, although its cached input portion is 90% cheaper. The first write costs more. Two calls (one write and one hit) cost $0.25125 rather than $0.30. With a $10 budget, one write followed by 119 verified hits gives 120 calls for $9.98625. This assumes the cache remains valid, all calls have these token counts, and no other charges apply; use actual cache-read and cache-write usage rather than assuming every repetition hits.
That gives us the rule: caching is worthwhile when you run one large context through many requests, and useless for scattered, short questions.
Where Do Tokens Get Used Up Without You Noticing?
Takeaway
The biggest hidden expense is a growing conversation history. Each new message carries the entire previous conversation as input, so by the end of a long conversation one request costs several times more than it did at the beginning. The second source is a model’s reasoning mode: hidden reasoning also counts as output tokens, the most expensive kind. The third is large attached files, which are sent in full as input with every request. To keep your budget from draining for nothing, start long conversations over from time to time and keep heavy context cached.
Bills often end up higher than estimated, almost always because of three things you can’t see at a glance.
The first and biggest is conversation history. The model doesn’t remember previous messages by itself; the entire conversation is sent to it again as part of the input every time. This means the tenth message in a long conversation carries all nine previous messages plus their responses. A request costs little at the start of a conversation, but by the end, a question with the same meaning costs several times more because the input has grown. Here’s a simple trick: when the topic changes, start a new conversation. There’s no need to drag one out forever.
The second is reasoning mode. Newer models have a mode where the model first works through its reasoning internally and only then responds. That reasoning also counts as output tokens, and output is the most expensive part. The response looks short, but there are many tokens behind it, so the bill comes as a surprise.
The third is large attachments. Attach a large document or a batch of files to a request, and they’re sent in full as input with every call for as long as they remain in context. If you work with the same document for a while, it’s worth keeping it cached so you don’t keep paying full price for it. Managing what stays in context is a separate skill, called context engineering, and it directly affects your bill.
How Can You Track Spending Without Calculating It Manually?
Takeaway
Every API response returns metadata fields with the exact number of tokens used for input and output, including the cached portion separately. They show the actual cost of a particular request, so there’s no need to estimate anymore. The provider’s account dashboard has a usage page showing daily spending and your remaining balance—check it while you still have money. For control, it’s useful to set a monthly spending limit and turn off automatic top-ups until you’re familiar with your usual usage.
You only need to estimate manually once—to understand how long your money will last in general. After that, you don’t need to calculate it by hand; the API does it for you.
Every model response comes with metadata fields showing the exact number of request tokens: how many went to input, how many to output, how many input tokens were read from cache, and how many were written to it for the first time. Those are exact facts about a particular call, and they show where your budget is really going. If you use a tool like Claude Code, it usually shows usage itself after each task.
There’s also a usage page in the provider’s dashboard, with spending by day and your current balance. Check it from time to time, especially in the first few weeks, until you get a feel for your usual spending pattern. A couple of habits will also help save money: set a monthly spending limit if your provider allows it, and don’t turn on automatic balance top-ups until you understand how much you normally spend. Otherwise, an agent that runs away overnight could charge more than you expected.
Sources
- Anthropic - model pricing - input, output, and cache prices for all Claude models
- Anthropic - prompt caching - how caching works, write and read prices, minimum length
- DeepSeek - models and pricing - usage formula, cache hit and cache miss prices, daytime and nighttime rates
- OpenAI - API pricing - input, cached input, and output prices for GPT models
Get to know Ailoot.
More details
AI API pricing calculation questions
How much is the sample request without caching?
At the article’s Opus 5 rates, 20,000 input tokens cost $0.10 and 2,000 output tokens cost $0.05, totaling $0.15. A $10 budget covers 66 whole calls at that fixed size, before any other charges.
Why is the cache discount smaller for the whole request than for cached input?
Fresh input and output still cost their regular rates. In the example, 15,000 cached input tokens plus 5,000 fresh input and 2,000 output total $0.0825, a 45% saving over $0.15. The first cache write instead costs $0.16875.