An LLM token counter does more than estimate spend. Counted separately, input (prompt) tokens and output (generated) tokens tell you how much work the inference engine does in each of its two phases: prefill processes the whole prompt and produces the first token, and decode generates the rest one token at a time. Put those two counts next to measured latency and you can see whether a request is slow because its prompt is long or because its answer is long. The two phases also scale differently: prefill scales with tensor parallelism, while decode does best on a single GPU or tuned pipeline parallelism.
How an LLM Token Counter Works, and What a Local Count Misses
A token counter runs the model’s tokenizer over your text and counts the tokens it produces. Hugging Face Transformers supports three subword algorithms, byte pair encoding (BPE), Unigram and WordPiece, which split text into units somewhere between words and characters so that common words stay whole and rare words break into pieces. Llama models use BPE, T5 uses Unigram and BERT-family models use WordPiece. OpenAI’s tiktoken works the same way: give it a string and an encoding such as cl100k_base and it returns the list of tokens. The tiktoken cookbook also notes that different models use different encodings. Our practical guide to how tiktoken counts tokens walks through the code.
In a serving engine, vLLM’s input preprocessor tokenises the prompt and returns prompt_token_ids.
Local counters miss several kinds of input beyond plain text. OpenAI’s documentation says local tokenizers like tiktoken handle plain text but not images or files, that tools and schemas add tokens that are hard to count locally, and that model-specific behaviour such as reasoning or caching can change tokenisation. Its count endpoint includes formatting tokens for message roles and boundaries that never appear in the text you tokenise yourself. Even OpenAI’s own message-counting recipe is described as “an estimate, not a timeless guarantee”. Anthropic’s endpoint counts messages, system prompt and tools together, under the tokenizer of the model you name. Google’s Gemini documentation counts system instructions and tools as input, and charges 258 tokens for an image of 384 pixels or less in both dimensions.
Output counts have the same problem. OpenAI reports output usage that includes every generated token, not only the visible text, and the number of non-visible formatting tokens varies by model and response shape. For attribution, we would trust the counts the engine or provider reports per request and treat a local recount of visible text as a rough check.
Input Tokens Set Prefill Work; Output Tokens Set the Number of Decode Steps
The two counts measure different kinds of work. Prefill processes all prompt tokens in parallel and is compute-bound, while decode processes only one token per request at a time and is memory-bound. The hardware reasons behind that split (high-reuse matrix multiplications against weight and KV-cache streaming) belong to the inference engine layers and are covered there. Why a GPU’s compute rating says little about decode speed is the subject of GFLOPS versus inference latency.
For a token counter, the useful result is that prefill time is predictable from token counts. The authors of A Systematic Characterization of LLM Inference on GPUs (arXiv, 2025) measured prefill job completion time against the number of uncached input tokens on Qwen2.5-7B, Qwen2.5-32B and Llama-3-8B in vLLM. They found Pearson correlations of 0.971, 0.991 and 0.977, well approximated by JCT ≈ a + b × n_uncached. The word “uncached” matters. Prompt tokens whose KV entries are already stored skip prefill, which is where a radix cache earns its keep, so the input count that predicts prefill cost is the uncached share and not the raw prompt length.
Decode behaves differently. The same study found per-step decode latency largely stable and independent of input length. A 2026 arXiv paper on task planning for edge LLM inference states the consequence as a latency model: per-token decode time is approximated by memory bandwidth, and total latency for o output tokens is T ≈ T_prefill + o × T_decode.
Why Token Count Drives Latency and Cost, Not Just the Bill
Databricks gives the same model in operational terms: latency = TTFT + TPOT × the number of tokens generated, where time to first token (TTFT) covers processing the prompt and time per output token (TPOT) is the decode speed each user sees. vLLM’s documentation computes per-request TPOT as (end-to-end latency − TTFT) / (number of output tokens − 1), which takes the prefill term out of the decode figure.
On a hosted API the link from token count to cost is direct, since providers charge a fixed price per token. The arXiv 2025 characterisation found total energy almost flat as input length rose from 16 to 2,048 tokens with output fixed at 256, but linear in output length at roughly 1.72 J per generated token (R² = 0.999). Capacity behaves the same way: goodput, the request throughput that still meets both TTFT and TPOT targets, sets serving cost, and raising it on fixed hardware lowers cost per query. Your token mix therefore shapes how many requests a GPU can serve within your latency targets.
That makes cost per request, split into tokens-in and tokens-out, a better optimisation target than total cloud spend. The same per-request cost question applies to LLM features in AI infrastructure and production SaaS deployments. For turning counts into a per-request estimate before deployment, see the LLM cost calculator for inference cost per request.
Is My Latency Coming from the Prompt or from the Generation?
Which one dominates depends on where your input length sits relative to a crossover. In the arXiv 2025 characterisation, Qwen2.5-7B with output fixed at 128 tokens spent most of its latency in decode at short inputs. Past roughly 2,000 input tokens, prefill took over as the dominant term. That figure comes from one model and one configuration. The study reports that a crossover of this kind appeared consistently across the models and workloads it covered, not that it sits at the same input length.
This crossover explains why the published rules of thumb seem to contradict each other. OpenAI’s latency guide gives a vendor heuristic for its API: cutting 50% of output tokens may cut about 50% of latency, while cutting 50% of the prompt may improve latency by only 1–5%. Databricks found that in MPT models, 512 extra input tokens added less latency than 8 extra output tokens. Workloads differ, though. The Sarathi-Serve paper (OSDI 2024) reports median prompts of 1,730 tokens for a ShareGPT conversation trace and 7,059 for an arXiv summarisation trace. A summarisation or retrieval-heavy service can sit past the crossover, where the prompt is the term to work on.
There is a third case that per-request counts alone will not show. On a shared server, other requests’ prefill work slows a request’s decode. The TaiChi paper (arXiv, 2025) defines interference intensity as the prefill tokens computed during a decode request divided by that request’s output length. It found TPOT linear in that intensity (R² = 0.99), rising by about 0.2 ms per unit in its setup. So a request with a short prompt can still show a poor TPOT because of other users’ long prompts.
Which Lever Moves Which Regime
| Regime | What the counters show | Levers that move it |
|---|---|---|
| Decode-bound | Output tokens high; decode time dominates end-to-end latency | Generate fewer tokens, for example shorter output field names; at low batch sizes, quantise weights so less data moves per token; for decode-dominant work, single-GPU execution was optimal in the arXiv 2025 study |
| Prefill-bound | Uncached input tokens past the crossover; TTFT dominates | Trim the prompt; reuse cached prefixes so fewer tokens need prefill; tensor parallelism scaled prefill in the same study |
| Interference-bound | Short prompts but high TPOT under load; many concurrent prefill tokens per output token | Chunked prefill, which bounds per-iteration latency regardless of prompt length; tune chunk size, since larger chunks help TTFT but increase interference |
Attributing Latency to Token Counts Before Optimising
The counters you need are already exposed in vLLM. vllm:prompt_tokens_total and vllm:generation_tokens_total count prompt and generated tokens. Per-request histograms record input and output token counts, along with TTFT, TPOT, prefill time and decode time. One caution: vLLM measures TTFT from when the frontend first receives the request. NVIDIA’s NIM documentation likewise says TTFT generally includes queuing, prefill and network latency.
A workable order of operations:
- Collect per-request input and output token counts from the engine or the provider’s usage fields, not from a local recount.
- Collect TTFT (or prefill time) and decode time for the same requests.
- Fit prefill time against uncached input tokens, and decode time against output tokens; the arXiv 2025 results show linear prefill and stable per-step decode.
- Split each request’s latency into its prefill share and decode share, then aggregate by endpoint or feature.
- Check the residual. Latency that neither fit explains (queuing, host-side work, network) is not a token problem, and the inference engine layers are where to look next.
- Only then pick the lever from the table above.
This is the profile-first habit applied to LLMs. Rules like “prompts don’t matter” or “always use tensor parallelism” only make sense in a particular context, and the token-attributed profile is that context. If you compare results across tools, check that their definitions match. Some phase-aware evaluations leave tokenisation and detokenisation out of their timings entirely, and NVIDIA advises comparing results only when definitions align. Reading published numbers is a separate skill, covered in how to read an LLM inference benchmark.
Why the Same Text Gives Different Token Counts on Different Models
Token counts are tied to one tokenizer, so they do not carry over between models. Anthropic’s token-counting documentation says the tokenizer introduced with Claude Opus 4.7 counts a prompt roughly 30 percent higher than earlier models, with the exact increase depending on content. Databricks cites Anyscale’s finding that Llama 2 tokenisation runs about 19% longer than ChatGPT’s for the same input. NVIDIA makes the practical point: two models with similar tokens per second may not be equivalent, because their tokens represent different numbers of characters. When you switch models, recount, and convert throughput to characters before comparing.
Language shifts counts further. Language Model Tokenizers Introduce Unfairness Between Languages (2023) found that the same text translated into different languages can differ in token length by up to 15 times. That changes cost, processing time and how much fits in the context window.
A count is not even unique for one model and one string. Tokenization Multiplicity Leads to Arbitrary Price Variation in LLM-as-a-service (arXiv, 2025) showed models producing the same output string with different tokenisations, mainly in non-English output. In one example the identical German output came to 26 tokens for one user and 28 for another, making it 7.7% more expensive. Where multiplicity occurred, the gap reached up to 15%. For reconciling a bill against your own token estimates, it is a reason to leave a margin.
FAQ
How Much Is 1,000,000 Tokens?
Google’s Gemini documentation says 100 tokens is about 60–80 English words. By that ratio, a million tokens is roughly 600,000–800,000 English words. Other tokenizers and languages will give different ratios.