Runoob Tutorial ArchiveEnglish

Token

Token

Have you ever wondered how AI understands your text when you ask Deepseek, Doubao, Qwen, ChatGPT, or Claude a question?

The core of the answer is a concept calledTokenwhich is calledToken in ChineseUnderstanding Token is the first step into the world of AI.

What is a Token?

Original prompt (Chinese, left untranslated)

Token (词元) = AI 能理解的最小文本单位

We can understand it as: text fragments in the AI world or fuel in the AI world.

Just as humans understand meaning by words when reading, AI does not process text character by character—it first cuts the text into pieces, and each piece is called a Token.

INPUT TEXT "ChatGPT is amazing" TOKENS Chat G PT is amaz ing Total 6 tokens

** A good analogy: **

Imagine an article as a pizza; you wouldn't swallow the whole thing, nor would you grind it into powder—instead, you cut it into slices, and each slice is a Token. This is how AI consumes text: chunking, understanding, and digesting.

A Token is finer than a word but coarser than a letter; it is a flexible intermediate unit.


What does a Token look like?

The segmentation method varies greatly depending on the text.

Common words are one Token, complex words are broken down, and punctuation also counts as a Token.

English sentence

"Hello, world!"

Hello

→

,

→

world

→

!

Total

4

Tokens

Complex English word

"unbelievable"

un

believ

able

Common

3

Tokens — long words will be split

Chinese sentence

"Hello, world!"

Hello

,

World

!

Total

4

Tokens — Chinese characters consume more Tokens per character


What is the difference between Tokens and characters/words?

Many people think Token = word, but actuallyIt is not entirely.

Token division follows a special algorithm (such as BPE, Byte Pair Encoding), and the results are sometimes intuitive and sometimes unexpected:

Text Token Count Description
cat 1 Common words, directly one Token
unbelievable 4 un+believ+able+ …
ChatGPT 3 Chat+G+PT
你好 Approx. 2-3 Chinese usually consumes more Tokens than English

Conclusion:Tokens are a flexible intermediate unit, finer than words but coarser than letters.

Finest granularity

Character / Letter

Granularity

A single letter or Chinese character

Example

H, e, l, l, o

Whether AI is used

❌ Too fine, low information density

Analogy

Grinding pizza into powder

✦ Actual AI usage

Token

Granularity

Roots, short words, character combinations

Examples

Hello / Chat·G·PT / un·believ·able

Whether AI is used

✅ Efficient, balanced information density

Analogy

Cut the pizza into appropriate bite-sized pieces

Coarsest granularity

Word / Sentence

Granularity

Full word or sentence

Example

Hello, unbelievable

Whether AI uses

❌ Too coarse, inflexible processing

Analogy

Take a whole slice of pizza in one bite


Why are Tokens important?

1. It determines how much AI can read

Every AI model hasa Context Window,which is the maximum number of Tokens it can process at once. For example:

If this limit is exceeded, the AI will forget what was said before, just like a person's short-term memory is full.

2. It affects the API usage fees

When calling the AI interface (API), fees are usually billed based on the number of Tokens.Input text + AI response textboth consume Tokens, so the longer it is written, the more it costs.

3. It affects the AI's response speed

When the AI generates text, it isOutputs one Token at a timeTherefore, the longer the response, the longer the waiting time.


Token trivia


Summary

Concept One-sentence explanation
Token The smallest unit AI uses to process text, falling between a character and a word
Context Window Maximum Tokens AI can process at once
Token Billing API calls are billed based on the total number of input and output tokens
Token Generation AI responses are generated token by token, and longer responses take longer