LLM Tokens Explained: How to Estimate Your API Bill Before It Surprises You
By Junaid Aslam. 3 min read. Updated .
AI APIs don't bill by the word or by the request. They bill by the token. If you don't know what a token is, your first invoice can be a nasty surprise.
What a token is
A language model reads tokens, not letters or whole words. A tokenizer cuts the input into chunks. A token can be a whole common word (the), part of a longer word (un + believ + able), a piece of punctuation, or even a single space.
For ordinary English, OpenAI's rule of thumb is that one token is about four characters, or about three quarters of a word. So 1,000 words is roughly 1,300 tokens. That's just an average. Your actual text can land quite far from it.
Why the same text gives different counts
- Different tokenizers. GPT models, Claude, Gemini and open models each use their own tokenizer, so one paragraph produces slightly different counts on each.
- Language. English tokenizes efficiently. Many other languages, especially ones with non-Latin scripts, use noticeably more tokens for the same meaning. That directly raises cost.
- Code and data. Source code, JSON, and long numbers break into lots of small tokens. Indentation and punctuation add up.
- Formatting. Extra whitespace, long URLs, and Markdown tables all take tokens.
The only reliable way to know is to count with the right tokenizer. The Token Counter gives an exact count for OpenAI models using the same tiktoken library, and estimates for other model families. Paste in a real prompt from your app, not a made-up one.
How pricing works
Providers publish prices per million tokens, and they charge input and output separately. Input is everything you send: the system prompt, the conversation history, any documents, and the user's question. Output is what the model writes back. Output tokens usually cost several times more than input tokens.
The formula is:
cost = (input tokens / 1,000,000 x input price) + (output tokens / 1,000,000 x output price)A worked example
These prices are made up so the math is easy to follow. Swap in the real prices for the model you use. Say a model charges $2 per million input tokens and $8 per million output tokens. Your app sends 3,000 input tokens and gets back 500 output tokens per request, and you expect 10,000 requests a day.
| Step | Math | Result |
|---|---|---|
| Daily input tokens | 3,000 x 10,000 | 30,000,000 |
| Daily input cost | 30 x $2 | $60 |
| Daily output tokens | 500 x 10,000 | 5,000,000 |
| Daily output cost | 5 x $8 | $40 |
| Total per day | $60 + $40 | $100 |
| Total per 30 days | $100 x 30 | $3,000 |
Output is only about 14% of the tokens (5 million of 35 million) but 40% of the cost. Most of the tokens sit on the input side, so trimming the prompt is often the easiest saving.
Where bills quietly grow
- Chat history. Each new turn resends the whole conversation. A 20-turn chat costs far more than 20 separate questions.
- Long system prompts. A 2,000-token instruction block is paid for on every single call.
- Retrieval. Stuffing five long documents into every prompt adds thousands of tokens each time.
- Retries and agents. Loops that call the model repeatedly multiply everything above.
- Verbose output. If you don't cap the response length, the model may write more than you need.
Ways to cut the cost
- Shorten the system prompt. Remove examples the model doesn't need.
- Summarize or trim old conversation turns instead of resending everything.
- Set a maximum output length and ask for concise answers when that's enough.
- Use a smaller, cheaper model for easy tasks and save the big one for hard ones.
- Check whether your provider offers prompt caching, which discounts repeated input.
- Batch non-urgent work if the provider offers a cheaper batch tier.
Context windows are a separate limit
Every model has a maximum context window: the most tokens it can handle in one request, counting input and output together. If your prompt plus the expected reply exceeds it, the call fails or gets cut off. Count tokens before you send big documents.
Once you've counted your tokens, plug them into the LLM Cost Calculator to compare what the same workload would cost across GPT, Claude, Gemini, and other models. Prices change often, so check the date shown on the calculator and confirm against the provider's pricing page before you commit to a budget.