Skip to content
Advertisement
Tutorials

LLM API Cost Estimation: Price a Feature Before You Build

AI Tools Tutorial Team15 min readDocumentation and user reports

Pricing and features verified August 2026

Photograph of bank finance

Photo by Artsy Crafty via stocksnap (CC0)

Cost per request equals input tokens times the input rate, plus output tokens times the output rate. The arithmetic is trivial. The hard part is deriving token counts for a feature that does not exist yet, and the answer is that prompt length, not traffic, sets your bill. Measure one representative request with a token counter, price it against published rates, then multiply by volume.

Key takeaways

  • Cost is set by the shape of one request. A 17x difference in prompt length between two designs of the same feature swamps a 2x difference in traffic
  • Output is priced above input everywhere checked, but the ratio is model-specific: 5x on Claude Opus 5, 6x on gpt-5.6-sol, 8x on gpt-5, 2x on deepseek-v4-flash
  • Caching reprices a repeated prefix at a tenth of base input on Anthropic, OpenAI and Gemini; batching takes a flat 50% off at Anthropic, OpenAI, Google and Mistral
  • Retries re-send the whole prompt, and Anthropic SDKs already retried twice before your error handler saw anything
  • Long context is provider-specific — Gemini 2.5 Pro doubles its input rate above 200k tokens, while Claude 4.6 and later bill 1M-token context at standard rates
  • Chat history makes cost quadratic: turn 20 resends turns 1 through 19, so a 20-turn conversation bills about 4x the naive per-turn estimate

The formula is the easy part#

The formula never changes. Input tokens divided by 1,000,000, multiplied by the input rate, plus output tokens divided by 1,000,000, multiplied by the output rate. Everything difficult happens before that line.

What sets the number is a design decision: how much text you put in front of the model on every call. Get that wrong and no amount of traffic modeling saves the forecast.

Advertisement

Tokens are the billing unit, and eyeballing them does not work#

Anthropic's pricing page gives a rough estimate of one token to about four characters, or 0.75 words in English. That is a sanity check, not a budgeting method, and the docs present it as approximate.

Two things break the estimate immediately. Tool definitions cost far more than they look: Anthropic's token counting docs show a short system prompt plus the message "Hello, Claude" at 14 input tokens, and the same message with one weather tool defined at 403. Attachments cost more again — one image measures 1,028 tokens and a PDF 2,188 in the same docs.

Model choice also changes the count for identical text. Anthropic states that Claude 4.7 and later use a newer tokenizer producing approximately 30% more tokens for the same input.

Anthropic token counting endpoint

Best for: Measuring the exact input size of a prompt, including tools, images and PDFs, before you ship it

Pricing
Free to use, with separate rate limits from message creation

POST to /v1/messages/count_tokens with the same structured payload you would send to create a message, and it returns an input_tokens count under that model's tokenizer. Two limits matter. The docs call the count an estimate that may differ from real usage by a small amount, and it applies no caching logic, because caching only occurs during real message creation.

Prompt length multiplies, request volume only adds#

Traffic is the number everyone forecasts and the one that matters least. Doubling requests doubles cost once. Prompt length multiplies against every request you will ever serve.

Take one feature, two designs. Design A pastes a 24,000-token policy handbook into every request; Design B retrieves an 800-token excerpt. Both handle a 600-token ticket and return 150 tokens of structured output.

On Claude Haiku 4.5 at $1 per million input and $5 per million output (checked August 2026), Design A costs $0.02535 per request and Design B costs $0.00215. At 5,000 requests a day that is $3,802.50 a month against $322.50. Doubling Design B's traffic adds $322.50, so the design choice is worth ten times the traffic decision. Stuffing context versus retrieving it is covered in the RAG versus fine-tuning guide.

Advertisement

Published per-token prices, checked August 2026#

Published list rates per 1M tokens, checked August 2026. Cached-input column shows each provider's published cache-hit price.
ModelInputOutputCached inputOutput:input
Claude Opus 5$5.00$25.00$0.505x
Claude Sonnet 5 (introductory)$2.00$10.00$0.205x
Claude Haiku 4.5$1.00$5.00$0.105x
gpt-5.6-sol$5.00$30.00$0.506x
gpt-5.6-terra$2.00$12.00$0.206x
gpt-5.6-luna$0.20$1.20$0.026x
gpt-5$1.25$10.00$0.1258x
Gemini 3.6 Flash$1.50$7.50$0.15 plus $1.00/1M per hour storage5x
Gemini 2.5 Flash-Lite$0.10$0.40$0.014x
deepseek-v4-flash$0.14 on cache miss$0.28$0.00282x
Mistral Large$2.00$6.00not published3x
Published list rates per 1M tokens, checked August 2026. Cached-input column shows each provider's published cache-hit price.

Two rows carry announced increases you must model. Claude Sonnet 5's $2 and $10 rate is introductory through August 31, 2026; standard pricing of $3 and $15 takes effect September 1, 2026, a 50% increase on both sides. DeepSeek's pricing documentation warns that overall API pricing is planned to rise in the near future, with a significant increase expected, but names no date. Mistral's pricing page publishes the Mistral Large figures and the batch discount, and directs you to the models overview docs for everything else.

Worked example: a support-ticket triage feature#

Design B from above, line by line, at 5,000 tickets a day on Claude Haiku 4.5.

Input is 800 tokens of instructions and taxonomy plus a 600-token ticket, so 1,400 tokens. That bills at 1,400 divided by 1,000,000, times $1, which is $0.0014. Output is 150 tokens at $5 per million, or $0.00075. Per request: $0.00215. Daily: 5,000 times $0.00215, or $10.75. Monthly at 30 days: $322.50.

Now apply the levers. Batch processing halves both sides to $161.25 a month. Caching does not apply at all, because Claude Haiku 4.5 requires a 4,096-token minimum and this prompt is 1,400.

Design A, the 24,000-token version, does clear that minimum. Cached, it bills 24,000 tokens at the $0.10 cache-hit rate ($0.0024), plus 600 uncached input tokens ($0.0006), plus output ($0.00075) — $0.00375 per request. Add one 5-minute cache write every five minutes all day, 288 writes at $0.03 each, and the month lands near $822. Caching cut Design A by roughly 78%, and it still costs 2.5x the uncached Design B.

Advertisement

Prompt caching: pay a premium once, read at a tenth#

Anthropic prices cache operations as multipliers on base input: a 5-minute cache write is 1.25x, a 1-hour write is 2x, and a cache read is 0.1x. The docs state the break-even directly — caching pays off after one cache read for the 5-minute duration, or after two cache reads for the 1-hour duration.

OpenAI publishes cached input at 10 percent of standard input on its gpt-5.x models ($5.00 to $0.50 on gpt-5.6-sol). For GPT-5.6 and later, cache writes cost 1.25x the uncached input rate and prefixes must reach at least 1,024 tokens, described in the guide as a strict minimum; earlier models carry no write fee and their minimum ranges from 1,024 to 2,048 tokens.

Google adds a dimension the others do not have: context caching costs $0.15 per million tokens on Gemini 3.6 Flash and 3.5 Flash, plus a storage charge of $1.00 per million tokens per hour. Implicit caching is on by default for Gemini 2.5 and newer, with activation thresholds of 4,096 tokens on Gemini 3.5 Flash and 2,048 on Gemini 2.5 Flash and 2.5 Pro. The Interactions API supports implicit caching only.

Caching also buys throughput. Anthropic's rate-limit docs state that for most Claude models only uncached input tokens count toward the input-tokens-per-minute limit: a 2,000,000 ITPM limit at an 80% cache hit rate effectively processes 10,000,000 input tokens per minute.

Batch discounts: 50% off, if 24 hours is acceptable#

What works

  • A flat 50% discount on input and output at Anthropic, OpenAI, Google and Mistral as published in August 2026
  • Anthropic reports most batches finishing in under an hour despite the 24-hour ceiling
  • Expired, errored and canceled Anthropic batch requests are not billed at all
  • Anthropic batch and cache discounts combine, with the multipliers stacking

What does not

  • Anthropic batches expire if processing does not complete within 24 hours, so nothing interactive can use them
  • Anthropic warns that concurrent batch processing may push spend slightly over a workspace spend limit
  • Cache pre-warming with max_tokens set to 0 is unsupported inside an Anthropic batch
  • OpenAI caps a batch at 50,000 requests, a 200 MB input file, and 2,000 batches per hour
  • OpenAI batch output files are deleted automatically 30 days after completion, and cancellation can take up to 10 minutes
Advertisement

Estimate-blower 1: retries you already paid for#

Anthropic's error docs state that the official SDKs automatically retry transient failures — connection errors, rate limits, 5xx errors — with exponential backoff, twice by default, honoring the retry-after header. A request that fails twice before succeeding sent your full prompt three times.

The retryable list is not exotic: 429 rate limit, 500 api error, 504 timeout and 529 overloaded. The docs note 529s can occur when the API sees high traffic across all users, and that sharp usage increases trigger 429s from acceleration limits — hence the advice to ramp traffic gradually.

Two more traps. Streaming errors can arrive after a 200 response, so they sit outside standard error handling. And Anthropic's monthly spend caps by tier — $500 on Start, $1,000 on Build, $200,000 on Scale — set the ceiling a runaway retry loop can reach. Retry design is covered in the automation error handling guide.

Estimate-blower 2: long context, where the rate itself can change#

Whether long context costs more per token is a provider-specific question with no universal answer.

Gemini 2.5 Pro tiers its rate by prompt length: input is $1.25 per million for prompts up to 200k tokens and $2.50 above that, with output moving from $10.00 to $15.00. Cross the threshold and the rate doubles on input.

Anthropic goes the other way. The pricing page states Claude 4.6 and later include the full 1M token context window at standard pricing, and spells out that a 900k-token request bills at the same per-token rate as a 9k-token request.

Filling that window is easy. Anthropic's docs put an average 10 kB web page near 2,500 tokens and a 500 kB research paper PDF near 125,000. One PDF in the prompt is a bigger cost event than a thousand short requests.

Advertisement

Estimate-blower 3: chat history turns cost quadratic#

A chat feature resends the entire conversation on every turn, so per-turn cost is not constant. That single fact breaks most estimates.

Model a conversation with a 1,000-token system prompt, a 150-token user message and a 250-token assistant reply per turn. Turn 1 bills 1,150 input tokens. Turn 20 bills 1,000 plus 400 times 19 plus 150, which is 8,750 — 7.6x turn 1. Across all 20 turns, total input reaches 99,000 tokens against the 23,000 a flat per-turn estimate predicts.

On Claude Sonnet 5 at introductory rates that conversation costs $0.198 of input plus $0.05 of output, about $0.248, where the flat estimate says $0.096. From September 1, 2026 the same conversation bills $0.297 plus $0.075, or $0.372.

Reasoning and tool tokens: the line items nobody budgets#

OpenAI's reasoning guide states that reasoning tokens are not visible via the API, still occupy context, and are billed as output tokens — anywhere from a few hundred to tens of thousands depending on problem complexity, reported under output_tokens_details.reasoning_tokens. Anthropic bills thinking tokens as output the same way, surfaced in output_tokens_details.thinking_tokens, and they count against max_tokens for the turn.

Tool use adds billable input on every request: Anthropic bills the tools parameter, tool_use and tool_result blocks, and an automatic tool-use system prompt worth 286 tokens on Claude Opus 5 with auto or none, 406 with any or a named tool.

Server-side tools bill outside the token model entirely. Anthropic's web search costs $10 per 1,000 searches on top of token costs. Two searches per request at 5,000 requests a day is 10,000 searches, or $100 a day — $3,000 a month, nearly ten times the token cost of the triage example above. Code execution without search or fetch gives 1,550 free hours per month per organization, then $0.05 per hour per container with a 5-minute minimum.

Build the spreadsheet#

  1. Measure one representative request, per model

    Send a realistic payload — system prompt, tools, any attachments — to the token counting endpoint for the exact model you plan to ship. Never carry a count between models: Claude 4.7 and later produce roughly 30% more tokens for identical text.

  2. Split input into fixed prefix and variable body

    The prefix is what repeats on every call: instructions, taxonomy, tool definitions, few-shot examples. Only the prefix is cacheable, and only if it clears your model's minimum.

  3. Price one request at published rates

    Prefix tokens times either the base or cache-read rate, plus variable tokens times the base rate, plus expected output tokens times the output rate. Add expected reasoning tokens to the output side.

  4. Multiply by volume, then by the growth factors

    Requests per day times days. For chat, replace flat volume with the summed per-turn input across a typical conversation length. For agents, multiply by expected tool-call rounds per task.

  5. Add the non-token line items

    Server tool charges such as $10 per 1,000 web searches, container hours beyond any free allowance, and cache storage where the provider bills it hourly.

  6. Add one sensitivity row per assumption you could be wrong about

    Prefix length, output length, conversation length, cache hit rate, retry attempts per request, and the data-residency multiplier — Anthropic applies 1.1x across every pricing category, input, output, cache writes and cache reads, when the inference_geo parameter pins inference to the United States on Claude 4.6 and later. Recompute the monthly total at each row doubled.

The sensitivity rows are the deliverable. A single monthly figure invites an argument about whether it is right; a table showing the total at 2x prefix length, 2x output length and 3x conversation length shows which assumption to measure first.

Verify against real usage fields before you scale#

Ship at low volume, then read the usage object instead of defending the spreadsheet.

Anthropic reports cache_read_input_tokens, cache_creation_input_tokens and input_tokens, where total input is the sum of the three and input_tokens covers only what follows the last cache breakpoint. If cache reads sit at zero across a live sample, caching is not working. Gemini reports usage.total_cached_tokens; OpenAI reports cached_tokens.

Response headers carry the throughput picture, including retry-after and the remaining input and output token allowances. Prompt edits move all of these, which is one more reason to keep prompts stable through model upgrades; see prompts that survive model updates.

Who this is not for#

Skip this method if you are buying a seat-priced product rather than calling an API. A per-user subscription has no token arithmetic to model.

Skip it at hobby volume. At a few hundred calls a month, almost any model above costs less than a coffee, and the hours spent trimming a prefix cost more than the tokens.

Skip most of it if latency binds. Batching, the largest single discount available, is off the table for anything a user waits on, and the estimate reduces to prompt length and model choice.

The recommendation#

Estimate the shape of one request before anything else. Measure the prefix, measure a realistic output, price them at the published rate for the exact model you will ship, and only then multiply by traffic.

Then attack in this order: cut the prefix, cache what remains if it clears your model's minimum, batch anything that tolerates delay. Model chat history as a growing sum rather than a flat per-turn cost, add retry attempts as real requests, and confirm how your provider prices long context.

Publish the estimate with its sensitivity rows attached and a date on the prices. Rates move — Claude Sonnet 5 changes on September 1, 2026 — so an estimate without a verification date is a number waiting to be wrong.

Frequently asked questions

How do you calculate the cost of an LLM API call?

Multiply input tokens by the input rate, multiply output tokens by the output rate, and add them. Rates are published per million tokens, so divide your token count by 1,000,000 first. A 3,800-token input and 150-token output on Claude Haiku 4.5, at $1 and $5 per million, costs $0.00455.

Why are output tokens more expensive than input tokens?

Every published table checked in August 2026 prices output above input, but the multiple varies by model rather than following one rule. Claude Opus 5 is 5x, gpt-5.6-sol is 6x, gpt-5 is 8x, Gemini 3.5 Flash is 6x, and deepseek-v4-flash is 2x against its cache-miss input rate. Check your model.

How many tokens is 1,000 words?

Roughly 1,300. Anthropic's pricing page gives a rough estimate of one token to about four characters or 0.75 words in English, which puts 1,000 words near 1,333 tokens. Treat that as a sanity check only. Token counts differ per model, so measure the real prompt with a token counting endpoint before budgeting.

Does conversation history increase LLM API costs on every turn?

Yes, and the growth is quadratic rather than linear. Turn 20 resends turns 1 through 19 as input, so a conversation with a 1,000-token system prompt and 400 tokens added per turn bills 8,750 input tokens on turn 20 against 1,150 on turn 1. Total input across the conversation reaches 99,000 tokens.

How much does prompt caching actually save, and when does it pay for itself?

Anthropic prices cache reads at 0.1x base input and states caching pays off after one cache read on the 5-minute duration, or two reads on the 1-hour duration. OpenAI prices cached input at 10 percent of standard input on its gpt-5.x models, with cache writes at 1.25x uncached input on GPT-5.6 and later.

Is the Batch API always 50% cheaper than the standard API?

The 50 percent figure holds across Anthropic, OpenAI, Google and Mistral as published in August 2026, but it buys latency, not free money. Anthropic batches expire after 24 hours, OpenAI caps a batch at 50,000 requests and a 200 MB input file, and neither suits interactive features.

Do reasoning or thinking tokens count as output tokens?

On both verified providers, yes. OpenAI's reasoning guide states reasoning tokens are invisible via the API but occupy context and are billed as output tokens. Anthropic bills thinking tokens as output and reports them in the thinking_tokens field. Reasoning length varies per request, so per-call output cost is not fixed.

Sources

  1. Anthropic — Claude API pricing
  2. Anthropic — Prompt caching
  3. Anthropic — Batch processing
  4. Anthropic — Token counting
  5. Anthropic — Rate limits
  6. Anthropic — API errors
  7. Anthropic — Extended thinking
  8. OpenAI — API pricing
  9. OpenAI — Prompt caching guide
  10. OpenAI — Batch API guide
  11. OpenAI — Reasoning guide
  12. Google — Gemini API pricing
  13. Google — Gemini API context caching
  14. DeepSeek — API pricing
  15. Mistral — Pricing
Advertisement

AI Tools Tutorial Team

Editorial

The editorial team behind aitoolstutorial.com. Every tool is checked against its vendor's own pricing and docs before anything is published, every source is linked at the foot of the article, and every recommendation names at least one thing the tool gets wrong.