Token

A token is the unit of text that a language model reads and writes, usually a word or a piece of a word.

A token is a small piece of text, such as a word, part of a word or a punctuation mark. Before a language model reads text, a tokenizer splits it into tokens and turns each into a number. The model then predicts the next token, one at a time, to produce its output. In English, a token is on average about three quarters of a word.

Tokens are the unit in which language models are measured and billed. A model's context window is the number of tokens it can consider at once. Speed is measured in tokens per second, and price in tokens read and written. Long inputs, such as large files or logs, use many tokens and cost more.

An agent spends tokens on every step it takes, including reading the output of the code it runs. A command that prints a long log can fill the context with tokens the agent does not need. Agents that run code in a sandbox therefore trim or summarize output before reading it. Doing work in the sandbox, such as searching files, can save tokens compared with reading everything into the model.