How do I count LLM tokens and estimate API costs?
Paste your text and select a model (GPT-4o, Claude, Gemini, Llama, Mistral, DeepSeek) to see the token count and estimated API cost. The tool uses BPE tokenization, shows context window usage, and lets you compare costs across 19 models from 6 providers. Everything runs in your browser.
Hello, how are you doing today?
Tokens: 8 Cost (GPT-4o): $0.00002 input Context used: 0.006%
LLM Token Counter & Cost Calculator
Count tokens and estimate API costs for GPT-4o, Claude, Gemini, and other LLMs. Uses BPE tokenization (cl100k_base).
Model Pricing Comparison
| Model | Input $/1M | Output $/1M | Context |
|---|---|---|---|
| $2.00 | $8.00 | 1M | |
| $0.40 | $1.60 | 1M | |
| $0.10 | $0.40 | 1M | |
| $2.50 | $10.00 | 128K | |
| $0.15 | $0.60 | 128K | |
| $2.00 | $8.00 | 200K | |
| $1.10 | $4.40 | 200K | |
| $1.10 | $4.40 | 200K | |
| $15.00 | $75.00 | 200K | |
| $3.00 | $15.00 | 200K | |
| $0.80 | $4.00 | 200K | |
| $1.25 | $10.00 | 1M | |
| $0.15 | $0.60 | 1M | |
| $0.10 | $0.40 | 1M | |
| $0.50 | $0.50 | 1M | |
| $0.20 | $0.20 | 524K | |
| $2.00 | $6.00 | 128K | |
| $0.27 | $1.10 | 131K | |
| $0.55 | $2.19 | 131K |
About Token Counting
This tool uses BPE tokenization (cl100k_base encoding), which is the tokenizer used by GPT-4, GPT-4o, and GPT-4.1 models. Token counts for other providers (Anthropic, Google, Meta) are approximations — typically within 5-15% of actual counts.
Pricing reflects publicly listed API prices as of March 2026. Actual costs may vary with batch pricing, prompt caching, fine-tuned models, or volume discounts. Output tokens are estimated using your selected output:input ratio.
What is a token? Tokens are the basic units LLMs process text in. A token is roughly 3-4 characters or ¾ of a word in English. Code, non-English text, and special characters typically use more tokens per character.
Tips & Best Practices
System prompts and tool definitions count toward your context window
The context window isn't just for your messages — system prompts, function definitions, and tool schemas consume tokens too. A complex system prompt with 20 tool definitions can use 3,000-5,000 tokens before the conversation even starts.
Token count varies dramatically between models for the same text
GPT-4 and Claude use different tokenizers. The same 1,000-word essay might be 1,200 tokens in GPT-4 (cl100k) but 1,400 in Claude. Always count tokens with the specific model's tokenizer — estimates based on 'words ÷ 0.75' are unreliable.
Estimate API costs before running batch jobs
Processing 10,000 documents through GPT-4o at $2.50/M input tokens and $10/M output tokens adds up fast. Token-count a representative sample, multiply by your dataset size, and calculate costs before running the full batch.
Long prompts can be used to hide prompt injection attacks
Attackers embed malicious instructions deep in long documents, hoping the LLM follows them. If you're processing user-submitted content through an LLM, be aware that longer inputs provide more surface area for prompt injection.
Frequently Asked Questions
How do LLM token counters calculate tokens from text?
How do I estimate API costs for LLM calls?
Why do different AI models produce different token counts for the same text?
Related Inspect Tools
Word & Character Counter
Count words, characters, sentences, and estimate reading time
Chmod Calculator
Calculate Unix file permissions with an interactive permission matrix
JSON Path Tester
Test JSONPath expressions against JSON data with real-time evaluation
Color Contrast Checker
Check WCAG 2.1 color contrast ratios for AA and AAA accessibility compliance