Skip to main content
Kliff

Tokens and cost

What a token is, how model usage is counted, and why an agent's cost grows with every step.

Video coming soon

Models do not read characters or words. They read tokens, and almost everything about model usage is measured in them: how much a model can hold at once, how long a reply can be, and what a request costs. Knowing how tokens add up helps you understand why some tasks cost more than others, and how to keep work lean without cutting corners.

What a token is

A token is a small chunk of text that the model treats as one unit. Before a model reads your prompt, a tokenizer splits the text into these chunks.

There is no fixed rule for where the splits fall, and different models split text differently. As a rough picture:

  • A common English word is often a single token.
  • A long or rare word may be split into several.
  • Spaces, punctuation, and symbols take tokens too.
  • Code often uses more tokens than prose of the same length, because of symbols, indentation, and unusual names.

For example, a line like const userId = req.params.id; is short to read, but each name, dot, and symbol is part of the count. A large JSON file or a long log can be many more tokens than it looks.

Input and output are counted separately

Every model request has two sides:

  • Input tokens: everything sent to the model. That is your message, plus any instructions, earlier conversation, file contents, and tool results the application includes.
  • Output tokens: everything the model writes back.

Providers usually price these separately, and output tokens often cost more per token than input tokens. Many providers also charge less for input they have recently seen, such as the same long instructions sent at the start of each request. Exact prices vary by model and change over time, so check the provider's current list rather than relying on a number you remember.

Why agents use more tokens than chats

Recall that a model keeps no memory between requests. Each request sends everything the model needs again.

In a chat, that means each new message re-sends the conversation so far. An agent goes further: it takes many steps for one task, and every step is a request. A step to read a file sends the conversation plus the file. The next step sends all of that plus the model's next move. So the input grows as the task goes on.

Here is a simplified picture of one small task:

How input grows step by steptext
Step 1  instructions + your message
Step 2  instructions + your message + file A
Step 3  instructions + your message + file A + test output
Step 4  instructions + your message + file A + test output + fix

Each line is billed as input. A task that reads many large files, or runs commands that print long output, costs more than one that stays focused.

Spend tokens where they help

Keeping cost down is not about writing short prompts. A clear, detailed first message usually saves tokens, because the agent wastes fewer steps exploring the wrong thing.

What helps:

  • Point to the right place. Naming the file or folder saves the agent from reading half the repository to find it.
  • Keep output small. Ask for a focused test run or a filtered log instead of the full output of everything.
  • Start fresh for a new task. A long conversation about a finished task is carried into every later request. A new session for unrelated work starts with less baggage.
  • Pick a model to match the job. Larger models tend to be more capable and cost more per token. A smaller, faster model can be the right choice for simple, well defined work.

What does not help: skipping verification to save a few steps. A test run costs tokens, but shipping a broken change costs more.

Key points

  • A token is a chunk of text, often a word or part of one. Code and logs can use more tokens than they look.
  • Usage is counted as input tokens and output tokens, which are usually priced differently.
  • An agent re-sends its growing context at each step, so long tasks cost more than their final answer suggests.
  • Clear instructions and focused output save tokens. Skipping checks does not.