Codebase, JSON & Document Context Token Estimator
Convert words, characters, lines of code, or PDF pages into accurate LLM token estimates and check fit across 32K–1M windows.
Input Parameters
Calculated Output
Primary Result
—
Adjust inputs to recalculate immediately.
BPE Tokenizer Density Rules of Thumb (vs. English Prose)
Punctuation, camelCase identifiers, brackets, and whitespace make code and JSON consume far more tokens per character than prose.
| Content Format | Tokens / Word | Tokens / Char | Tokens / 1,000 Units | Context Window Notes |
|---|---|---|---|---|
| English Prose | ~1.33 tok/word | ~0.25 tok/char | 1,330 tok / 1k words | Optimal BPE compression |
| Source Code (TS/Python) | ~1.75 tok/word | ~0.35 tok/char | 14,000 tok / 1k LOC | Punctuation + indentation heavy |
| Dense JSON / API Payloads | ~2.10 tok/word | ~0.40 tok/char | 400 tok / 1k chars | Keys, quotes & UUIDs inflate tokens |
| Technical PDF Pages | ~1.35 tok/word | ~0.27 tok/char | 450,000 tok / 1k pages | Tables/OCR add extra noise |
Formula & Engineering Methodology
Applies empirically calibrated BPE tokenizer density multipliers matching modern 100k–200k-vocab tokenizers (cl100k/o200k/Llama-3/DeepSeek) across characters, words, lines, and document pages.
est_tokens = quantity * ratio(input_mode, content_type)
pct_128k = (est_tokens / 128000) * 100
pct_200k = (est_tokens / 200000) * 100
single_turn_cost = (est_tokens / 1e6) * model_input_rate_per_m
Variable Definitions
ratio(mode, type): Format-calibrated token multiplier (e.g., 14 tok/line for code, 0.40 tok/char for JSON).pct_128k / 200k: Percentage of standard cloud context limits consumed in a single turn.
Practical Note: Even when a prompt fits inside a 200K–1M window, retrieval precision degrades near the middle ('lost-in-the-middle') and Time-To-First-Token rises linearly/quadratically.
Frequently Asked Questions
Why do JSON and source code consume ~35–60% more tokens per character than English prose?
JSON braces, quotes, colons, UUID hashes, and code indentation fragment into single-character tokens instead of whole multi-letter English word merges.
How does long context affect Time-To-First-Token (TTFT)?
Every prompt turn must prefill all uncached context tokens through every transformer layer before outputting token #1; 100K uncached tokens can add 5–25 seconds of latency.
Should I dump an entire repo into 1M context or use RAG?
For one-off refactors under 100K tokens, full context with prompt caching is fast and simple; for repeated queries across large codebases, AST chunking + RAG is cheaper and higher accuracy.