Developer & Tech

LLM Token Counter

What this does

Estimate how many tokens a piece of text consumes using character-based and word-based heuristics, plus an optional cost line.

Enter your details

Runs in your browser

Calculator inputs

Using the llm token counter

  1. 01

    Paste your text

    Prompts, system messages, retrieved context; anything destined for a model.

  2. 02

    Optionally set pricing

    Your provider’s $/Mtok turns counts into dollars for budgeting loops and batches.

Why estimates suffice (and when they don’t)

For capacity planning and cost ballparking, ±20% rarely matters. It matters enormously at context-window boundaries: a request estimated just-under might actually overflow. For exact limits near the edge, run the provider’s real tokenizer.

What inflates token counts

  • Code and JSON; dense symbols tokenize poorly
  • Non-English scripts; some languages run 2–3× chars/token
  • Whitespace-heavy formatting; indentations are tokens too
  • Repeated boilerplate; system prompts bill every single call

The math behind this calculator

tokens ≈ ⌈characters ÷ 4⌉ alt: words ÷ 1.3 cost = tokens ÷ 1,000,000 × $/Mtok

English prose averages roughly four characters per token under common BPE tokenizers (OpenAI guidance), so characters ÷ 4 gives a quick upper-bracket estimate. The word-based alternative (words ÷ 1.3) cross-checks it; disagreement signals unusual content like code or heavy punctuation where real tokenizer output will diverge.

Assumptions & limitations

  • Heuristic ~4 chars/token named and approximate; real tokenizers vary.
  • Non-English text and emoji consume more tokens per character.
  • Word estimate assumes ~1.3 tokens per English word.

Worked example

The pangram “Pack my box with five dozen liquor jugs.” repeated ten times is exactly 400 characters; about 100 tokens, costing $0.000300 at $3/Mtok.

Frequently asked questions

How accurate is characters ÷ 4?
Within roughly ±20% for typical English prose. Code, multilingual text and emoji can deviate far more; treat it as a planning heuristic.
Do I pay for input and output tokens separately?
Yes, usually at different rates. Use this tool for inputs and the API cost calculator for combined call economics.
Why show two different estimates?
Character-based suits prose; word-based handles punctuation-heavy text better. Agreement builds confidence; divergence flags odd content.

Related calculators