Count tokens for GPT-4o, GPT-4.1, Claude, and Gemini models instantly in your browser. Estimate API costs before sending requests. No data is sent to any server.
Tokens are the units that large language models use to process text. A token is roughly 4 characters or 0.75 words in English, but this varies by language and content type. AI APIs like OpenAI, Anthropic, and Google charge per token, so knowing your token count before making requests helps you control costs and stay within model context limits. This tool uses the same tokenization encodings as the official APIs to give you accurate counts.
Input:
What is the capital of France?
Output:
8 tokens Context used: 0.006% of 128,000 Estimated input cost: $0.000020
What is a token in AI models?
A token is a chunk of text that a language model reads as a single unit. In English, one token is roughly 4 characters or 0.75 words. Common words like 'the' are a single token, while longer or uncommon words may be split into multiple tokens.
Why do token counts differ between models?
Different models use different tokenization encodings. GPT-4o and GPT-4.1 use o200k_base, while GPT-3.5 Turbo and GPT-4 Turbo use cl100k_base. The same text can produce slightly different token counts depending on the encoding used.
How accurate is the token count?
The count for OpenAI models is exact, as this tool uses the same official tokenization encoding (cl100k_base or o200k_base) that OpenAI uses. Claude and Gemini counts are estimates using a compatible encoding since those APIs use proprietary tokenizers.
What is a context window?
A context window is the maximum number of tokens a model can process in a single request, including both your input and the model's output. For example, GPT-4o has a 128,000 token context window. Exceeding this limit will cause the request to fail or earlier content to be truncated.
Is my text sent to any server?
No. All tokenization happens entirely in your browser using a pure JavaScript implementation. Your text never leaves your device.
How is the API cost estimated?
Cost is calculated as (token count / 1,000,000) × price per million tokens for the selected model. Input and output costs use different rates since most APIs charge more for output tokens. Output cost uses the same token count as input as a rough estimate.