</>CodeScrub

LLM Token Counter & Cost Calculator

Count tokens. Estimate costs. Visualize boundaries. 100% private.

ModelGPT-4o·128K contextexact
Your Text
0Tokens
0Chars
0Words
$0.00Input cost
Context window
0 / 128,000 tokens< 0.01% used

128,000 tokens remaining for the response.

Cost estimate
500
08,192 max
$0.00Input
$0.0050Output
$0.0050Per request
At 1,000 requests/day: $5.00/day, $150.00/month
Token boundaries

Type something to see token boundaries.

Ctrl + Enter re-countCtrl + Shift + C copy count
Ad space · token-counter-mid

What Are LLM Tokens?

Tokens are the subword units that language models actually process — not characters, not words. A single token is roughly four English characters or about three-quarters of a word, but the exact breakdown depends on the model. The same text produces different token counts across GPT, Claude, and Gemini because each one uses a different tokenizer, so a payload that fits comfortably in one model may overflow another.

Exact vs Estimated Counts

For OpenAI models this tool uses gpt-tokenizer, a JavaScript port of OpenAI's tiktoken library, so the counts match what the API bills. For Claude, Gemini, and Llama we run a shape-aware character-based estimate that lands within about 5–10% of the real value. For precise Anthropic counts, use the count_tokens endpoint.

How Token Pricing Works

Every major LLM API bills separately for input tokens (what you send in the prompt) and output tokens (what the model returns). Output tokens typically cost 2–5× more than input, so a small prompt with a long response can cost far more than a long prompt with a short response. Knowing the input token count up front lets you estimate the whole call before spending anything on it.

Tips to Reduce Token Usage

  1. Use TOON format instead of JSON for structured data in prompts — try the JSON ↔ TOON Converter to see the savings on your specific payload.
  2. Trim unnecessary whitespace, comments, and multi-shot examples from system prompts. Every example is being paid for on every request.
  3. Prefer concise instructions: "Respond in three bullet points" beats a paragraph of formatting rules.
  4. Enable prompt caching (supported by both Anthropic and OpenAI) for repeated system prompts — the cached tokens are billed at a fraction of the normal input rate.
  5. Pick the right model. Don't use GPT-4o for tasks that GPT-4o mini handles well; don't use Claude Opus for anything Haiku can answer.

Privacy

Your text never leaves your browser. Tokenization runs entirely client-side using gpt-tokenizer — no data is sent to any API or server.