“Send me the token.” “We ran out of tokens.” “It’s a token on Ethereum.”

Three sentences, three unrelated things, one word. Add the two older meanings from linguistics and compilers and you have five. Anyone building with AI agents runs into most of them in the same afternoon, because an agent spends tokens to call an API with a token.

They share one idea: a token is a small thing that stands in for something else. What it stands in for is where they part ways. Each section below has a short animation. They play as you scroll, and the dots let you step through them yourself.

A pass you show at the door

A security token stands in for you. You log in once, the server hands you a string, and from then on the string is shown instead of your password.

The most common shape is a JWT, a JSON Web Token.

eyJhbGciOiJIUzI1NiIs….eyJzdWIiOiJrcmlzdG9m….ZWm8JIm2xPKMBiD3BT1q…
header{ "alg": "HS256", "typ": "JWT" }
payload{ "sub": "kristoffer", "scope": "read:posts", "exp": "09:00" }
signatureHMAC-SHA256(header + "." + payload, secret)
08:15  signature matches → 200 OK 09:01  same string, expired → 401
  1. A security token looks like noise. It is one string, sent along with every request.
  2. Two dots split it into three parts.
  3. The first two are only base64. Anyone holding the token can read them.
  4. The third is a signature. The server recomputes it with a secret only it knows, and a match means nobody changed a byte.
  5. The token carries its own expiry. An hour later the same string opens nothing.

Two things are worth remembering from that.

  • It is signed, not encrypted. Anyone who gets hold of the token can read what is in it. Never put a secret in the payload.
  • Whoever holds it is you. The server does not ask how you got the string. That is why these expire, and why this is the one kind of token that must never end up in a chat, a log or a screenshot.

Not every security token is a JWT. Many are opaque random strings that the server looks up in a database. The role is the same: a stand-in for a login.

A piece of text with a number

A language model’s token stands in for a fragment of text. Models do not read letters or words. A tokenizer cuts the text into pieces from a fixed vocabulary and hands over the piece numbers.

English 8 tokens
The791 tokenizer47058 splits41567 unbelie40037vably89234 long1317 words4339.13
Norwegian 14 tokens
Token3404is285ering4776en268 del1624er261 opp4083 us603ann1036syn20960lig7864 lange53387 ord6141.13
  1. To you this is a sentence: six words and a full stop.
  2. The tokenizer cuts it into pieces it has seen often. Common words survive whole. “Unbelievably” does not.
  3. Each piece is swapped for a number. This list of numbers is all the model ever sees.
  4. The same sentence in Norwegian is 14 tokens instead of 8. Models read, remember and bill by the token, so the language you write in changes the price.

Those are real numbers from GPT-4’s tokenizer. Other models cut differently, but the consequences are the same everywhere.

  • Tokens are the unit of everything. Context windows, rate limits and invoices are all counted in them.
  • A token is not a word. In English it averages about three quarters of one. Rare words, names, code and most other languages cost more.
  • It is not a secret. The vocabulary is public, and the same text gives the same tokens every time.

A row in a shared table

A blockchain token stands in for value or ownership. The surprise is where it lives: not in your wallet. The wallet holds a key. The token is an entry in a ledger.

Alice0xA1…9f 10070
signed by 0xA1…9ftransfer(0xB0…2c, 30)
Bob0xB0…2c 2050
#1041←#1042←#1043 · transfer
  1. A blockchain token is not a thing you hold. It is a number next to your address, in a table that thousands of computers keep a copy of.
  2. To send 30, Alice signs a message saying so. Her private key is the only proof of ownership there is.
  3. The network puts the message in a block, and every copy of the table adds that block.
  4. Now the table says 70 and 50. Nothing travelled anywhere. Everyone agrees on new numbers.

A fungible token like a stablecoin is a balance: a number per address. A non-fungible one turns the table around, and maps one item to the address that owns it.

Either way, copying the token is meaningless. There is nothing to copy. What you can lose is the key that signs for it.

One occurrence of a word

This is the oldest of the five. In linguistics a token is one occurrence of a word in a text, as opposed to the word itself, which is a type.

tokens 8
a1rose2is3a4rose5is6a7rose8
types 3
a×3rose×3is×2
  1. A linguist's token is one occurrence of a word. This line has eight.
  2. Colour the repeats, and there are only three different words in it.
  3. Those are the types. Eight tokens, three types: the ratio is a rough measure of how varied a text is.

It sounds like a footnote, but it is the meaning the AI one grew out of. Counting occurrences is how language was first turned into statistics, and a tokenizer is the same idea with smaller pieces.

The smallest unit of code

A compiler’s token stands in for a slice of source code that means something. Before a program can be understood it is cut into keywords, names, operators and literals. That step is the lexer.

compiler 13 characters5 tokens
constkeyword·xidentifier·=operator·10number;punctuation
GPT-4 6 tokens
const1040 x865 =284␣22010605;26
  1. A compiler reads source one character at a time. To it, this line is 13 characters.
  2. The lexer groups them into the smallest units that mean something, and throws the spaces away.
  3. Each token gets a type. From here on the parser only reads the types.
  4. Hand the same line to GPT-4 and it is six tokens, not five. One of them is a space the compiler threw away.

The last step is the one to keep. The same thirteen characters were cut by two tokenizers into two different sets of tokens, and neither is wrong. A token only means something to the system that cut it.

Side by side

Stands in for Made by If someone copies it
Security You, logged in The login server They are you until it expires
Language model A fragment of text The tokenizer Nothing. The vocabulary is public
Blockchain Value or ownership A contract on a ledger Nothing. Only the key can move it
Linguistics One occurrence of a word Whoever wrote the text Nothing
Compiler A meaningful slice of code The lexer Nothing

Only one row is a secret. That is the practical point of knowing the difference: when a tool, a colleague or an AI agent asks for “the token”, the first question is which row it is on.

Look inside one

Here is the token from the first animation. Change a character in the payload, or paste one of your own from a test system.

Decoded in your browser. Nothing is sent anywhere, and the signature is shown, not checked: checking it takes the secret.

The header and payload opened without a key. That is the “signed, not encrypted” part, seen first hand.

Further reading

This post replaces Token Explorer, a small site that used to live at token.kristoffer.dev. That address now lands here.