Skip to the content

What is a token? Why AI reads your text in pieces.

Carina Robinson25 NOV 2026 · 3 MIN READ

You type a sentence. The model never sees it as a sentence. Before anything happens, a tokenizer cuts your text into pieces from a fixed list of many thousands, and turns each piece into a number. The model works on those numbers and writes its answer back one token at a time.

What a token looks like

A token can be a whole word, part of a word, a space plus a word, or a single character. Common English words like "the" or "cat" are usually one piece. A word like "unbelievable" is more likely to come out as two or three. A long German compound like "Haftpflichtversicherung" gets cut into several, because the tokenizer has seen it far less often than "the".

Code gets split too: brackets, colons and indents are all pieces the model has to read.

Count them yourself

The Anthropic API has an endpoint that counts tokens without running the model, so it costs nothing to try. This runs with the official anthropic package and an API key.

import anthropic

client = anthropic.Anthropic()

def tokens(text):
    reply = client.messages.count_tokens(model="claude-haiku-5-5", messages=[{"role": "user", "content": text}])
    return reply.input_tokens

for text in ["cat", "unbelievable", "Haftpflichtversicherung", "def run(task):"]:
    print(f"{tokens(text):>3}  {text}")

tokens.py · 7 lines · the count includes a few tokens the API adds around every message, so compare the rows with each other

Try it with a sentence in English and the same sentence in German. Tokenizers learn their pieces mostly from English text, so other languages often need more tokens to say the same thing. Each model family has its own tokenizer, so always count with the model you'll use.

Why tokens matter at work

  • Cost: you pay per token, for what you send and for what comes back. Output tokens cost more: on Claude Haiku 5.5 they are five times the input price at the time of writing.
  • Limits: every model has a context window, the most tokens it can read in one go. A long contract plus a long chat history fills it faster than you'd think.
  • Speed: the answer is written one token at a time. A reply that's twice as long takes about twice as long to arrive.

So "keep it short" in a prompt is not just about style. It's cheaper and faster.

Why models trip over letters

Because the model sees pieces, not letters, questions about letters are oddly hard for it. "How many r's are in strawberry?" asks about something the model never directly saw: it got a token or two, not ten letters. Newer models handle this better, but the reason it was ever a problem is the token.

The same goes for exact word counts, rhymes and reversing text. If a task depends on single characters, let code do it, and let the model decide when to call that code. That's the idea behind an AI agent.

Want to build this yourself?

Build Your First Agent. The first module shows what a model does with your tokens. It's free. The first chapter is free, in your browser.

Start the first chapter
BUILD

Same question, different answer: why AI isn't a calculator.

A language model picks every next word with some chance involved, so the same question can get a different answer. Here's why, a script to see it, and what to do about it at work.

CARINA · 2 MIN READ · 25 NOV 2026

BUILD

What is an AI agent? A model in a loop, in 15 lines of Python.

Strip away the frameworks and an agent is a short loop: ask the model, run the tool it picks, repeat, stop. Here's the whole thing, line by line.

CARINA · 3 MIN READ · 24 NOV 2026