Tokenization guide
How LLM tokenization affects cost
Learn how text becomes tokens, why token counts vary by content type, and how to estimate API cost before sending a prompt.
How to use the AI token calculator
Paste Your Text
Enter or paste the text you want to analyze into the text area above.
View Token Count
See an instant token count directly in your browser.
Compare API Costs
Review estimated input, cached-input, and output costs across major LLM providers.
Optimize Your Prompts
Use the token visualization to identify opportunities to reduce token usage and API costs.
Understanding tokenization
This tool estimates how a prompt is split into tokens directly in your browser. Token counts are useful for planning context windows, output limits, and API cost before sending text to a provider.
What is BPE (Byte-Pair Encoding)?
BPE is the tokenization algorithm used by GPT models. It breaks text into subword units by iteratively merging the most frequent character pairs. For example, "tokenization" might become ["token", "ization"]. This allows models to handle rare words efficiently while keeping vocabulary size manageable.
What is a Context Window?
The context window is the maximum number of input and output tokens a model can process in one request. Exceeding a context window can cause truncation, rejected requests, or unexpectedly high cost.
What is Cached Input Pricing?
Cached input pricing offers significant discounts (up to 90% off) when you reuse the same prompt prefix across multiple API calls. This is ideal for system prompts, few-shot examples, or document analysis where the context remains constant while only the query changes.
Input vs Output Token Costs
Output tokens are typically 2-4x more expensive than input tokens because they require the model to perform sequential generation. To optimize costs, design prompts that get concise responses, use output length limits, and choose the right model for each task.
Word-to-token conversion guide
Token counts vary significantly based on content type and language. Use this reference to estimate token usage before running your text through the calculator.
English Text
Standard prose averages 1.3 tokens per word
Code (Python/JS)
Symbols, operators, and syntax increase token count
Chinese/Japanese
CJK characters often split into multiple tokens
Technical Writing
Technical terms and abbreviations vary
JSON/XML Data
Structural characters add significant overhead