AI Token Counter
Estimate token counts and API costs for OpenAI, Anthropic Claude, and Google Gemini models. 100% client-side.
New to this tool? Click here for instructions
How to Use the AI Token Counter
- Paste your text into the input area on the left (or top on mobile). This can be a prompt, system message, document, or any text you plan to send to an AI model.
- Select a model by clicking one of the model chips above the input area. Each chip corresponds to a specific AI model with its own pricing.
- View the results on the right panel. You will see the estimated token count, word count, character count, and the estimated API cost for both input and output.
- Compare costs by switching between models. Click different model chips to instantly see how pricing varies across OpenAI, Anthropic, and Google models.
- Copy the results using the Copy Results button to save the breakdown for documentation or cost planning.
What This Tool Does
This AI token counter estimates the number of tokens in your text for popular large language models from OpenAI, Anthropic, and Google. It provides an instant cost estimate based on each model's published per-token pricing, helping you budget API usage before making actual API calls. The tool runs entirely in your browser — your text is never sent to any server or API endpoint.
What Are Tokens?
Tokens are the fundamental units that large language models use to process text. Rather than reading text character by character or word by word, models like GPT-4o, Claude, and Gemini break text into subword pieces called tokens using a method called Byte Pair Encoding (BPE). A token might be a whole short word like "the" or "cat," a part of a longer word like "un" + "believ" + "able," or a single punctuation mark. For typical English text, one token averages about 4 characters, which means roughly 100 tokens per 75 words. Code, non-English text, and text with unusual formatting may tokenize differently, often producing more tokens per word.
Why Token Counting Matters
Token counting is critical for two reasons: cost management and context window limits. AI APIs charge per token for both input (your prompt) and output (the model's response), so knowing your token count upfront helps you estimate costs before hitting the API. Additionally, every model has a maximum context window — the total number of tokens (input plus output) it can handle in a single request. If your prompt approaches the context window limit, you will need to shorten it or use a model with a larger window. For production applications processing thousands of requests daily, even small differences in token counts can translate to significant cost differences between models.
Supported Models
- GPT-4o — OpenAI's flagship multimodal model. 128K context window. $2.50 input / $10.00 output per million tokens.
- GPT-4o mini — OpenAI's cost-efficient model. 128K context window. $0.15 input / $0.60 output per million tokens.
- Claude Opus — Anthropic's most powerful model for complex tasks. 200K context window. $15.00 input / $75.00 output per million tokens.
- Claude Sonnet — Anthropic's balanced model for most use cases. 200K context window. $3.00 input / $15.00 output per million tokens.
- Claude Haiku — Anthropic's fastest, most affordable model. 200K context window. $0.80 input / $4.00 output per million tokens.
- Gemini Pro — Google's advanced reasoning model. 2M context window. $1.25 input / $5.00 output per million tokens.
- Gemini Flash — Google's speed-optimized model. 1M context window. $0.075 input / $0.30 output per million tokens.
Token Estimation Method
This tool uses a heuristic approximation rather than running an actual tokenizer. It splits text on word boundaries and punctuation, then estimates token count based on word length: short words (4 characters or fewer) count as one token, while longer words are split at roughly every 4 characters. This approach mirrors the general behavior of BPE tokenizers and is typically accurate within 5-15% for standard English text. For exact token counts, use the official tiktoken library for OpenAI models or each provider's API tokenization endpoint. However, for quick cost estimation, prompt length planning, and context window budgeting, this heuristic is fast and reliable. For more text analysis, try the Word Counter for detailed text statistics, the Code Line Counter for source code metrics, or the Base64 Encoder for encoding data before sending it to APIs.