What is a token in AI? Meaning, how it works and the tools to count them
What a token is, how a model turns your text into tokens, why your bill is counted in them, and how to keep the count under control.
A token is the small chunk of text an AI model actually reads and writes: a whole word, a piece of a word, a punctuation mark or a space. In English, one token is about 4 characters, or three quarters of a word, so 100 tokens make roughly 75 words.
Tokens are also the unit you pay in and the unit of every limit: the context window, the price per million, the rate limits. We compared the official docs and price lists: this page explains tokenization in plain words, walks through what a chatbot conversation really consumes, lists the traps that inflate a bill, sets tokens against words, characters and embeddings, and reviews eight tools to count and track them.
The ranking is editorial: a sponsored place is always flagged on its card, and no affiliate link changes a rating.
How tokenization works, in three steps
A language model never sees letters or words. Before your prompt reaches it, a piece of software called a tokenizer cuts the text into tokens and swaps each one for a number. The model works on those numbers, then predicts the next token, one at a time, until the answer is done.
- Split. The tokenizer cuts the text into pieces it knows. Frequent words usually stay whole. Rare words, names and typos get cut into smaller pieces. Spaces and capital letters matter: "red", "Red" and " red" with a leading space are three different pieces of text for a tokenizer.
- Number. Each piece maps to an ID in a fixed vocabulary, the list of every token the model knows. That vocabulary is fixed when the tokenizer is trained. A newer model can ship a new tokenizer, and then the same sentence gives a different count.
- Predict. The model turns each ID into a vector (an embedding), reads the whole sequence, and outputs the most likely next token. Your answer is written token by token, which is why output is slower and pricier than input.
Most current models use subword tokenization, usually a method called byte pair encoding (BPE): start from characters, then merge the pairs that appear most often until the vocabulary reaches its target size. Two older approaches show why. Word-level tokenization needs a huge vocabulary and chokes on any word it has never seen. Character-level tokenization handles anything but turns a sentence into a long string of tokens, which costs compute. Subwords sit in between: common words in one piece, rare words in a few.
The rules of thumb come from the model makers themselves. For English, 1 token is about 4 characters and three quarters of a word, so 100 tokens are about 75 words. For Gemini models, a token is also about 4 characters, and 100 tokens equal 60 to 80 English words. Code, tables and other languages break those ratios, so treat them as a first estimate, never as a budget.
Tokens are not only text. Multimodal models turn images, audio and video into tokens too, each with its own counting rule. Whatever goes in, the bill and the limits are counted in the same unit. To see what the model does with those tokens, read our page on large language models; for what happens at answer time, our page on inference.
A step-by-step example: what one chatbot conversation really consumes
Most token surprises come from one fact: the API doesn't remember the conversation. Your app resends the whole history with every message. Here is a support chatbot, with round numbers you can redo yourself.
- The fixed part. The system prompt (tone, rules, product facts) weighs 1,000 tokens. It travels with every single request.
- Turn 1. The customer writes 50 tokens, the bot answers in 200. Input: 1,000 + 50 = 1,050 tokens. Output: 200.
- Turn 2. The new question (50 tokens) goes out with the system prompt and all of turn 1 (250 tokens). Input: 1,300 tokens, for a question of the same size.
- Turn 10. The request now carries nine previous exchanges. Input: 1,000 + 9 × 250 + 50 = 3,300 tokens, about 3.1 times turn 1.
- The whole conversation. Over ten turns, you send 21,750 input tokens and receive 2,000 output tokens, while the customer and the bot only wrote 2,500 tokens of new text.
On Claude Haiku 4.5, at $1 per million input tokens and $5 per million output tokens, that conversation costs about $0.032: $0.02175 of input plus $0.01 of output. At 10,000 conversations a month, that's $317.50. The bill grows with the length of the chats, not only with their number, which is why a team can see spend rise while traffic stays flat.
Two fixes change the math. Trim the history: keep the last few exchanges and a short summary of the rest. And cache the fixed part: on most Claude models, reading a cached prefix costs 0.1 times the base input price, and a 5-minute cache write at 1.25 times pays for itself after one read. Our page on prompt engineering covers how to write shorter prompts that still hold the rules.
What a token really costs, and the traps that inflate the count
Most explainers stop at "more tokens, higher cost". Here are the numbers that decide your bill, read on the official price lists and docs. Prices are per million tokens (MTok): $5 / MTok means $5 for every million tokens.
1. Output costs five times input. Claude Haiku 4.5 charges $1 per million input tokens and $5 per million output tokens; Claude Sonnet 4.6, $3 and $15. A long answer costs more than a long question. Ask for the format you need (a list, a JSON with the fields you use) and cap the output length.
2. Reasoning tokens are billed but not shown. On reasoning models, the model thinks before it answers. Those reasoning tokens never appear as text, yet they count toward output usage and are billed as output tokens. A two-line answer can cost far more than its two lines.
3. A new tokenizer changes the count of the same prompt. Claude 4.7 and later models use a newer tokenizer that produces about 30% more tokens for the same text. A budget measured on an older model is wrong on the new one, even if the price per token looks the same. Recount with the model you plan to use.
4. Tools add tokens you never typed. When you give Claude Haiku 4.5 tools, the API adds a tool-use system prompt of 496 tokens (588 when you force tool use with tool_choice any or tool), before your own tool names, descriptions and schemas. Agents with a dozen tools pay for all of them on every call, used or not. Fetched content counts too: an average 10 kB web page is about 2,500 tokens.
5. Some prices jump with prompt length. Claude Haiku 5.5 costs $0.10 per million input tokens for prompts up to 100,000 tokens, and $0.50 above. The whole request is repriced, cache reads included: cross the line by one token and that request pays five times the input rate.
6. Your language changes the price. Tokenizers learn mostly from English. The same text translated into other languages can need far more tokens, with gaps of up to 15 times measured in research on public tokenizers. A product sold in Hindi, Arabic or Thai should budget from real counts in those languages.
The savings that are real. Cache what repeats: on most Claude models a cache read costs 0.1 times the input price, and a 1-hour cache write at 2 times pays off after two reads. Batch what can wait: the Claude Batch API takes 50% off input and output. For the full price grid across providers, see our LLM API pricing index, and for the cheapest options, cheap LLM APIs.
When counting tokens matters, and when you can ignore it
Count your tokens if…
- You call an LLM API and pay per million tokens
- You build a chatbot or an agent that resends its history on every turn
- You stuff documents, web pages or search results into prompts (RAG)
- You give the model tools, JSON schemas or long examples
- You sell in several languages and price your product per message
- You move to a newer model version and want the same budget
You can mostly ignore them if…
- You use a chat app on a flat monthly plan, where limits are counted for you
- Your prompts are short one-offs and your monthly spend is a few dollars
- A no-code tool bills you per task or per run, not per token
- You only need a ballpark: 4 characters per token is enough for a first estimate
Token vs word, character, embedding and "token" elsewhere: what changes
"Token" means different things depending on who says it. Here's how an AI token compares with the units and the namesakes it gets confused with.
| AI token | The neighbors | |
|---|---|---|
| What it is | A chunk of text (or image, audio) mapped to an ID in a model's vocabulary | Word: a unit of language Character: one letter, digit or sign |
| Size in English | About 4 characters, three quarters of a word | Word: about 1.3 tokens Character: about a quarter of a token |
| Same count on every model | No, each tokenizer counts its own way | Word and character: yes |
| What you pay for | Tokens in and tokens out, at different prices | Some speech services bill per minute of audio instead |
| Embedding | The token is the input piece | Embedding: the vector of numbers that captures a token's or a text's meaning |
| Not to confuse with | An AI token is a unit of text | API token: a secret key that authenticates you Crypto token: a digital asset on a blockchain |
An embedding turns tokens into numbers that carry meaning; our page on vector databases shows where those embeddings end up. An API key is sometimes called a token too, but it is a password, not a unit of text.
The best tools to count and control your tokens
We compared eight tools, from a free tokenizer to production cost tracking. The quick route: on OpenAI models, tiktoken in your code; to learn and compare prompts, Tiktokenizer; on Claude, the free token counting API; images, audio or video on Gemini, countTokens; open models, Hugging Face Tokenizers; to see cost per feature in production, Langfuse or Helicone; to compare token prices across models, OpenRouter. Each card gives the price, who it's for, its limit and one tip.
The tools
tiktoken: OpenAI's tokenizer, in your code
Best for OpenAI modelstiktoken is the open source library OpenAI publishes to turn text into the exact tokens its models see. You install it with pip install tiktoken, pick an encoding such as o200k_base, or ask for the one that matches a model, and the length of the encoded list is your token count. OpenAI also offers the OpenAI Tokenizer, a page to see the split in a browser, and an input-token counting API for full requests.
Who it's for. Developers who call OpenAI models and want a count before each request, in a script, a backend or a test.
The limit. It counts plain text for OpenAI encodings only. It doesn't know Claude's or Gemini's tokenizers, and it doesn't add the formatting tokens of a chat request or the reasoning tokens of the answer.
The tip. Load the encoding once and reuse it: it is between 3 and 6 times faster than a comparable open source tokenizer. For a full request with tools and images, use the counting API instead of rebuilding the prompt by hand.
Choosing a provider? See the best LLM APIs.
- Price
- Free, MIT license
- Best for
- Developers on OpenAI models
- Limit
- OpenAI encodings and plain text only
Tiktokenizer: see the split before you code
Easiest startTiktokenizer is a free online playground for tiktoken. You type a system message and user messages, pick a model, and it shows the token count and every token ID, including the special tokens the chat format wraps around each message. It's the quickest way to understand why a word becomes three tokens, or why a JSON blob costs more than the sentence it describes.
Who it's for. Anyone learning how tokens work, prompt writers comparing two versions of a prompt, and teams explaining a bill to a non-technical manager.
The limit. It reflects OpenAI-style encodings. A Claude or Gemini count will differ, so use it to learn and compare, not to budget another provider's model.
The tip. Paste the same paragraph as prose, as a bullet list and as JSON. The difference in count shows you which format to send in your prompts. The code is open source under the MIT license, so you can run your own copy.
- Price
- Free, MIT license
- Best for
- Learning and comparing prompts
- Limit
- OpenAI-style encodings only
Claude token counting API: the exact count before you send
Best for ClaudeAnthropic's token counting endpoint takes the same request you would send to Claude (system prompt, messages, tools, images, PDFs) and returns the number of input tokens. It counts under the tokenizer of the model you name, which matters since Claude 4.7 and later models produce about 30% more tokens for the same text than earlier ones.
Who it's for. Teams on Claude who route requests by size, trim prompts to fit a budget, or migrate to a newer model.
The limit. The count is an estimate and can differ by a small amount. It refuses server tools such as web search, the MCP connector, and images or PDFs sent by URL: send them as base64 to count them.
The tip. It's free, with its own rate limit: 5,000 requests per minute on the Start tier, 10,000 on Build, 20,000 on Scale, separate from your message limits. Count the same request on your current model and on the next one before you switch. Full review: Claude. Looking elsewhere? Our Claude alternatives.
- Price
- Free (rate-limited by usage tier)
- Best for
- Claude API users and migrations
- Limit
- Estimate; no server tools or URL sources
Gemini countTokens: counts for text, images, audio and video
Best for multimodalGoogle's countTokens method runs a Gemini model's tokenizer on your content and returns the token count. It shines on multimodal input, where word-based guesses are useless: an image up to 384 pixels on both sides counts as 258 tokens, larger images are cut into 768 × 768 tiles of 258 tokens each, audio counts 32 tokens per second and video 263 tokens per second in static processing, though Google's Gemini API docs also put default-resolution video at about 100 tokens per second.
Who it's for. Teams sending images, recordings or video to Gemini, and anyone filling the large context windows of Gemini models.
The limit. There's no charge for calling it through Firebase AI Logic, with a quota of 3,000 requests per minute. The counting rules for agentic video processing vary, so measure real files rather than multiplying by seconds.
The tip. Count one minute of your real audio: at 32 tokens per second, a 60-minute call is 115,200 tokens before you add a single word of prompt. Full review: Gemini; or compare our Gemini alternatives.
- Price
- Free via Firebase AI Logic (3,000 requests/min)
- Best for
- Images, audio and video on Gemini
- Limit
- Gemini tokenizer only
Hugging Face Tokenizers: count and train for open models
Best for open modelsTokenizers is Hugging Face's open source library for the tokenizers of open models. It implements BPE, WordPiece, Unigram and WordLevel, with a Rust core and bindings for Python, Node.js and WebAssembly. You load the tokenizer published with the open model you run and count tokens locally, without any API call.
Who it's for. Teams that self-host open models, fine-tune them, or count tokens locally for an open model's tokenizer.
The limit. It doesn't know the closed tokenizers of OpenAI, Claude or Gemini. The Python package is published as a v1 release candidate, so you install it with pip install --pre tokenizers, and that version does not ship every feature yet: training is still on the list of things being brought back to the Python bindings.
The tip. If your text is full of jargon, product codes or a less common language, count a sample with the tokenizer of each open model you shortlist: fewer pieces per word means more text per context window. To train your own tokenizer, check first that the version you install supports it. Full review: Hugging Face. Looking elsewhere? Our Hugging Face alternatives.
- Price
- Free, Apache-2.0 license
- Best for
- Open and self-hosted models
- Limit
- No closed-model tokenizers
Langfuse: see where your tokens go in production
Best open source trackingCounting tokens before a call is half the job. Langfuse records the usage of each model call, broken down by usage type (input, output, cached), and calculates its cost in USD from the model name and its price. Dashboards then show cost across models, tags or users, so you see which feature burns the budget. It is open source and you can self-host it for free.
Who it's for. Teams with an LLM feature in production who need cost per feature, per customer or per release, not one total on the provider's dashboard.
The limit. Cloud plans bill in units, and a billable unit is any tracing data point you send, not a token. Hobby is free with 50,000 units a month, 2 users and 30 days of data access. Core costs $29 a month with 100,000 units included, then $8 per 100,000 units.
The tip. Log the attempt number and the workflow name with each call: retries and fallbacks then show up as one user action, not three. More options in the best LLM observability tools and our Langfuse alternatives.
- Price
- Hobby free (50k units/month); Core $29/month
- Best for
- Cost per feature in production
- Limit
- Units are data points, not tokens
Helicone: token and cost logs with one line of setup
Quickest to set upHelicone is a gateway between your app and the model providers. You point your SDK at it by changing the base URL, each request shows up in its Requests tab within seconds, and its cost analytics estimate spend from the model and the token counts. Custom properties, sent as request headers, slice that spend by feature, user tier or environment. It's open source.
Who it's for. Small teams who want token and cost visibility today, without instrumenting their code call by call.
The limit. Hobby is free with 10,000 requests, 1 seat and 7 days of retention. Pro costs $79 a month with unlimited seats and 1 month of retention, plus usage-based pricing beyond the 10,000 free requests. Team is $799 a month. Helicone is now part of Experiential Labs: check its roadmap before you build on it.
The tip. Send the feature name as a custom property on each request. Seven days of free retention is enough to find the one prompt that doubled your bill, before you pay for history. See also our Helicone alternatives, and why each request's wait time matters in our page on latency.
- Price
- Hobby free (10,000 requests); Pro $79/month
- Best for
- Fast setup, small teams
- Limit
- 7-day retention on the free plan
OpenRouter: compare token prices across models in one place
Best for comparing pricesOpenRouter gives you one API for models from many providers, with each model's input and output price per token listed side by side. Input and output tokens are billed per model at posted rates, and inference is billed at the provider's list price on every plan: OpenRouter doesn't mark up the tokens.
Who it's for. Teams that test several models on the same task, or want a fallback model when one provider is down.
The limit. The fee sits on credits: 5.5% when you buy credits on the Standard plan, 8% on Business. The free plan gives 25+ free models and 50 requests a day, enough to try, not to run a product.
The tip. Compare cost per task, not price per token: run the same 20 prompts through two models and add up the real tokens each one spends. A failed attempt isn't charged for its model tokens, so fallbacks cost you only the run that answers. Looking elsewhere? Our OpenRouter alternatives.
- Price
- Provider list price + 5.5% fee on credits
- Best for
- Comparing models on cost per task
- Limit
- Free plan: 50 requests a day
Is your tool missing from this page? Email us: hello@hackceleration.com
Token FAQ
Do spaces and punctuation count as tokens?
Yes. Spaces, punctuation and line breaks are part of the text a tokenizer splits, so they take up tokens. A leading space is usually glued to the word after it, which is why "red" and " red" are different pieces of text with different token IDs. Extra blank lines, indentation in pasted code and decorative symbols all add tokens you pay for without adding meaning.
Why do AI models use tokens instead of whole words?
Because a fixed list of subword pieces can spell any word, while a list of whole words can't. English alone has roughly 171,000 words in current use, before names, typos, slang and other languages. Subword tokens keep the vocabulary at a manageable size and let the model read a word it has never seen by breaking it into pieces it knows.
Does a bigger context window cost more per token?
Usually not: on Claude 4.6 and later models, a 900k-token request is billed at the same per-token rate as a 9k-token one, so a full window simply costs more tokens. The exception is Claude Haiku 5.5, whose input price rises from $0.10 to $0.50 per million once a prompt passes 100,000 tokens. Check what shares the window, though. Gemini 4 models share a single window of 1,048,576 tokens across input, thinking and output, while Gemini 3 and 2.5 models keep separate budgets: 1,048,576 tokens of input and 65,536 of output.
What happens when a prompt goes over the token limit?
The model can't take it whole: depending on the tool, the request fails, or the input is cut and the model loses part of the context. A long prompt also eats the space left for the answer. In an older model with a 4,096-token window, a 3,900-token prompt left only 196 tokens for the reply, so answers stopped mid-sentence.
How many tokens does a PDF use?
It depends on the model and on the pages, not on the file size alone. On Gemini, each page of a PDF is tokenized like an image, so a scanned page costs the same as a picture of the same size. On Claude, a 500 kB research paper fetched with the web fetch tool takes about 125,000 tokens, and a 100 kB documentation page about 25,000: one file can fill a small context window. Count one real document with the provider's counting endpoint before you send a batch of them.
Why does the same text cost more in some languages?
Because most tokenizers are trained mostly on English, so other languages and scripts get cut into more, smaller pieces. Research on public tokenizers found that the same text translated into different languages can differ in token count by up to 15 times. More tokens mean a higher bill and less text per context window, so a product sold in several languages should be priced on real counts in each one.
Why does a chat request count more tokens than the text I typed?
Because the chat format wraps every message in special tokens you never type: markers for the start and end of a message and for the role (system, user, assistant). In the gpt-4o format, a system message reading "You are a helpful assistant" with an empty user turn counts 16 tokens, of which only 5 are the sentence itself. On short messages sent at high volume, that overhead is a real share of the bill.
