all posts

AI API pricing explained: input, output and cached tokens

AI API pricing is a rate per million tokens, split into input, cached input and output. The number to manage is the cost of a finished task, not the cost of a single call.

Guide 13 min read Updated
“Update these contacts from the trade-show list.”
Call 1 input1,162 fresh tokens
Calls on the task6 calls, 9 turns
Per finished taskdivide spend by 1,536

The rates are examples, and live prices change.

How does AI API pricing work?

A live agent has one bill worth explaining. It is the cost of a finished task, and the call inside that task that spent the money.

AI API pricing is the provider’s rate card for a model. The usual unit is a price per million tokens. The card splits that unit into input, cached input and output.

A conversation pays the card once per model call. A task takes several calls. This guide covers the three lines, how a cache changes the bill, one 9-turn CRM attempt, the cost per finished task across 2,400 attempts, where the live rates sit, and when a price line is the wrong tool.

LineWhat it countsWhen it is billed
InputPrompt tokens the provider did not cacheEvery call, at the input rate
Cached inputPrompt tokens reused from an earlier callOn a cache hit, at the cached rate
OutputTokens the model writes, including a tool callEvery call, at the output rate
ReasoningHidden thinking tokens, when a line existsWhen that model’s page lists a rate
BatchThe same tokens, run where waiting is fineWhen the request is sent as a batch

Rates move. Nothing below is a vendor’s current list price. The worked figures use stand-in rates of $1.37 per million fresh input tokens, $0.137 per million cached input tokens and $8.64 per million output tokens. Put the live line in their place before you budget.

How is one model call billed?

A model call sends a prompt and gets a completion back. The prompt is input. The completion is output. If the provider has stored a leading stretch of that prompt, the stretch is cached input. The rest of the prompt is fresh input.

The cost of one call is three products added together. Fresh tokens times the input rate, plus cached tokens times the cached rate, plus output tokens times the output rate. Divide by 1,000,000, because the rate is per million tokens.

A call with 1,162 fresh tokens, no cached tokens and 17 output tokens costs $0.001739 at the stand-in rates. That call is the first one in the CRM attempt below. The same formula prices every later call. Only the three token counts change.

  • System prompt. The instructions. They are input, and they are the usual start of a cache.
  • Tool definitions. On this agent, find_contacts, update_contacts and log_activity. They ride along until the cache holds them.
  • Turns. Each new message from the person, and each earlier reply, sent again on the next call.
  • Tool results. The payload that says 3 contacts were updated and 6 were skipped. That payload is input on the next call. It is not free.

Output is every token the model writes on that call. The person sees some of it. A tool invocation is the rest. “Updating the 9 contacts now” and the update_contacts call are both output. The result that comes back is fresh input on the following call.

The card prices reading and writing differently. You do not need the provider’s reason to use it. You do need to count output on its own. A short reply can cost more than a long prompt that was already cached.

What are cached input tokens?

Cached input tokens are prompt tokens the provider has stored from an earlier call and bills at a lower rate. On an agent, the stored stretch is usually the system prompt, the tool list and the earlier turns of the same attempt.

The first call cannot hit a cache. Nothing has been stored yet. From the second call on, this guide treats every token the provider has already seen as cached. Only the new turn, or the new tool result, is fresh input.

A provider that caches a shorter prefix will charge more. The method does not change. The cached column gets smaller and the fresh column gets larger. Read the columns on the invoice. Do not assume the whole prompt was cached because a cache exists.

A cache miss bills those stored tokens at the full input rate. On the transcript below, the cached column holds 6,411 tokens. Billed at $1.37 instead of $0.137, they add $0.007905. The attempt then costs $0.011601 instead of $0.003696. That is 3.14 times the cached bill. The price line did not change. The cache did.

This is why a single rate per million tokens is a weak estimate of a conversation. The same token is full price on call 1 and a tenth of that price once it sits in the cache. Cached input pricing is a property of the call, not a discount you apply to the whole task.

The stand-in cached rate is a tenth of the fresh rate, $0.137 against $1.37. Live fractions differ by provider and by model. Some cards use a half, some a tenth, some another figure. Take the fraction from the model’s page. Do not reuse this tenth.

How much does one agent conversation cost?

The agent in this guide is the assistant inside a CRM, and the request it gets is “update these contacts from the trade-show list”. The agent clarifies, finds 9 contacts, updates 3, skips the 6 whose emails do not match, and reports the 3 as done. On turn 9 the person comes back for the missing 6. The task stops.

The assistant speaks on turns 2, 4, 6, 7 and 8. It calls the 3 tools. This worked example counts 6 model calls for that attempt. A tool round trip is its own call: one call invokes the tool, the next call reads the result. The token counts are labelled so the arithmetic can be checked. They are not a trace from a live account.

Two rules fix the table. The system prompt and the 3 tool definitions are 1,148 tokens. They sit inside call 1’s 1,162 fresh tokens, which is 1,148 plus 14 tokens for the opening request. Cached input on a later call equals every token already seen: the previous prompt plus the previous output.

CallFresh inputCached inputOutputCost
1. Asks who to update1,162017$0.001739
2. Calls find61,17922$0.000360
3. Says it found 9671,2078$0.000326
4. Calls update41,28228$0.000423
5. Reports 6 skipped961,31419$0.000476
6. Says the 3 were logged471,42913$0.000372

Add the cost column. The attempt costs $0.003696. Fresh input is 1,382 tokens, cached input is 6,411 and output is 107. Added, that is 7,900 tokens billed. Output is a small slice of the tokens and a quarter of the money, because $8.64 is 6.31 times $1.37.

Fresh input is just over half the $0.003696. Most of it is call 1, which has no cache, plus the tool results on calls 3, 5 and 6. Cached input is the rest. It is a large share of the tokens and a smaller share of the money. That is because cached input is billed at a tenth of the fresh rate.

Turn 9 does not add a call. The signal lands after the bill. By the time the person asks where the rest are, the agent has already been paid for all 6 calls. A dissatisfaction signal is evidence about the task. It is not a line on the invoice.

The call formula, with the stand-in rates

def call_cost(fresh, cached, output, p_in, p_cache, p_out):
    return (fresh * p_in + cached * p_cache + output * p_out) / 1_000_000

rates = (1.37, 0.137, 8.64)  # dollars per million tokens, stand-in rates
calls = [
    (1162, 0, 17),
    (6, 1179, 22),
    (67, 1207, 8),
    (4, 1282, 28),
    (96, 1314, 19),
    (47, 1429, 13),
]
print(round(sum(call_cost(*c, *rates) for c in calls), 6))

What is cost per finished task?

It is the bill for the attempts that finished and for the ones that stopped. One stopped attempt is not the number to manage. The same task has 2,400 attempts. 92 stop on find the contacts. 528 stop on update them. 244 stop on log the activity. 1,536 finish. The 92, the 528 and the 244 are 864 stopped attempts, and each of them still cost money.

Price an attempt by the last step it reached. Attempts that stop while finding the contacts pay calls 1 to 3, which add to $0.002425. Attempts that stop while updating pay calls 1 to 5, which add to $0.003324. Attempts that reach the log step pay all 6 calls, which add to $0.003696.

The log row is 1,780 attempts, not 244. It is everyone who reached that step: the 244 who stop there and the 1,536 who finish. This example does not add a seventh call for a finished attempt. Turn 8 already contains the log claim. A live agent that confirms after the log will cost more than this row. Say so when you copy the shape.

Step reachedAttemptsCalls billedOne attempt
find the contacts921 to 3$0.002425
update them5281 to 5$0.003324
log the activity1,7801 to 6$0.003696

Multiply the row. 92 times $0.002425 is $0.2231. 528 times $0.003324 is $1.7551. 1,780 times $0.003696 is $6.5789. The 2,400 attempts cost $8.5571. That is $0.003565 per attempt. Divide the same $8.5571 by 1,536 and the cost per finished task is $0.005571.

Divide by the attempts that finished, not by every attempt. The 864 that stopped were paid and produced no finished task. Using the per-attempt figure as your cost of a result understates the bill by the ratio of 2,400 to 1,536.

The log step holds $6.5789 of the $8.5571, which is 76.88%. The 528 attempts that stop on update them cost $1.7551, which is 20.51%, and they finish nothing. The 92 that stop while finding contacts cost $0.2231, which is 2.61%. An average cost per conversation hides which step spent the money.

abracadabra reads every conversation, names the task in it and points to the step where the attempt stopped. Join the token bill to that step and the $1.7551 has a name. It was spent on update them.

Cost per finished task sits with agent performance. The finish rate says whether the person got the 9 contacts updated. The bill says what you paid for the 1,536 who did, and for the 864 who did not. Keep the two numbers in the same report.

Where can you find today’s model prices?

The stand-in rates exist so you can check the arithmetic. A budget needs the live line for the model your agent calls. Read input, cached input and output as three numbers, each per million tokens, and note the unit before you multiply.

A zero on a price line is a quota, not a promise that production traffic is free. When the quota is spent, the paid line applies. Both the zero and the paid line change. Read them on the model’s page when you send traffic.

Speech and image models often use a different unit. A Whisper-class model is often priced per minute of audio. An image model is often priced per image, sometimes by size. Do not force those units into a per-million text formula. Read the unit, then apply it to the minutes or the images your attempt used.

ProviderUnit to readPage
OpenAIPer million tokens: input, cached input, outputOpenAI API pricing page
Google AI StudioPer million tokens, plus any free quotaGemini API pricing page
GroqText per million tokens. Speech often per minuteGroq pricing page
DeepSeekPer million tokensDeepSeek API pricing page
SambaNovaPer million tokensSambaNova pricing page
Cloudflare Workers AIThe unit printed for that modelCloudflare Workers AI pricing page
fal.aiPer imagefal.ai pricing page

Those pages live in the AI model pricing directory, which is updated as the cards change. Voice models are gathered under voice model pricing. Image models are gathered under image model pricing. If a card on this page and a card in the directory disagree, the directory is the one to budget from.

Claude Managed Agents adds a session charge on top of model tokens. Use that guide for the session price. Price the tokens with the method here, then add the two bills. Neither number is the whole cost of the session on its own.

  1. Export fresh input, cached input and output tokens for every model call on the attempt.
  2. Tag each call with the attempt, and with the step it served: find the contacts, update them, or log the activity.
  3. Multiply by the live input, cached input and output rates for that model, and divide by 1,000,000.
  4. Sum the calls. That sum is the cost of the attempt.
  5. Sum the attempts in the task, then divide by the number that finished.

OpenAI API pricing, Gemini pricing and the other names in the table are searches for a current rate. The directory holds the rate. This page holds the way to turn a rate into a task. Take the rate from the page named in the row, and run the five steps.

What should you watch on a live agent?

A price line tells you the rate. Live traffic tells you whether the rate is doing what you think. Watch five figures, on one task, and read them beside the finish rate. A loop that never stops is the quickest way to a surprise bill, so set step and cost limits.

  • Cache hit rate. The share of prompt tokens billed at the cached rate. A miss on this transcript multiplies the attempt by 3.14.
  • Output share of the bill. 107 output tokens are a quarter of the $0.003696 here, because the output rate is the high one. A longer reply moves the bill faster than a longer prompt.
  • Tool-result size. The 96 fresh tokens on call 5 are the skip payload: 6 emails did not match. A fatter result is fresh once, then cached. Trim it before it is sent, not after.
  • Retries. A second pass shaped like call 5 adds $0.000476 at these stand-in rates. The useful change on this agent is one retry after a lookup by name. Cap it, or the same 528 attempts pay the call again.
  • Shadow traffic. Shadow testing runs a second model pass and throws the reply away. The attempt is paid twice. Sample a share of traffic if the second bill is the thing you cannot afford.

When A/B testing a prompt or a tool description, hold cost per finished task as a guardrail next to the finish rate. A version can finish more of the 2,400 attempts and still be the wrong ship, if it spends twice the output tokens to do it.

Tag the model and the price line on the attempt. A model swap changes every rate in the formula at once. Without the tag, the finish rate and the bill move together and you cannot say which change did which.

Batch is the wrong lever for a reply a person is waiting on. A batch line is the same three rates, lower, for work that can wait. The discount is printed on the model page. Do not memorise it. A live turn uses the live line.

Some models raise the input rate after the prompt passes a threshold printed on the page. Call 1 and call 6 then do not share a rate, even on the same attempt. Check the threshold before you multiply a long transcript by the short-prompt price.

When is the price list not enough?

A price line answers what a token costs at the printed rate, on that model, at that provider. It does not answer whether the person got the contacts updated. Use it for the bill. Use something else for the task.

  • A rate card goes stale. The stand-in rates on this page will be wrong if you treat them as a forecast. They were chosen so the sums can be checked. Open the live page before you commit a number to a forecast.
  • A cache assumption is not a cache hit. This transcript assumes a growing cache: everything already seen is billed at the cached rate. Your provider may cache only the system prompt. Recompute the fresh column from the invoice, not from this table.
  • The token counts are an illustration. 1,162, 96, 47 and the rest are here so a reader can redo the multiplication. A real attempt will differ. Keep the formula. Replace the counts with the ones your gateway logged.
  • The price line cannot see the task. Conversation analytics names the task and the step where it stopped. The invoice names tokens. Joined, they tell you the step was expensive. Apart, the invoice is a total with no cause.
  • Speech and images use other units. Per minute and per image do not go through the per-million text formula. The method of summing the attempt, then dividing by finished tasks, still holds. The line items do not.
  • Two rates can share one model name. A long-context tier, a batch tier and a standard tier are three cards. The request decides which one applied. If you multiply by the wrong card, the error is silent and the total still looks precise.

If you only need the current number for one model, open that model’s page and stop. The method on this page is for the next question: what the task cost, once the rate is known, and which step spent it.

Common questions about AI API pricing

How much does the OpenAI API cost per million tokens?

OpenAI API pricing is three rates per million tokens: input, cached input and output. The figures change, so the live ones belong on the OpenAI page of the pricing directory, not in a guide. One rate is not the cost of a conversation. An agent pays the rate once per model call, and a task takes several calls.

What is cached input pricing?

It is a discounted rate for prompt tokens the provider already holds from an earlier call on the same attempt. Call 1 always pays full price, and a cache miss sends stored tokens back to the full rate. See What are cached input tokens? above for the worked numbers.

How do you calculate the cost of an AI agent conversation?

Multiply each call’s three token counts by their three rates, divide by 1,000,000 and add up every call the attempt made, whether it finished or stopped. To get cost per finished task, divide the total for all attempts by the ones that finished. The five steps under Where can you find today’s model prices? set this out in order.

Why does output cost more than input?

The price card charges a higher rate for tokens the model writes than for tokens it reads. You can use the card without the provider’s reason. You cannot skip the split. In the stand-in rates here, output is $8.64 per million tokens and fresh input is $1.37. At those rates, 107 output tokens are a quarter of a $0.003696 attempt.

Where are current Gemini, Groq, DeepSeek and SambaNova prices?

Current rates for Gemini, Groq, DeepSeek and SambaNova sit on each provider’s page in the AI model pricing directory, and they move. Gemini is under Google AI Studio. Speech models, including Whisper on Groq and Cloudflare, are often priced per minute and are listed with the voice models. Read the unit on the page before you multiply.

all posts

Divide the spend by the tasks that finish.

Abracadabra shows which tasks finish and where the rest stop, so the token bill can be read per finished task.