# 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.

AI and LLM interview question Q324, Inference, performance and cost. Beginner, very common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/how-to-estimate-token-cost

## Say it in 30 seconds

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.

## Say it in 2 minutes

Every AI call is billed in tokens, which are small pieces of text. A feature has two bills in one: input tokens for everything I send, and output tokens for everything the model writes back. Each has its own price, so I never estimate them as one number. Take a claims assistant at an insurer. It sends about 9,000 input tokens per claim and gets 600 back.

To get a real figure, I start with a sample of real requests. A made-up test question misses the long documents and history real users send. I count the input tokens, measure the output from real runs, and multiply by the rates. Then I scale by calls per day and by the number of days. For the claims example, that is about 2,880 dollars a month, using made-up rates.

The estimate usually misses the hidden parts. Rules, tool definitions and chat history all count as input, and an agent re-sends its growing history on every tool step. Retries are paid calls too. On OpenAI's reasoning models, hidden reasoning tokens are billed as output.

To bring the cost down, I cache the repeated rules so later calls read them at a tenth of the price, trim the prompt, and send easy steps to a smaller model. Then I check the estimate against real usage after launch. The price per token is only one part of the total cost.

## 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.

- **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.

*Diagram, Counting a feature's cost: 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.*
1. Each sample request has its input tokens counted.
2. Each one's output is measured from a real run.
3. Input tokens are priced at the input rate.
4. Output tokens are priced at the output rate.
5. Cost per call × calls × days gives the month.

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:

```text
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.

*Diagram, Three levers that cut the bill: 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.*
1. The repeated rules are saved and read again, cheaply.
2. Rules are trimmed to what this step needs.
3. Simple steps on the new claim go to the smaller model.
4. Cached reads cost a tenth of the price on most models.
5. Fewer input tokens are paid for on every call.
6. Cheaper steps lower the total, if answers stay good.

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." Better: Count 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." Better: Also count retries, tool loops, repeated history and hidden reasoning output.
- Trap: "A cheaper model always means a smaller bill." Better: A 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?

A. One test question with 800 input tokens, multiplied by 40,000 queries a day.
B. 300 real queries, input and output counted apart, then scaled by days.
C. Each query priced at the input rate and the output rate, then added together.
D. A check against the real usage numbers in the first week.

**Answer:** A. One short test question leaves out the long documents and history real users send, and it skips the output side. Sample real traffic, price input and output apart, then compare with the real numbers.

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

A. Adding more rules to the system prompt
B. Caching the rules block so repeat calls read it cheaply
C. Sending the rules in an extra call before each request
D. Asking the model for longer answers, so users see more

**Answer:** B. A cached read of a repeated start costs a fraction of the normal input price. More rules, an extra call or longer answers all add tokens to the bill.

## Can you answer these from memory?

**Flash cards**

- **What is a token?** A small piece of text. OpenAI: about 4 characters in English.
- **Input vs output tokens?** Input: everything you send. Output: everything the model writes back.
- **Why sample real requests?** Test prompts miss the long documents and history that real users send.
- **What does caching change?** Repeated input is read at a tenth of the normal price on most Claude models (Anthropic, 2026).
- **What is the Batch API?** Asynchronous work at 50 percent off input and output tokens (Anthropic).
- **A common hidden cost?** Repeated history and retries. Each tool step re-sends the growing context.

## Likely follow-up questions

- Q323 Small vs large model: how do you choose? https://designervenkat.online/interview/ai/small-vs-large-model
- Q325 What is semantic caching? (full answer coming)
- Q326 Prompt cache vs semantic cache vs KV cache? (full answer coming)
- Q331 When do you use batch APIs? (full answer coming)
- Q330 How do you handle rate limits and 429 errors? (full answer coming)
- Q187 How do you control agent cost? https://designervenkat.online/interview/ai/how-do-you-control-agent-cost

## Learn it in depth

- [Tokens](https://designervenkat.online/learn/ai-engineering/tokens)
- [Prompt Caching](https://designervenkat.online/learn/ai-engineering/prompt-caching)
- [Watching cost and speed](https://designervenkat.online/learn/ai-engineering/cost-latency-monitoring)
