Count tokens in text for GPT-4, Claude, Llama, and other LLMs. Estimate API costs, compare models, and optimize prompts for token limits.
Tokens are the fundamental units that large language models (LLMs) use to process text. Unlike words or characters, tokens are subword units determined by the model's tokenizer — a word might be a single token, or it might be split into multiple tokens depending on its frequency in the training data. Understanding token counts is essential for managing API costs, staying within context window limits, and optimizing prompt engineering.
Different LLM providers use different tokenizers, meaning the same text produces different token counts depending on the model. This tool counts tokens for popular models so you can estimate costs and ensure your prompts fit within context limits.
| Model Family | Tokenizer | Avg. Tokens per Word | Context Window |
|---|---|---|---|
| GPT-4 / GPT-4o | cl100k_base (tiktoken) | ~0.75 | 128K tokens |
| Claude 3.5 | Custom BPE | ~0.75 | 200K tokens |
| Gemini 1.5 | SentencePiece | ~0.8 | 1M-2M tokens |
| Llama 3 | Custom BPE | ~0.8 | 128K tokens |
| Mistral | SentencePiece | ~0.8 | 32K-128K tokens |
The text "Tokenization is important" might tokenize as:
| Text | GPT-4 Tokens | Count |
|---|---|---|
| "Hello world" | ["Hello", " world"] | 2 |
| "Tokenization" | ["Token", "ization"] | 2 |
| "🎉" | ["🎉"] | 1 |
| "antidisestablishmentarianism" | ["ant", "idis", "establish", "ment", "arian", "ism"] | 6 |
Common English words are typically single tokens. Rare words, technical terms, and non-English text split into more tokens.