esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

How Do You Estimate Token Cost for a Feature?

How to count tokens, price input and output, and budget a monthly bill for an AI feature, explained simply for your AI interview.

In short

Count the tokens a feature sends in and gets back on real requests, price each type separately, then scale by calls per day. Check the estimate against real usage numbers, because repeated context and retries often add more than expected.

11 min readBeginnerVery common · estimateFacts checked 26 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

To estimate the cost of a feature, I start with real traffic. I count input tokens and output tokens separately on a sample of real requests, multiply each by its price, then scale by calls per day. After launch I check the estimate against the real usage numbers. I also add the hidden parts, like repeated rules, chat history and retries, because they are often the biggest surprise.

What is a token cost, in plain words?

Every AI call is billed in tokens. A token is a small piece of text, and OpenAI puts it this way: "1 token is approximately 4 characters." A long document is many tokens, and a short reply is a few.

Think of a print shop. It charges for the pages you hand in, and again for the pages it prints back, at different rates. An AI call works the same way. Input tokens are what you send. Output tokens are what the model writes back. Each one has its own price.

A real case: a claims team at a mid-size insurer wants an assistant that reads each claim, checks the policy rules and drafts a summary for a human adjuster. Before launch, the team needs a monthly figure, not a guess.

Key words

Token
A small piece of text. In English, about four characters.
Input tokens
Everything you send: rules, documents, chat history and the user's message.
Output tokens
Everything the model writes back, including hidden reasoning that some models bill.
Price per million
Vendors quote the rate per million tokens, not per single token.
Cache
A saved copy of a repeated start of a prompt, so the next call reads it more cheaply.

How do you count the tokens before launch?

Start with real traffic. Take a few hundred real requests from a test log and count the input tokens each one sends. Anthropic's token counting is free and gives an estimate, not an exact figure. OpenAI warns that a plain-text count can miss tokens that message structure adds, so count the whole request, tools included.

Counting a feature's cost

Real requests

200 calls from a test log

Count each call

Input tokens

all text sent, rules included

Output tokens

all text written back

Price per million

one rate for each token type

Monthly cost

the total you check against the bill

  1. 1Each sample request has its input tokens counted.
  2. 2Each one's output is measured from a real run.
  3. 3Input tokens are priced at the input rate.
  4. 4Output tokens are priced at the output rate.
  5. 5Cost per call × calls × days gives the month.
Start with a sample of real requests. Count the input and output tokens for each, price them separately, then scale to a month. The last box is the number you check against the real bill.

Output is harder, because you cannot read it off the input. Measure it from real runs instead. OpenAI's Responses API reports usage after each call: "Responses reports input_tokens, output_tokens, and total_tokens." Log those numbers for your sample.

  • “A lower price per million tokens does not necessarily produce a lower total cost”

    OpenAI

  • “An input count does not predict how many output tokens the model will generate.”

    OpenAI

Then do the sum. Cost per call is input tokens times the input rate, plus output tokens times the output rate. Multiply by calls per day and by the number of days. That gives a monthly figure you can defend, and you check it against the real bill after the first week.

What does a real feature cost per month?

Back to the claims assistant. Each claim sends about 9,000 input tokens: 2,500 for the rules and instructions, 4,500 for policy excerpts that search pulls in, and 2,000 for the claim itself. It gets back about 600 output tokens. The team expects 8,000 claims a day.

The rates below are made up for the example: 1 dollar per million input tokens and 5 dollars per million output tokens. Real prices are on each vendor's pricing page, and they change, so check the page on the day you estimate.

Python
# A made-up claims assistant: estimate the monthly bill before launch.
PRICE_IN = 1.00   # made-up: dollars per million input tokens
PRICE_OUT = 5.00  # made-up: dollars per million output tokens

def cost_per_call(input_tokens, output_tokens):
    return (input_tokens * PRICE_IN + output_tokens * PRICE_OUT) / 1_000_000

def monthly(calls_per_day, input_tokens, output_tokens, days=30):
    return round(calls_per_day * days * cost_per_call(input_tokens, output_tokens), 2)

# Only the rules repeat exactly on every claim; excerpts and the claim are new.
RULES, EXCERPTS, CLAIM, OUTPUT = 2500, 4500, 2000, 600
print("Per claim, no cache:", round(cost_per_call(RULES + EXCERPTS + CLAIM, OUTPUT), 4))
print("Per month, no cache:", monthly(8000, RULES + EXCERPTS + CLAIM, OUTPUT))
# With caching, the repeated rules are read at a tenth of the price.
cached_in = RULES * 0.1 + EXCERPTS + CLAIM
print("Per claim, cached:", round(cost_per_call(cached_in, OUTPUT), 4))
print("Per month, cached:", monthly(8000, cached_in, OUTPUT))

Output

Per claim, no cache: 0.012
Per month, no cache: 2880.0
Per claim, cached: 0.0097
Per month, cached: 2340.0
  • Without caching

    About $2,880 a month

    Every claim sends 9,000 input tokens and gets 600 output tokens back, at the made-up rates.

  • With caching

    About $2,340 a month

    The 2,500 rules are read from cache at a tenth of the price. The policy excerpts and the claim are new on each call.

The rules are the same on every call, which is why caching helps with them. The policy excerpts change with each claim, so they are not cached. Anthropic's prompt caching docs say cache reads cost 0.1 times the base input price on most models, and a 5-minute cache write (the first save of a repeated start) costs 1.25 times. The cache lasts 5 minutes by default and is refreshed each time it is used, so the saving holds while calls keep arriving within that window. The example skips the occasional write, so treat the cached figure as a floor.

Two things push the real bill above this example. An agent re-sends its growing history on every tool step, so a five-step run sends that history five times. And each retry is a paid call too. Tool definitions (the written descriptions of the functions the model may call) are sent as input tokens, and Anthropic's pricing page says tool-related token counts are added to your normal input and output tokens.

Tip

Asked how you would estimate a feature's cost? Name the sample, count input and output separately, scale by calls and days, then say what you would cut first.

How do you bring the cost down?

Three levers do most of the work, and the chart shows how each one reaches the bill. Caching stops you paying full price for the same rules on every call. Shorter prompts send less. OpenAI's help page gives the same advice when input is too large: "Remove unnecessary or repeated context." A small model can take the easy steps while the big model handles the hard ones.

Three levers that cut the bill

Each call

Repeated rules

sent again on every call

Policy excerpts and claim

new on every call

Levers

Prompt caching

a tenth on most models

Shorter prompt

trim to what this step needs

Small model, easy steps

cheap model for simple steps

Lower bill

same work, fewer paid tokens

  1. 1The repeated rules are saved and read again, cheaply.
  2. 2Rules are trimmed to what this step needs.
  3. 3Simple steps on the new claim go to the smaller model.
  4. 4Cached reads cost a tenth of the price on most models.
  5. 5Fewer input tokens are paid for on every call.
  6. 6Cheaper steps lower the total, if answers stay good.
Three levers reach the bill. Caching and shorter prompts cut the repeated input, and a smaller model takes the easy steps. Each one lowers the bill only if the answers stay good enough.

Batch processing is a fourth lever. Anthropic's pricing page says its Batch API, a queue where results come back later rather than live, gives a 50 percent discount on both input and output tokens for large volumes. Use it for overnight summaries, where nobody waits for the reply.

What does the interviewer want to hear?

A strong answer covers

  • Count input and output tokens separately, using a sample of real requests.
  • Price each type at its own rate, then scale by calls and days.
  • Include the hidden parts: rules, tool definitions, history, retries, reasoning.
  • Check the estimate against real usage numbers after launch.
  • Name the levers: caching, shorter prompts, smaller models, batch.
  • Say that prices change, so check the vendor's pricing page on the day.

Common traps

  • Trap"Just count the words in the prompt."

    BetterCount tokens. One word can be more than one token, and the answer counts too.

  • Trap"The bill is one call times the number of users."

    BetterAlso count retries, tool loops, repeated history and hidden reasoning output.

  • Trap"A cheaper model always means a smaller bill."

    BetterA lower price can still cost more if answers are longer or need retries. Test a real task.

Can you spot the weak estimate?

Spot the weak estimate

A contract-search team estimates its cost like this. Which line would most likely understate the real bill?

Quick check

A feature sends the same 6,000-token rules block on every call. Which change cuts most of that repeated cost?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q323Small vs large model: how do you choose?11 min
  2. Q325What is semantic caching?Coming soon
  3. Q326Prompt cache vs semantic cache vs KV cache?Coming soon
  4. Q331When do you use batch APIs?Coming soon
  5. Q330How do you handle rate limits and 429 errors?Coming soon
  6. Q187How do you control agent cost?13 min

Learn it in depth

Last updated on 26 November 2026

Building an AI feature and not sure what it will cost?

I design and build AI products and agents, and I plan their running costs with them. Book a short call and tell me the feature, the volume and the budget you have.