← Back to Blog

What Is a Token? How AI Coding Tools Count and Bill Tokens (2026 Guide)

June 20, 2026 · 8 min read

Lines of source code displayed on a screen with syntax highlighting

The Short Answer

A token is the unit an AI model uses to read and write text. It's not quite a word and not quite a character — it's a chunk of text, usually a few characters long. Every AI coding tool bills you by the token, so understanding what a token is gives you direct insight into why your AI bill looks the way it does.

A useful rule of thumb: 1 token ≈ 4 characters of English text, or roughly ¾ of a word. So 1,000 tokens is about 750 words. Code tends to tokenize a little differently — punctuation, indentation, and symbols each cost tokens — but the 4-characters-per-token estimate is close enough for budgeting.

Why Models Use Tokens Instead of Words

Models don't read characters or whole words — they read tokens, which are produced by a process called tokenization. A tokenizer breaks text into common sub-word pieces. Frequent words like "the" become a single token; rarer or compound words get split into several. The word "tokenization" might become "token" + "ization," for example.

This matters for code because source code is full of things that don't tokenize neatly. A variable named getUserAccountBalance may split into multiple tokens. Whitespace, braces, and semicolons each consume tokens. That's why a 100-line file can be more tokens than you'd guess from its word count alone — code is denser in tokens than prose.

How Tokens Become Your Bill

AI providers price in dollars per million tokens, and they charge separately for input tokens (what you send — your prompt, your code, the conversation history) and output tokens (what the model generates back). Output almost always costs more than input.

Here's how a few 2026 models price it, per million tokens (input / output):

• Claude Opus 4.8: $5 / $25
• GPT-5.5: $5 / $30
• Claude Sonnet 4.6: $3 / $15
• Gemini 3 Flash: $0.50 / $3
• DeepSeek V4 Pro: $0.435 / $0.87

Notice the spread: the most expensive output rate (GPT-5.5 at $30/M) is nearly 35× the cheapest here (DeepSeek V4 Pro at $0.87/M). The model you pick moves your bill far more than any other single factor.

A Worked Example

Say you ask an AI coding tool to refactor a file. You send 6,000 tokens of context (the file plus instructions) and it returns 2,000 tokens of revised code. That's 6K input + 2K output.

With Claude Opus 4.8: 6,000 × $5/M = $0.03, plus 2,000 × $25/M = $0.05, for $0.08 total. With DeepSeek V4 Pro: 6,000 × $0.435/M + 2,000 × $0.87/M ≈ $0.004. Same task, a 20× cost difference, driven entirely by token pricing.

The catch is that this counts one clean pass. Real coding sessions involve back-and-forth, and each turn re-sends the growing conversation as input. That's why long sessions get expensive — the input token count climbs with every exchange.

What This Means for Your Budget

Once you think in tokens, the levers become obvious. Send less context — only the files that matter, not your whole repo. Use prompt caching so repeated context isn't billed at full input price every turn. Match the model to the task — a cheap model for boilerplate, a frontier model only where it earns its rate.

Understanding tokens turns your AI bill from a mystery into arithmetic. To put real numbers on your own project, plug your expected usage into our AI cost calculator and compare models side by side.

Frequently Asked Questions

What is a token in AI?

A token is the unit an AI model uses to read and write text — a chunk usually a few characters long, produced by breaking text into common sub-word pieces. A rough rule of thumb is 1 token ≈ 4 characters of English, or about ¾ of a word, so 1,000 tokens is roughly 750 words.

How many tokens is a line of code?

It varies, but code is denser in tokens than prose because punctuation, indentation, symbols, and long variable names each consume tokens. A 100-line file is often more tokens than its word count suggests. The 4-characters-per-token estimate is a reasonable budgeting approximation.

Why do output tokens cost more than input tokens?

Generating text is more computationally expensive than reading it, so providers price output higher. For example, Claude Opus 4.8 charges $5 per million input tokens but $25 per million output, and GPT-5.5 charges $5 input versus $30 output.

How can I reduce my token costs?

Send less context (only relevant files, not the whole repo), use prompt caching so repeated context isn't billed at full price each turn, and match the model to the task — cheap models for boilerplate, frontier models only where their capability earns the higher per-token rate.

Want to calculate exact costs for your project?