compression with a quality contract
Token Economics · Module 1 of 3 ~4 min read

Fundamentals — what a token is

In this module
  • What a token is — Byte-Pair Encoding, and the anatomy of one.
  • Why JSON, logs and code cost roughly the tokens of prose.
  • Why tokenizers aren't interchangeable — and can shift under you.
  • Where the tokens actually go in a single agent request.

What a token actually is

A token is not a character and not a word. It is a subword unit — the atomic chunk a model reads and predicts. Modern models build their vocabulary with Byte-Pair Encoding (BPE): start from individual bytes, then greedily merge the most frequent adjacent pair over and over until you hit a target vocabulary size. Frequent words collapse into one token; rare words fall back to a handful of subword pieces. There is no <unknown> — every possible string is representable, in any language.

RAW STRING (a tool result) {"status":"ok","rows":2} BPE tokenizer 13 TOKENS — STRUCTURE COSTS EXTRA {" status ":" ok "," rows ": 2 } Only ok and 2 are signal. The braces, quotes and keys are pure overhead — and you pay for every one. CHARACTERS PER TOKEN — DENSITY VARIES BY CONTENT ~4.0 English prose 100 tokens ≈ 75 words. The efficient case. ~2.5 Source code camelCase, operators & indentation split hard. ~2.0 JSON / logs Punctuation-dense. The same bytes cost ~2× the tokens.

Three consequences fall straight out of how BPE works, and they drive the whole course:

Where the tokens go — anatomy of one request

Here is where most cost surprises come from. A single agent turn is not "the user's question." The API is stateless, so every turn re-sends the entire working set. A typical request, before the model has read a single word of your actual task, already carries:

One request to the model — token budget Widths ≈ proportions commonly seen in tool-heavy agents. The query you care about is the sliver on the right. System prompt Tool schemas Message history Tool results persona, rules every tool's JSON schema — often the biggest block all prior turns, resent verbatim ← your query A 5-server tool setup can spend ~55,000 tokens before the task is read.

The biggest, most-overlooked sources of waste, with the hardest public numbers we have:

Key takeaways
  • A token is a BPE subword unit; structured text (JSON, code, logs) costs ~2× the tokens of prose — and agents live in that expensive regime.
  • Count tokens with the target model's tokenizer; they're neither portable across families nor fixed within one.
  • Most of an agent request is scaffolding (system prompt, tool schemas, history, stale tool results) — not your task. That gap is where compression lives.