Understanding Tokens: The Metering Logic of AI Compute
This article explains what tokens are, why they are the fundamental unit for measuring large language model usage, and how tokenization differs between Chinese and English. It covers context window limits, why input and output tokens are priced separately, and practical strategies for controlling token costs. It also provides a token governance checklist for tracking usage, setting budgets, running evaluations, and archiving reusable knowledge.
1. Why AI Needs a New Unit of Measurement
When calling a large language model API, developers typically encounter three pieces of information: the number of tokens consumed per session, input and output prices quoted per million tokens, and the maximum context length the model supports. Together, these numbers form the measurement system for LLM services.
Traditional software is measured in calls, requests, or bytes. LLMs, however, perform probabilistic natural language generation, where compute cost is proportional neither to character count nor to request count. What actually drives compute consumption is how many discrete symbol units the model must process at once—the token. It serves as the billing unit and as the base scale for memory usage, inference latency, and context capacity.
2. What a Token Really Is: Text Fragments as the Model Sees Them
A token is not a character or a word. It is a subword unit produced by a tokenizer based on statistical patterns. Converting natural language into a token sequence is called tokenization.
For example:
Original text: I love BeijingIntuitive split: I / love / Bei / jingActual split: I / love / Beijing
English works the same way. Common words form their own tokens, longer words are split into roots and suffixes, and spaces usually attach to the beginning of a token:
["Token", "ization", " is", " the", " process", " of", " converting", " text", " into", " tokens", "."]
This design has three direct consequences:
- High-frequency fragments use short tokens and low-frequency fragments use longer ones, balancing compression against vocabulary size.
- The model does not have to process massive numbers of characters, keeping the computation graph manageable.
- Unseen words can still be broken into known subwords, giving the model strong generalization ability.
3. Why Chinese and English Consume Tokens Differently
A common question is why a single Chinese character often costs one or more tokens, while an English word often maps to a single token. The reason lies in the training data and vocabulary distribution of mainstream tokenizers. English is naturally delimited by spaces and reuses subwords heavily. Chinese has no spaces and blurry word boundaries, so if vocabulary coverage is insufficient, text degrades to character-level or even byte-level splitting.
Practical recommendations:
- For Chinese-language scenarios, evaluate tokenization efficiency for the target language rather than looking at unit price alone.
- For structured text such as JSON, code, and tables, remember that symbols and indentation also count as tokens.
- Before launch, sample real corpus data to establish a baseline of average tokens per request for your workload.
4. Context Window: Tokens as a Capacity Scale
The context window is the total number of tokens a model can hold in a single call, shared by input and output. It determines how much material you can supply and how long a response can be. A larger window does not mean unlimited usage: attention computation cost grows with length, and recall of key information within a long context also degrades.
Common engineering approaches include segmented summarization, retrieval augmentation, keeping only the most recent few conversation turns, and preprocessing long documents into reusable intermediate representations.
5. Why Input and Output Are Priced Separately
Input tokens correspond to a single forward pass, while output tokens are typically generated autoregressively one token at a time, with intermediate states cached. As a result, compute and memory costs on the output side are significantly higher than on the input side, which is why higher output prices are common across the industry.
A general approach to cost optimization:
Total cost ≈ input tokens × input price + output tokens × output price
- Compress prompts by removing redundant explanations and repeated examples.
- Cache stable system instructions and knowledge fragments.
- Constrain output format and length to avoid unbounded generation.
- Route simple tasks to smaller models and escalate complex tasks when needed.
6. A Token Governance Checklist for Production
- Establish metering: log input and output tokens for every call on the application side to build an observability dashboard.
- Establish budgets: set token quotas and alert thresholds per business line.
- Establish evaluation: use a fixed test set to compare token efficiency and output quality across models and prompt designs.
- Establish archiving: turn frequent questions into searchable knowledge to reduce repeated input.
7. Conclusion
Tokens are the shared scale linking model capability, compute cost, and product experience. By understanding tokenization, language differences, and cost structure, developers can make explainable and reproducible tradeoffs among quality, latency, and budget. This metering and governance approach also applies to model services on cloud platforms such as Baidu AI Cloud, helping organizations turn compute investment into stable business output.
