8 min read

Does TOON Save Tokens on Every Tokenizer? GPT, Claude, Gemini & Llama

Token savings depend on the tokenizer. See how TOON's reductions hold across o200k_base, Claude, Gemini, and Llama vocabularies—and why you should count tokens on your own model.

By JSON to TOON Team

TOON saves tokens on every BPE-based tokenizer — GPT, Claude, Gemini, and Llama included — because it removes structural repetition that all tokenizers charge for. But the exact savings depend on vocabulary size, and accuracy varies sharply by model. Always count tokens on your actual target model before treating the benchmark numbers as gospel.

Why Token Savings Are Universal But Not Identical

Every major LLM API uses a variant of Byte Pair Encoding (BPE) for tokenization. BPE starts from individual bytes, then iteratively merges the most frequent adjacent pair into a new token until a target vocabulary size is reached. At inference time, those merge rules are applied deterministically to split any input text into tokens.

TOON's savings come from a structural reduction, not a tokenizer quirk. In a JSON array of N objects with the same schema, every key is repeated N times — surrounded by double quotes, a colon, and commas. TOON replaces all of that with a single header line: items[N]{field1,field2,field3}:. The per-row token cost collapses to the values alone plus a delimiter. This collapse happens regardless of the tokenizer's vocabulary because the keys themselves are what disappear.

What the vocabulary does affect is the baseline token count for the JSON side of the comparison. A tokenizer with a larger vocabulary can merge multi-character sequences — including some punctuation clusters — into single tokens, which lowers the JSON baseline slightly and narrows TOON's relative advantage. The magnitude of savings varies; the direction does not.

For background on how TOON's tabular block syntax works and why it was designed that way, see our TOON introduction.

Which Tokenizer Did the TOON Benchmark Use?

The official toonformat.dev benchmarks ran 5,016 LLM calls across 209 questions, six formats, and four models. All token counts were computed using OpenAI's o200k_base tokenizer via the gpt-tokenizer npm package.

o200k_base is the tokenizer for the GPT-4o and GPT-5 model families. It has a vocabulary of approximately 200,000 tokens — roughly twice the size of cl100k_base (used by GPT-3.5-turbo and GPT-4). The larger vocabulary means more multi-character sequences, including common English words, merge into single tokens. In English prose, o200k_base averages roughly 4 characters per token.

Using o200k_base as the benchmark tokenizer is a reasonable choice for measuring token-count comparisons when targeting GPT-5-family models. For other models the absolute token counts will differ, though the percentage reduction from TOON should remain in the same general range because the structural savings are proportional to the number of repeated keys, not to how the tokenizer handles individual characters.

For a full breakdown of what the benchmarks measured and how 39.9% average savings splits across data shapes, see our TOON format comparison guide.

The Same Array Across Tokenizers: What Changes and What Stays

The following example uses a small product array to illustrate the structural reduction that applies under any BPE vocabulary, and to show where tokenizer differences show up.

// JSON — keys repeated on every row.
// Every tokenizer charges for "id", "name", "price", "qty" four times.
[
  {"id": "A1", "name": "Widget",  "price": 9.99,  "qty": 120},
  {"id": "A2", "name": "Gadget",  "price": 24.50, "qty": 45},
  {"id": "A3", "name": "Doohickey","price": 4.99, "qty": 300},
  {"id": "A4", "name": "Thingamajig","price":14.99,"qty": 80}
]
// o200k_base estimate: ~85 tokens
// cl100k_base estimate: ~90 tokens  (slightly more; smaller vocab, more splits)
// Llama-3 (32k vocab) estimate: ~95 tokens  (smallest vocab, most splits)

// TOON — keys declared once in the header; rows are pure values.
products[4]{id,name,price,qty}:
  A1, Widget,      9.99,  120
  A2, Gadget,      24.50,  45
  A3, Doohickey,   4.99,  300
  A4, Thingamajig, 14.99,  80
// o200k_base estimate: ~52 tokens  (~39% fewer)
// cl100k_base estimate: ~54 tokens  (~40% fewer)
// Llama-3 (32k vocab) estimate: ~56 tokens  (~41% fewer)
//
// The percentage reduction is similar across all three tokenizers.
// The absolute counts differ; the structural advantage does not.

Notice that the percentage reduction is stable — roughly 39–41% — while the absolute counts shift modestly. As datasets grow to hundreds or thousands of rows, the structural savings dominate further and the tokenizer-vocabulary effect becomes negligible.

For a side-by-side comparison of JSON and TOON token counts across multiple data shapes with the GPT-5 tokenizer, see our JSON vs TOON deep-dive.

Accuracy Varies Sharply by Model — Count Both Dimensions

Token savings are a tokenizer property. Accuracy is a model property. They are independent, and the gap between models on accuracy is far wider than the gap in savings.

The official benchmark tested four models. Overall TOON accuracy across all models was 76.4% at 39.9% fewer tokens — 27.7 accuracy-points per thousand tokens versus JSON's 16.4. But that overall figure masks a dramatic spread by model:

  • Gemini 3 Flash: 96.7%
  • GPT-5 Nano: 90.9%
  • Claude Haiku: 59.8%
  • Grok 4.1: 58.4%

A 38-percentage-point gap between the best and worst model on the same format is not a rounding error — it is a fundamental difference in how well each model was trained to parse TOON's tabular syntax. If you are routing to Claude Haiku or Grok 4.1, you cannot assume the 96.7% figure applies to your workload. Run your own accuracy evaluation before committing TOON to production on those models.

For the Claude-specific picture, including why smaller Claude models struggle with TOON and what that means for cost-accuracy trade-offs, see TOON efficiency with Claude models.

Tokenizer and Model Comparison Table

The following table summarizes what to expect from TOON across the major tokenizer families and the models that use them. Token-savings behavior is structural and consistent; accuracy caveats are model-specific.

Model / tokenizerVocab size / notesExpected TOON token savingsAccuracy caveat
GPT-5 Nano / GPT-4o
o200k_base
~200,000 tokens; ~4 chars/token English; benchmark baseline39.9% average; up to 58.8% on flat tables (benchmark source)GPT-5 Nano: 90.9% accuracy — strong; safe for production with accuracy testing
GPT-3.5 / GPT-4
cl100k_base
~100,000 tokens; ~2× smaller vocab than o200k_base; slightly higher token counts on same textSimilar percentage reduction; absolute token counts ~5–8% higher than o200k_base baselineNot tested in official benchmark; expect lower accuracy than GPT-5 Nano on TOON syntax
Gemini 3 Flash / Gemini 2.5 Pro
SentencePiece-based
~256,000 tokens; SentencePiece BPE; character coverage differs from tiktokenStructural savings apply; exact counts differ from o200k_base baseline; measure with countTokens APIGemini 3 Flash: 96.7% accuracy — highest of all tested models; best current choice for TOON
Claude Haiku / Claude Sonnet
Anthropic tokenizer
Vocabulary details not publicly disclosed; use Anthropic token-counting API for countsStructural savings apply; measure with Anthropic API before assuming benchmark numbersClaude Haiku: 59.8% accuracy — significantly below benchmark average; validate before production use
Grok 4.1
xAI tokenizer
Vocabulary details not publicly disclosed; BPE-basedStructural savings apply; measure independentlyGrok 4.1: 58.4% accuracy — lowest of all tested models; TOON not recommended without fine-tuning
Llama-4
Meta tokenizer
~128,000–256,000 tokens depending on variant; TONL multi-tokenizer support includes Llama-4Structural savings apply; TONL provides tokenizer-aware optimization out of the boxNot in official TOON benchmark; accuracy unknown — test before deploying TOON on Llama models

If you need tokenizer-aware optimization without manual counting, TONL is multi-tokenizer aware out of the box, with explicit support for GPT-5, Claude Sonnet 4.5, Gemini 2.5/3 Pro, and Llama-4.

How to Measure TOON Savings for Your Model

The benchmark numbers are a useful starting point, but the correct way to validate TOON savings for your specific model and dataset is to measure directly. Each major provider exposes a token-counting path:

  • GPT models: Use the tiktoken library with the o200k_base or cl100k_base encoding. Run len(enc.encode(text)) on both the JSON and TOON versions of your dataset.
  • Claude models: Use the Anthropic token-counting API endpoint (POST /v1/messages/count_tokens) — it accepts the same message format as the main API and returns exact counts before you incur inference cost.
  • Gemini models: Use the countTokens method in the Gemini API. It returns the token count for a given prompt without running inference.
  • Llama models (self-hosted): Use the tokenize endpoint on your serving infrastructure, or load the tokenizer directly from the model's tokenizer.json via the Hugging Face transformers library.

Beyond counting, also measure accuracy on a representative sample of your actual queries. The benchmark used 209 questions spanning field retrieval, aggregation, filtering, and structure awareness. For most production retrieval tasks — which skew toward simple field lookups — TOON's 99.6% accuracy on field retrieval is the relevant figure, not the blended 76.4% average.

Use our free converter to generate TOON from your JSON instantly and paste both versions into your preferred token counter.

TONL: When You Need Multi-Tokenizer Guarantees

If you are routing requests across multiple model providers — for example, GPT-5 for reasoning and Gemini for speed — manually verifying token savings for each tokenizer gets tedious. TONL (Token-Optimized Notation Language) was built for exactly this scenario. At version 2.5.2, it explicitly supports GPT-5, Claude Sonnet 4.5, Gemini 2.5/3 Pro, and Llama-4, with tokenizer-aware serialization that maximizes savings on each target.

TONL also adds type hints (u32, str, bool), which cost roughly 20 additional tokens but unlock schema validation, auto TypeScript generation, and a SQL-like query API with indexed lookups under 0.1ms. Even with type hints, TONL saves 32–50% fewer tokens than JSON. For a comparison of when to use TOON versus TONL, see our format comparison guide.

Frequently Asked Questions

Does TOON save tokens on Claude and Gemini, or only on GPT?

TOON saves tokens on every BPE-based tokenizer because the mechanism is structural: removing repeated JSON keys, braces, and quotes reduces character count universally. However, the exact savings depend on the tokenizer's vocabulary size, and accuracy varies sharply by model — Gemini 3 Flash reached 96.7% while Claude Haiku reached only 59.8% in the official benchmark.

Which tokenizer did the official TOON benchmark use?

The official TOON benchmark used OpenAI's o200k_base tokenizer via the gpt-tokenizer npm package. This is the tokenizer used by the GPT-4o and GPT-5 model families. It has a vocabulary of approximately 200,000 tokens — roughly twice the size of cl100k_base — and averages about 4 characters per token in English.

Why does TOON accuracy differ so much between models?

Accuracy differences across models reflect how well each model was trained on TOON-like tabular syntax. Gemini 3 Flash scored 96.7% while Grok 4.1 scored 58.4% on the same data. Token savings are a tokenizer property; accuracy is a model property. You need to verify both on your specific target model before relying on TOON in production.

How do I count TOON tokens for my specific model?

For GPT models, use tiktoken with the o200k_base encoding. For Claude, use Anthropic's token-counting API endpoint. For Gemini, use the countTokens method in the Gemini API. TONL is also multi-tokenizer aware and supports GPT-5, Claude Sonnet 4.5, Gemini 2.5/3 Pro, and Llama-4 natively.

Does a larger tokenizer vocabulary reduce TOON's savings?

A larger vocabulary can merge more multi-character sequences — including some JSON structural glyphs — into single tokens, which slightly narrows the gap between JSON and TOON. But the primary driver of TOON's savings is the elimination of repeated keys across array rows, not the cost of individual punctuation characters. That structural reduction holds under any BPE vocabulary.

Recommended Reading

TokenizerTOONGPT-5ClaudeGeminiLlama