Skip to content

Whitespace and Formatting Cost

Put the same content in two forms — pretty-printed and minified, markdown and plain — and see the estimated token difference and what it costs per month.

Estimated token difference, A minus B
+34

Version A is 36.2% larger than version B. At 100,000 requests a month: $10.20.

Version AVersion BDifference
Estimated tokens946034
Characters21214765
Whitespace characters66165
…of which is indentation36036
Newlines10010
Punctuation and syntax65650
Monthly input cost, version A
$28.20
Monthly input cost, version B
$18.00
Difference per request
34 tokens
Difference per month
$10.20
Difference per year
$122.40

Estimated, not tokenized. Token figures here come from an approximation running in your browser: no tokenizer vocabulary is downloaded, because a real one is megabytes and nothing on this page fetches anything. It imitates how a byte-level BPE splits text — words, digit groups, punctuation runs, whitespace runs — but it has no merge table, so treat it as a planning number. The authoritative count is the usage object on a real API response.

Both columns run through the same estimator, so a systematic bias in it partly cancels in the difference. Trust the direction and the rough size of the gap; do not quote the absolute token counts as if they came from a tokenizer.

What this assumes: The two versions are assumed to be the same content — nothing here checks that, and a comparison where B quietly says less is not a formatting saving, it is a shorter prompt. The monthly figure counts input tokens only, at the price you typed, on the assumption the prompt is sent whole on every request. If this text is a cached prefix, the saving is at your cached rate instead, which is much smaller.

Formatting is not free, and the reason is mechanical rather than mysterious. Tokenizers split on whitespace and punctuation before any merging happens, so every newline, every run of indentation and every ** is a piece the model is charged for. Pretty-printed JSON is the clearest case: the data is identical to the minified form and the braces are in the same places, but the indentation and line breaks are pure structure a model does not need in order to parse it.

The arithmetic that decides whether you should care has one term people forget. A saving of d tokens on a prompt sent R times a month at price P per million is d × R × P / 1,000,000. Forty tokens is nothing. Forty tokens on every request of a service handling two million requests a month is eighty million tokens a year, and that is a line item. Meanwhile the same forty tokens on a batch job that runs nightly is not worth the pull request. The volume field above is doing all the work in that judgement.

Two honest counterweights. First, formatting sometimes buys accuracy: markdown headings and numbered lists genuinely help a model find the instruction it needs in a long prompt, and if stripping them costs you one bad answer in a hundred, no token saving repays it. Structure that separates sections earns its keep; structure that decorates does not. Second, if the block is a stable prefix that gets cached, you are paying the cached rate for it, so the saving shrinks by whatever the discount is — and changing it invalidates the cache once. The formatting worth removing is the formatting nobody, human or model, was reading.

Whitespace and Formatting Cost · Multigrid