halfoff.dev
Get a key
Guide

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.

Prepaid, no subscriptionREST or MCPOne key for models, data and agents

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.

01

Step 1: count tokens per request

010203

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:

Fixed input

system prompt, tool definitions, instructions. The same on every call.

Variable input

the user's message, retrieved text, the conversation so far.

Output

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.

02

Step 2: price the four kinds of usage

010203
KindBilled atNotes
Uncached inputInput priceThe part that changed since last time
Cached inputCache-read price, a small fractionRepeated prefixes; automatic on GPT and Gemini, marked with cache_control on Claude
Cache writesSlightly above input (Claude only)Paid once per cached prefix
OutputOutput price, several times inputReasoning 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.

03

Step 3: multiply by volume

010203

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.

04

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.

05

Add a margin for the unknowns

Retries and failed calls

add some percent; track them from day one.

Reasoning tokens

can double output on hard prompts; read the usage fields and set the effort deliberately.

Real inputs are longer than your examples

Take the 90th percentile, not the average.

Prices change

Read them from the catalog (GET https://halfoff.dev/v1/models) instead of hard-coding.

06

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.

One prepaid key for models, data and agents

No subscription. Top up, use what you need, see every charge in your logs.