Free AI Tools

View all 83 →
AI Explained

How to Count Tokens and Estimate AI API Costs

By Botvana Team ·

Every AI API bill is really a token bill. If you know how to count tokens, you can predict what a chatbot, an agent or a document pipeline will cost before the invoice arrives, and you'll know whether a long prompt will even fit in a model's context window.

This guide explains what tokens are, the quick rules of thumb, how to get exact counts from OpenAI, Anthropic and Google, and a simple formula for turning tokens into dollars, pounds or euros. Facts come from each provider's documentation, checked on November 1, 2026. For a fast estimate without any code, paste your text into our free AI token counter.

Sentence split into glowing token blocks flowing into a calculator and coin stack, illustrating how to count tokens and estimate AI API costs

QUICK ANSWER

A token is a chunk of text, often part of a word. For English, Google says one token is about 4 characters and 100 tokens is about 60 to 80 words. For an estimate, use a token counter; for exact numbers use the provider's tool: tiktoken for OpenAI, the count_tokens endpoint for Claude, and count_tokens in the Gemini SDK. Cost = (input tokens / 1M x input price) + (output tokens / 1M x output price).

What is a token?

AI models don't read words; they read tokens. Google's Gemini token guide puts it simply: tokens can be single characters like "z" or whole words like "cat", and long words are broken into several tokens. The full set of tokens a model knows is its vocabulary, and splitting text into tokens is called tokenization.

Tokens matter for two reasons:

  • Cost: API providers bill per token, usually quoting a price per million input tokens and a different, usually higher, price per million output tokens.
  • Limits: a model's context window, the amount it can consider at once, is measured in tokens and includes your prompt, any documents and its reply.

Quick rules of thumb for counting tokens

If you just need a ballpark figure for English text:

  • Google says one token is about 4 characters for Gemini models.
  • Google also says 100 tokens is about 60 to 80 English words, so 1,000 words is very roughly 1,250 to 1,700 tokens.
  • A common shortcut is about 0.75 words per token (about 750 words per 1,000 tokens), which sits inside that range.

Rules of thumb break down for code, numbers, tables and non-English text, which can use noticeably more tokens. Each company also uses its own tokenizer, so the same paragraph gives different counts on different models. Anthropic, for instance, says Claude 4.7 and later models use a newer tokenizer that produces roughly 30% more tokens for the same text than earlier Claude models. Never reuse an old count after switching models.

Use our free AI token counter

Our AI token counter gives you an instant estimate in the browser. It averages the two rules above (about 4 characters per token and about 0.75 words per token), shows word and character counts, checks your text against common context-window sizes, and estimates cost at whatever price per million tokens you type in. It doesn't send your text anywhere.

  1. Paste your prompt, document or chat history.
  2. Read the estimated token count.
  3. Enter your model's input price per 1M tokens from the provider's pricing page and how many times you'll send it.
  4. Remember the reply also costs tokens, usually at a higher rate.

It's an estimate by design. When money is on the line, confirm with the official methods below.

How to count tokens exactly for each AI provider

OpenAI (ChatGPT models): tiktoken

OpenAI's open source tiktoken library is the fast tokenizer for its models. Install it with pip install tiktoken, then:

import tiktoken

enc = tiktoken.get_encoding("o200k_base")
# or: enc = tiktoken.encoding_for_model("gpt-4o")
print(len(enc.encode("How many tokens is this sentence?")))

Anthropic (Claude): the count_tokens endpoint

Anthropic's token counting API accepts the same inputs as a normal message, including system prompts, tools, images and PDFs, and returns the input token total. Anthropic says token counting is free to use but has its own requests-per-minute limits, and that the result is an estimate that may differ slightly from the final count.

import anthropic

client = anthropic.Anthropic()
response = client.messages.count_tokens(
    model="claude-opus-5-5",
    system="You are a helpful assistant",
    messages=[{"role": "user", "content": "Hello, Claude"}],
)
print(response.json())  # e.g. {"input_tokens": 14}

Google (Gemini): count_tokens and usage data

In the Gemini SDK, call count_tokens before sending a request to check its size, or read the usage data on the response afterwards, which breaks out input, output, thinking, cached and tool-use tokens.

from google import genai

client = genai.Client()
result = client.models.count_tokens(
    model="gemini-3.8-flash",
    contents="The quick brown fox jumps over the lazy dog.",
)
print(result.total_tokens)

Images, audio and video count too

For Gemini, Google says images up to 384 pixels in both dimensions count as 258 tokens; larger images are tiled into 768 x 768 tiles of 258 tokens each. Audio is 32 tokens per second and video 263 tokens per second (for static processing). A long video can therefore cost far more than its transcript.

How to estimate AI API costs from tokens

The formula is the same for every provider:

Cost per request = (input tokens / 1,000,000 x input price) + (output tokens / 1,000,000 x output price)

Here's a worked example using made-up round prices so the maths is easy to follow. Always plug in your provider's current prices.

ItemExample value
Input price$1.00 per 1M tokens (example only)
Output price$4.00 per 1M tokens (example only)
Tokens per request1,500 in, 500 out
Cost per request$0.0015 + $0.0020 = $0.0035
1,000 requests a day$3.50 a day, about $105 over 30 days

Our AI API cost calculator does this for you, with daily, monthly and yearly totals, optional prompt-caching and batch discounts, and a second scenario to compare two models side by side.

7 ways to cut your token bill

  1. Trim the system prompt. It's resent with every request. Our system prompt builder helps keep it tight.
  2. Cap output length with a max-tokens setting; output tokens usually cost more.
  3. Shorten chat history by summarising older turns instead of resending everything.
  4. Use prompt caching for repeated documents or instructions where your provider offers it.
  5. Batch non-urgent jobs if your provider discounts asynchronous batch processing.
  6. Route simple tasks to smaller models. Our Claude Haiku 5.5 guide shows where a small model is enough.
  7. Recount after every model change, because tokenizers differ.

Choosing between assistants rather than APIs? See ChatGPT vs Gemini vs Claude, or explore everything in our free AI tools hub.

Related: Shorter, clearer prompts use fewer tokens. See our complete guide to AI prompt generators, or try a free AI chat with no login before you pay for an API.

FAQ

How do I count tokens in my text?

For a quick estimate, paste the text into a token counter. For exact counts, use the provider's own tool: tiktoken for OpenAI models, the count_tokens endpoint for Claude, or count_tokens in the Gemini SDK.

How many words are 1,000 tokens?

For English, roughly 600 to 800 words based on Google's guide that 100 tokens is about 60 to 80 words. A common shortcut is about 750 words per 1,000 tokens.

How many characters is one token?

About 4 characters of English text, according to Google's Gemini documentation. Code, numbers and other languages can differ.

Do different AI models count tokens differently?

Yes. Each provider uses its own tokenizer, and even new versions from the same company can change. Anthropic says Claude 4.7 and later produce about 30% more tokens for the same text than earlier Claude models.

How do I calculate AI API cost from tokens?

Multiply input tokens divided by one million by the input price, add output tokens divided by one million times the output price, then multiply by your number of requests.

Sources and further reading

Botvana Team

The Botvana Team tests AI tools hands-on and explains AI news in plain language for students, freelancers and small businesses. Facts are checked against official sources.

Last updated

Comments

Contact Botvana

Newsletter

One short email every Friday: the AI news that matters and one tool worth trying.

Botvana
Home About Newsletter
Home Topics Search Newsletter