Token Counter for GPT, Claude, Llama
Count tokens for ChatGPT, GPT-4o, Claude, Llama, and Gemini before hitting context limits. Shows per-model token count, character count, and approximate API cost.
| Model | Vendor | Tokens | $/1M input | Cost / call |
|---|---|---|---|---|
| GPT (latest) | OpenAI | 41~est | $5.00 | $0.000205 |
| GPT-5.4 (mid-tier) | OpenAI | 41~est | $2.50 | $0.000102 |
| Claude Opus (latest) | Anthropic | 44~est | $5.00 | $0.000220 |
| Claude Sonnet (latest) | Anthropic | 44~est | $3.00 | $0.000132 |
| Claude Haiku (latest) | Anthropic | 44~est | $1.00 | $0.000044 |
| Gemini Pro (latest) | 39~est | $2.00 | $0.000078 | |
| Gemini Flash (latest) | 39~est | $1.50 | $0.000058 | |
| Llama 3.x (70B, self-hosted) | Meta | 41~est | — | — |
Exact counts (OpenAI): real tiktoken (o200k_base) running in your browser.
Estimates (Claude, Gemini, Llama): chars-per-token heuristic. Expect ±10% on English prose; larger error on code or non-Latin scripts. For exact counts, use each vendor's own API.
Prices are input only. Output is typically 3-5× more expensive and depends on response length. Static prices reflect rates pinned on 2026-05-22. Click Refresh prices to pull live values from OpenRouter.
How to use the token counter for gpt, claude, llama
Paste your prompt or input text. Token counts and approximate input cost update live for each major LLM. Exact counts use the real OpenAI tokenizer (tiktoken). Other vendors use a chars-per-token heuristic because their tokenizers aren't publicly available in JavaScript. Click "Refresh prices" to pull current rates from OpenRouter.
Formula & explanation
Token count = number of BPE tokens the model's tokenizer produces. Cost = (tokens / 1,000,000) × input price per million. Output cost is 3-5x input cost and depends on response length, so it's not estimated here.
Examples
The string "Hello, world!" is 4 tokens in GPT-4o. One "average" English word ≈ 1.3 tokens. One code token ≈ 0.5 words.
Frequently asked questions
- Are these token counts exact?
- For OpenAI models yes — we use the actual tiktoken encoder (o200k_base) running in your browser. For Claude, Gemini, and Llama, no public JavaScript tokenizer exists, so we use a chars-per-token heuristic calibrated against published averages (~3.5 for Claude, ~4 for Gemini, ~3.8 for Llama). Expect ±10% error on those.
- Are the prices current?
- The prices shown by default are pinned to 2026-05-22 when this page was last updated. Click "Refresh prices" to pull live values from OpenRouter, which aggregates current rates across providers. The page falls back to the pinned values if the network call fails.
- Why does the same text produce different counts on different models?
- Each model family uses its own tokenizer. Recent OpenAI models use o200k_base, which is more efficient on multilingual text than the older cl100k_base. Claude, Llama, and Gemini each have their own BPE vocabularies.
- Why doesn't the cost include output tokens?
- Output token count is unpredictable — it depends on how long the model decides to respond. Most APIs charge 3-5x more for output than input, so total cost is roughly (input tokens) × (input price) + (output tokens) × (3-5 × input price). Multiply this tool's number by your expected response ratio.
- Where do the live prices come from?
- OpenRouter (openrouter.ai), which aggregates pricing across LLM providers for routing purposes. They expose a public JSON API at /api/v1/models. We fetch it only when you click the Refresh button — the page makes zero network calls otherwise.
- Does this work offline?
- Yes for the token counts. The tokenizer runs entirely in your browser. The live-price refresh button needs network; without it, the page shows the pinned static prices.
- Why is my Claude token count an estimate?
- Anthropic does not publish their tokenizer as a runnable library. The only way to get an exact Claude token count is to call their API's count_tokens endpoint, which requires an API key and a network round-trip. The heuristic we use is accurate to within ~10% for English prose.
Related developer tools tools
- LLM JSON Schema ValidatorValidate JSON Schemas for OpenAI strict mode, function calling, Anthropic tool use, and Gemini controlled generation. Catch vendor-specific schema errors before shipping.
- JSON FormatterPretty-print, minify, and validate JSON. Detects syntax errors with line numbers and supports nested structures of any depth.
- JSON DiffCompare two JSON values semantically. Ignores key order; shows added, removed, and changed fields with their JSONPath — great for diffing API responses and config files.
- JSON to XML ConverterConvert JSON objects and arrays to well-formed XML. Maps object keys to elements, array items to repeated elements, with optional root wrapper.
- JSON to YAML ConverterConvert JSON to clean indented YAML for Kubernetes manifests, Docker Compose, CI configs, and Helm charts. Preserves nested structures.
- JSON to CSV ConverterConvert JSON arrays to CSV with automatic header detection from object keys. Handles nested values and arbitrary delimiters.