Offline LLM BPE Token Counting & Prompt Cost Optimization Guide
Count exact o200k_base and cl100k_base BPE tokens offline, visualize token boundary segments, prune null JSON fields, and cut prompt API costs locally.
Use an offline BPE token counter to budget LLM prompt cost before making paid API calls. DataTo lazy-loads gpt-tokenizer inside local Web Workers for exact o200k_base vs cl100k_base tokenizer counts (plus calibrated Claude and Gemini estimates), lets you visualize BPE token segments locally, and pairs with JSON Token Optimizer to strip null fields from JSON and slash LLM tokens without leaving valid JSON.
How o200k_base vs. cl100k_base BPE tokenization works offline
Byte-Pair Encoding (BPE) merges frequent character sequences into subword IDs, which is why punctuation, repeated JSON field keys, and leading spaces affect prompt bills far differently than plain word counts. Comparing o200k_base vs cl100k_base tokenizers shows how GPT-4o / o3's 200k vocabulary compresses JSON syntax and multilingual text tighter than GPT-4 / 3.5's 100k vocabulary.
In DataTo LLM Token Counter, gpt-tokenizer computes exact token counts locally for o200k_base and cl100k_base with zero network calls, while reporting transparent, clearly labeled estimates for Claude 4 / Sonnet (~1.07x o200k) and Gemini 2.5 / 3 (~1.03x o200k) alongside context-window usage percentages and estimated input pricing per 1M tokens.
| Model Profile | Encoding / Method | Context Window | Est. Input Rate / 1M |
|---|---|---|---|
| GPT-4o / o3 | o200k_base (exact BPE) | 128,000 tokens | $2.50 |
| GPT-4 / 3.5 | cl100k_base (exact BPE) | 128,000 tokens | $10.00 |
| Claude 4 / Sonnet | claude-bpe (est. ~1.07x o200k) | 200,000 tokens | $3.00 |
| Gemini 2.5 / 3 | sentencepiece (est. ~1.03x o200k) | 1,000,000 tokens | $1.25 |
3-stage prompt reduction: Null Pruning, TOON, and Token Segments
Start with JSON Token Optimizer when downstream tools still require valid RFC 8259 JSON: enabling stripNulls, stripEmptyArrays, and minify deletes bloated null keys, empty [] arrays, and indentation whitespace cleanly.
For read-only RAG records or prompt tables, convert JSON, CSV, or YAML into TOON to fold repeated object keys into a single header, then enable compareToon and showTokenSegments in LLM Token Counter to inspect decoded BPE token boundaries (up to 5,000 segments) and exact JSON-vs-TOON savings side by side.
// Before (formatted with null/empty clutter)
{
"requestId": "req_901",
"debugTrace": null,
"warnings": [],
"items": [{ "sku": "PRO-01", "qty": 2, "notes": null, "tags": [] }]
}
// After JSON Token Optimizer (valid minified JSON)
{"requestId":"req_901","items":[{"sku":"PRO-01","qty":2}]}Worker-isolated BPE tables with zero prompt exposure
Pasting unpublished system prompts, internal RAG contexts, or fine-tuning datasets into hosted web tokenizers exposes proprietary copy to third-party servers. DataTo isolates large BPE rank tables inside lazy Web Workers (keeping landing pages lightweight and running in Airplane Mode) and pairs directly with JSONL Validator to flag any dataset line exceeding maxTokensPerLine.
Tools used in this guide
LLM & TOON →Measure exact o200k_base and cl100k_base BPE tokens, context window share, API cost estimates, and TOON savings offline.
JSON Token OptimizerStrip null properties, empty arrays, and whitespace from API JSON payloads to cut LLM token costs while staying 100% valid JSON.
JSON to TOONShrink JSON arrays into Token-Oriented Object Notation (TOON) to cut GPT-4o and Claude prompt tokens up to 60%.
CSV to TOONTransform CSV or TSV spreadsheets into schema-declared TOON blocks with typed numbers and booleans for LLM prompts.
YAML to TOONCompress Kubernetes manifests, OpenAPI specs, and YAML configs into compact TOON for ~42% smaller LLM prompt payloads.
JSONL ValidatorAudit every JSONL line for syntax errors, OpenAI ChatML role alternation, missing assistant turns, and per-line BPE token limits.
Related formats
Related Comparisons
Frequently asked questions
Are GPT-4o and GPT-4 token counts exact in DataTo LLM Token Counter?
Yes. DataTo uses gpt-tokenizer with official o200k_base and cl100k_base vocabularies locally in Web Workers, while Claude and Gemini values are explicitly labeled as calibrated estimates.
When should I use JSON Token Optimizer instead of JSON to TOON?
Use JSON Token Optimizer whenever downstream code or strict schemas still require valid JSON; use JSON to TOON when maximizing prompt token savings on uniform arrays fed directly to an LLM.
Does LLM Token Counter crash on special strings like <|endoftext|> in datasets?
No. DataTo configures disallowedSpecial: new Set() so literal special-token strings inside prompts or fine-tuning corpora count safely without throwing errors.
Authoritative References
More engineering guides
Compare GPT-4o o200k_base BPE token counts across formatted JSON, minified JSON, YAML, CSV, and TOON—plus how TOON cuts prompt array tokens 40%–60%.
OpenAI Batch API JSONL: Unwrapping, Sharding & Validation GuidePrepare OpenAI Batch API JSONL files locally: unwrap nested JSON arrays, deduplicate lines, split shards into ZIP archives, and flatten results to CSV.
OpenAI & Anthropic Fine-Tuning JSONL Dataset Preparation GuideFormat, convert, validate, deduplicate, and shard ChatML JSONL fine-tuning datasets from CSV, Alpaca, ShareGPT, or Parquet locally in browser RAM.
Convert HuggingFace Parquet Files to JSONL & CSV Without PythonConvert HuggingFace Parquet shards to JSONL, JSON, or UTF-8 BOM CSV locally in browser RAM using hyparquet and sql.js WASM—zero Python or uploads required.