How to estimate LLM API cost before you build
Count tokens, price the four kinds of usage and size a monthly bill for a chatbot, a document pipeline or an agent, with a method you can redo in minutes.
You can estimate an LLM API bill to within a small factor before writing any product code, and a small factor is all you need to decide whether an idea works. The method is the same for every model: count tokens per request, price them by kind, multiply by volume. This page walks through it, then applies it to three workloads. When you want the arithmetic done for you, use the cost calculator.
Step 1: count tokens per request
A token is a piece of a word. In English text, one token is about four characters, or three quarters of a word, so a 1,000-word document is roughly 1,300 tokens. Other languages and code use more tokens per word. Each model family has its own tokenizer, so the exact count differs between Claude, GPT and Gemini.
Count the parts of a request separately, because they're billed separately:
system prompt, tool definitions, instructions. The same on every call.
the user's message, retrieved text, the conversation so far.
the answer, plus any reasoning the model does first.
For an exact number on a real prompt, ask the API: Anthropic and Gemini offer a token-counting endpoint, and every response reports its usage.
Step 2: price the four kinds of usage
| Kind | Billed at | Notes |
|---|---|---|
| Uncached input | Input price | The part that changed since last time |
| Cached input | Cache-read price, a small fraction | Repeated prefixes; automatic on GPT and Gemini, marked with cache_control on Claude |
| Cache writes | Slightly above input (Claude only) | Paid once per cached prefix |
| Output | Output price, several times input | Reasoning and thinking tokens count as output |
Prices are per million tokens, so divide your token count by a million and multiply. The price tables for each vendor are live.
Step 3: multiply by volume
Monthly cost is cost per request times requests per month. Do it for a typical request and for a heavy one, and keep both numbers: the first is your budget, the second is your worst case.
Three workloads, worked
A support chatbot. Each reply sends about 1,500 input tokens (instructions, retrieved snippets, the question) and writes 400. The instructions are identical every time, so most of that input can be cached. At ten thousand replies a month that is 15 million input tokens and 4 million output tokens, and output is usually the larger part of the bill. Haiku-class and Flash-class models are the first thing to test.
A document pipeline. Each document is 20,000 tokens, and the summary is 500. Ten thousand documents is 200 million input tokens: input dominates, so the model's input price, and whether the document is cached across several questions, decide the bill. Run it on the cheapest model that summarizes acceptably.
A coding agent. One task is dozens of requests, each resending a growing history. The history is mostly cached, so cache-read price and hit rate matter more than the headline input price. Measure one real task, then multiply: How much Claude Code costs shows a turn priced line by line.
Add a margin for the unknowns
add some percent; track them from day one.
can double output on hard prompts; read the usage fields and set the effort deliberately.
Take the 90th percentile, not the average.
Read them from the catalog (GET https://halfoff.dev/v1/models) instead of hard-coding.
Frequently asked questions
How do I calculate the cost of an LLM API call?+
Input tokens times the input price, plus output tokens times the output price, each per million tokens, with cached input at the cache-read price. The formula is spelled out in Models & pricing.
How many tokens is 1,000 words?+
About 1,300 tokens in English, give or take. Code, numbers and non-English text use more. Count real samples rather than relying on the rule.
Are output tokens more expensive than input tokens?+
Yes, on every major model: output is typically several times the input price per token, which is why a long answer costs more than a long question.
How can I lower the estimate?+
Use a smaller model, cache repeated context and cap the output. The cheapest way to use the Claude API lists the changes in order of impact.
Where can I run the numbers?+
In the calculator with live prices for every model, or on the model list. Prices there are the prices you pay: Half Off Dev bills every model at half of the official list price.