What Is a Token in LLMs: A Complete Guide from Text Tokenization to Model Billing

    This guide explains what a token is in large language model applications, how text is split into tokens by a tokenizer, and how tokens differ from character and word counts. It covers why LLMs bill by tokens, how to calculate request costs, why multi-turn conversations grow more expensive, and practical strategies for reducing token consumption. It also outlines cost-monitoring and budgeting practices for enterprise deployments, helping readers estimate expenses accurately and design more efficient LLM systems.

    1. What a Token Actually Is

    In large language model applications, a token can be understood as the basic unit of measurement the model uses when processing text. It is neither strictly a “character” nor exactly a “word,” but rather a fragment of text produced after the model’s tokenizer processes the input.

    For example, a sentence looks like a continuous string of characters, letters, and punctuation to a user, but the model usually does not compute over the entire sentence directly. Instead, it first splits the text into several tokens, then converts those tokens into numeric vectors and passes them to the neural network.

    A token may correspond to:

    • A single Chinese character;
    • Several consecutive Chinese characters;
    • An English word;
    • Part of an English word;
    • A number or a fragment of a number;
    • A punctuation mark;
    • Formatting information such as spaces or line breaks;
    • Keywords, operators, or special symbols in code.

    Because of this, there is no fixed conversion ratio between “1,000 characters” and a number of tokens that applies to all text. Chinese, English, numbers, code, tables, and mixed text all produce different token counts.

    2. How Text Is Split into Tokens

    After receiving a request, a large language model typically goes through a flow like the following:

    1. Raw text
    2. ↓
    3. Normalization
    4. ↓
    5. Tokenizer splits the text
    6. ↓
    7. Token sequence
    8. ↓
    9. Tokens mapped to numeric IDs
    10. ↓
    11. Model computation
    12. ↓
    13. Output tokens generated
    14. ↓
    15. Decoded into readable text

    The role of the tokenizer is to find suitable text fragments within a vocabulary. The vocabulary usually contains a large number of common characters, words, symbol combinations, and code fragments. High-frequency content can often be encoded more efficiently, while low-frequency content may be broken into finer pieces.

    For example, an English word may map to a single token as a whole, or it may be split into multiple tokens such as a root and suffixes. A short Chinese phrase may be split by single characters, words, or continuous fragments. A piece of structurally complex code may consume more tokens because of its symbols, indentation, and variable names.

    This means the number of tokens mainly depends on the following factors:

    1. Language type: Different languages have different average splitting efficiency.
    2. Word commonness: Common phrases are usually easier to represent compactly.
    3. Number and symbol count: Long numbers, special characters, and complex punctuation can increase the token count.
    4. Code structure: Indentation, brackets, paths, variable names, and comments all consume tokens.
    5. Text format: Structured content such as JSON, XML, Markdown, and tables usually contains many symbols.
    6. Tokenizer version: Different models may use different vocabularies and splitting rules.

    So in real projects, you cannot roughly judge cost based on character count alone. A more reliable approach is to use the tokenization tool that corresponds to the target model to get statistics.

    3. How Tokens Differ from Character and Word Counts

    Many people directly equate tokens with “character count,” which is one of the most common misconceptions.

    Character count is a measurement oriented toward human reading, usually based on the number of characters. Word count depends on language rules; for example, English separates words with spaces, while Chinese has no natural space boundaries. A token, by contrast, is a unit oriented toward model computation, determined by the specific tokenization algorithm.

    You can understand it this way:

    1. Character count: how many characters a human sees
    2. Word count: how many words a human divides out by language rules
    3. Token count: how many fragments the model's tokenizer finally splits out

    A piece of text may not have many characters, but because it contains many numbers, paths, or special symbols, the token count can increase noticeably. Conversely, some common phrases may be encoded more compactly.

    During the estimation stage, you can use character count for a preliminary budget, but before going live you should calibrate with the actual tokenization result. The error is usually large in the following scenarios:

    • Code completion;
    • Log analysis;
    • Long-table question answering;
    • Multilingual content processing;
    • Transferring large amounts of structured data;
    • Requests containing image descriptions, tool-call parameters, or complex message structures.

    4. Why LLMs Charge by Token

    The computation of a large language model is essentially built around tokens. The model needs to understand the input tokens and progressively generate output tokens. Longer inputs and more outputs usually mean more computation, so the token becomes a natural billing unit.

    A common billing structure has two parts:

    • Input token cost: The prompts, context, historical messages, and attachment text the user sends to the model.
    • Output token cost: The answers, code, and structured results the model generates.

    The cost of a single request can be expressed with a general formula:

    1. Single-request cost =
    2. input token count × input unit price
    3. +
    4. output token count × output unit price

    If the service provider distinguishes different input states, the following situation may also occur:

    1. Single-request cost =
    2. uncached input tokens × uncached unit price
    3. +
    4. cached input tokens × cached unit price
    5. +
    6. output tokens × output unit price

    Here, caching is usually applied to context that appears repeatedly. For example, system prompts, fixed business rules, or long-term unchanged document prefixes—if they can be recognized and reused, part of the input may be billed at a lower price. However, whether the cache takes effect, how long it stays valid, and how cache fragments are divided should follow the actual service rules. You cannot assume a cache hit just because “the same content was sent before.”

    5. Calculating Cost with a General Example

    Suppose a request contains:

    • Input text: about 500 Chinese characters;
    • Model output: about 1,000 Chinese characters;
    • After actual tokenization, the input is 800 tokens;
    • After actual tokenization, the output is 1,600 tokens;
    • Input unit price is a certain fee per million tokens;
    • Output unit price is a certain fee per million tokens.

    The input cost can be written as:

    1. Input cost = 800 ÷ 1,000,000 × input unit price

    The output cost can be written as:

    1. Output cost = 1,600 ÷ 1,000,000 × output unit price

    The total cost is:

    1. Total cost = input cost + output cost

    If you make 10,000 calls per day, the daily cost is:

    1. Daily cost = single-request cost × 10,000

    Estimating 30 days per month:

    1. Monthly cost = single-request cost × daily calls × 30

    This example shows that what really affects cost is not “how long the question looks,” but how many tokens the input and output are finally split into. For scenarios like customer service, content generation, and code assistants, output tokens are often not negligible; for long-document question answering and multi-turn conversations, input tokens may become the main source of cost.

    6. Why Multi-Turn Conversations Get More Expensive

    In multi-turn conversations, the model usually needs to reference both the current question and some historical messages. As the number of turns increases, the context carried by each request may grow longer.

    For example:

    1. Turn 1: system instruction + user question 1
    2. Turn 2: system instruction + question 1 + answer 1 + user question 2
    3. Turn 3: system instruction + question 1 + answer 1 + question 2 + answer 2 + user question 3

    If the application sends the full message history every time, the input tokens keep growing. Even if the user only types one sentence, the content the model actually processes may already include a large amount of historical context.

    Common optimization methods include:

    1. Limiting the number of history turns: Keep only the most recent few turns.
    2. Summarizing and compressing history: Condense earlier conversation into a structured summary.
    3. Extracting key facts: Keep only user preferences, task state, and key conclusions.
    4. Retrieving content on demand: Do not put the entire document into the context; load only the fragments relevant to the current question.
    5. Separating fixed instructions from dynamic content: This makes it easier to reuse stable context and reduce the cost of repeated transmission.
    6. Setting a reasonable output limit: Avoid having the model generate large passages beyond business needs.

    7. How to Reduce Token Consumption

    Reducing token cost does not mean simply shortening everything, but improving information density.

    7.1 Optimize Prompt Structure

    A prompt should clearly state the task, constraints, input format, and output format, avoiding repeated expression. For example, fixed rules can be defined once in one place rather than repeatedly described in every request.

    7.2 Avoid Meaningless Context

    Historical messages, redundant examples, repeated documents, and irrelevant logs all increase input tokens. The application should filter and trim them before sending.

    7.3 Control the Output Format

    If the business only needs three fields, there is no need to ask the model to generate a long explanation. You can use explicit field constraints, for example:

    1. Return only the following fields:
    2. {
    3. "result": "",
    4. "reason": "",
    5. "confidence": 0
    6. }

    Structured output helps reduce irrelevant content and makes it easier for programs to parse.

    7.4 Process Long Documents in Segments

    Do not submit an entire document at once. First split the text, then retrieve relevant fragments based on the question, and finally hand only a small set of candidate content to the model for analysis.

    7.5 Let the Model Output Moderately Concise Content

    When the task allows, you can explicitly require “keep it within a specified length,” “give only the conclusion and the basis,” or “do not repeat the question.” Such constraints are usually more reasonable than truncating after the fact.

    7.6 Grade Requests by Difficulty

    Tasks like simple classification and keyword extraction do not necessarily require a complex long-text reasoning pipeline. You can choose models or processing pipelines of different tiers based on task difficulty to control cost overall.

    8. Cost Accounting Recommendations for Enterprise Applications

    Before officially going live, it is recommended to establish token-level observability and record at least the following metrics:

    • Input token count per request;
    • Output token count per request;
    • Average and maximum token counts;
    • Call volume of different business interfaces;
    • Success rate, timeout rate, and retry count;
    • Usage by individual user, tenant, or department;
    • Ratio of cache hits to misses;
    • Daily, weekly, and monthly cumulative costs.

    Pay special attention to the retry mechanism. If a failed request is automatically resent multiple times, it can bring extra token consumption. For timeouts, network errors, and format-validation failures, distinguish whether model billing has already occurred, and set a reasonable retry count.

    In addition, establish budget-control measures, such as:

    • Setting a daily call limit for individual users;
    • Setting a monthly budget for different businesses;
    • Alerting on abnormal growth;
    • Intercepting overly long inputs;
    • Setting an upper limit on output length;
    • Enabling an application-layer cache for high-frequency repeated questions;
    • Periodically reviewing prompts and context templates.

    9. Summary

    A token is the key unit that connects text, model computation, and service cost. It is neither a simple character count nor a fixed word count, but a text fragment produced by the tokenizer according to the model’s vocabulary and rules.

    Understanding tokens has at least three benefits:

    1. Understanding model limits: The context window is usually measured in tokens, and overly long input can cause truncation or request failure.
    2. Accurately estimating cost: Input and output are usually billed separately, and the actual token count determines the final cost.
    3. Optimizing system design: Through summarization, retrieval, caching, trimming, and output constraints, you can reduce consumption and improve response efficiency.

    In practice, the most reliable method is to first make a preliminary estimate with character count, then get precise statistics using the tokenization tool that corresponds to the target model, and finally calibrate the average and peak values against real call logs. Only by bringing token count, call frequency, context strategy, and abnormal retries under unified management can you achieve sustainable, quantifiable control over the performance and cost of large language model applications.