What Is a Token in LLMs: A Practical Guide to Billing and Cost Optimization

    This article explains what a token is in the context of large language models, how tokenization actually works, and why token usage drives API costs. It covers the three different meanings of "token" across computing, blockchain, and AI; why one token does not equal one character or word; why Chinese typically consumes more tokens than English; and how input and output tokens are priced differently. You will also find typical token usage ranges for common AI tasks, why agent workflows multiply token consumption, and a practical checklist for controlling costs through context management, retrieval, model tiering, output limits, caching, retries, observability, and batching.

    1. Start With the Bill: Tokens Are Becoming a Baseline Usage Metric

    “How many tokens did you use this month?” This question is moving from developer circles to everyday users. As large models are embedded into search, office productivity, coding, and customer support, token consumption is becoming an observable, budgetable expense—much like electricity, water, or mobile data.

    To understand that expense, you first need to understand the token itself.

    2. Three Meanings of “Token”: One Word, Three Technical Contexts

    In English, “token” originally means a sign, a voucher, or a keepsake, and as an adjective it means “symbolic.” Over the 20th century, three technical fields borrowed the term and gave it three distinct meanings:

    • Computing: an authentication token. Used as an identity or session credential, such as a login token or a verification code, emphasizing a one-time, time-limited pass.
    • Blockchain: a crypto token. A credential for on-chain digital rights, emphasizing verifiable ownership and transferability.
    • Artificial intelligence: a token is the smallest unit of text a large model processes, emphasizing the basic fragment that can be encoded and measured by the model.

    This article discusses only the third meaning, the token in the AI context. The three share a name, but their technical meanings must not be mixed.

    3. How Text Is Split Into Tokens: Not Characters, but Encoded Fragments

    A common misconception is to equate a token with a character or a word. A more accurate understanding is that a token is the resulting unit after a tokenizer splits raw text according to a specific vocabulary and merge rules, then maps it to integer IDs. The model never “sees” text; it only sees these ID sequences.

    Several practical conclusions follow:

    1. One token does not equal one character. A common rule of thumb is that one Chinese character, one punctuation mark, or one English word corresponds to roughly one token, and spaces and some symbols also consume tokens.
    2. The same meaning costs differently across languages. Because mainstream vocabularies cover English subwords more thoroughly, Chinese often needs more fragments to express the same information, typically 30% to 50% more than English. This means that in cost-sensitive scenarios, the way you phrase something is itself an adjustable variable.
    3. Splitting boundaries cannot be predicted precisely. Proper nouns, code, JSON, URLs, and rare characters are often split into multiple fragments, so “character count ≈ token count” is only good for rough estimates, not for billing.

    An illustrative estimation logic (pseudocode that conveys the idea only and does not represent any specific implementation):

    1. def rough_estimate_tokens(text: str) -> int:
    2. # Common engineering practice: estimate with an empirical ratio first,
    3. # then calibrate with the official tokenizer
    4. cjk = count_chinese_chars(text)
    5. others = len(text) - cjk
    6. return int(cjk * 1.0 + others * 0.3) # ratios must be calibrated against the actual tokenizer

    Engineering recommendation: make tokenization and metering a standalone module, and use the actual usage fields returned by the API for regression calibration, rather than scattering hard-coded ratios across business code.

    4. The Cost Model: Why More Questions and Longer Answers Always Cost More

    Most large model services bill by the sum of input tokens and output tokens, and the two sides usually have different unit prices, with output being more expensive. The reason is that generation is an autoregressive process that proceeds token by token: at each step the model runs a forward pass over the entire preceding context, which costs significantly more compute than the one-time encoding of the input.

    A simplified formula that captures the essentials:

    1. cost per call ≈ input tokens × input price + output tokens × output price
    2. where: input tokens = system prompt + conversation history + current question + retrieved reference material

    The most easily overlooked factor here is the accumulating effect of conversation history. In a multi-turn conversation, all previous turns are counted again as input, so the actual input size at turn N is often far larger than the length of “this one sentence.” Cost growth over a long session is roughly quadratic rather than linear.

    By empirical order of magnitude, token consumption for a single AI query breaks down roughly as follows:

    Scenario Typical token volume
    A single short question 10–30
    Everyday one-question-one-answer 80–300
    Moderately complex request (rewriting, short copy, simple analysis) 500–2000
    Long-text processing (summarization, organizing material, writing reports) 3000+

    The industry scale is similarly substantial: public reports indicate that weekly calls to a regional AI large model have reached the trillion-token level, which works out to thousands of tokens per person per week; some organizations forecast hundreds-fold growth in inference-side token consumption over the coming years. Together these numbers point to one conclusion: tokens are shifting from a technical detail to a cost item that needs to be governed.

    5. Agent Scenarios: The Amplification Effect on Token Consumption

    A conversational interaction consumes a few thousand tokens, while an agent application can consume tens of thousands of tokens for a single task—and that gap comes from the execution paradigm, not from a model price increase.

    An agent breaks a complex goal into dozens of steps: goal parsing, task planning, tool selection, argument construction, result validation, and failure fallback and retry. Each step calls the model to make a decision, and each step must carry enough context, so tokens are “multiplied by the number of steps.”

    A typical agent task chain:

    1. user instruction
    2. → planning (decomposed into N subtasks)
    3. → loop N times: call model to decide → call tool → read result → decide whether to retry
    4. → aggregation and output
    5. total consumption ≈ Σ(input context per step + output per step), scaling with step count and retries

    Take a realistic task: have an agent “collect globally relevant financial information from the past 24 hours about a certain asset class, deduplicate it, and deliver it to a specified email address.” Its consumption comes mainly from three parts—long text from fetched web pages entering the context, repeated comparison for deduplication and judgment, and repeated computation from failed retries. It is not unusual for such a task to consume hundreds of thousands of tokens in a single run; adding a second instruction such as “read a local spreadsheet, analyze it row by row, and output conclusions” pushes total consumption higher still. Converted to money, a single task may cost only a few cents to a few yuan, but multiplied by call frequency and user scale, it becomes a cost item that must be optimized.

    6. Cost Optimization Checklist: Treat Tokens as a Governable Resource

    1. Control context, not question length. Prioritize trimming earlier turns, summarizing and compressing early conversation, and injecting only the necessary fragments by relevance.

    2. Use retrieval instead of feeding everything in. Put long documents into a retrieval pipeline and pull back a small number of highly relevant fragments into the context on demand, which can significantly reduce input-side consumption.

    3. Tier your model selection. Route intent recognition, format conversion, and classification or tagging to smaller models or a rules engine, and call the large model only when reasoning and generation quality matter.

    4. Compress output. Explicitly constrain output structure, item count, and length to avoid high-priced output-side spending caused by “a few extra sentences.”

    5. Cache and reuse. Apply prefix caching to stable content such as system prompts and long document prefixes, and cache results for high-frequency identical requests.

    6. Raise the first-attempt success rate. In agent scenarios, retries are the largest hidden cost. Improving tool descriptions, argument validation, and the readability of error messages is often more worthwhile than switching to a more expensive model.

    7. Build observability. Collect input and output tokens per call, task success rate, and cost per task into a unified logging and monitoring and alerting system, with attribution and budget alerts by business dimension.

    8. Go asynchronous and batch. Run non-real-time tasks through asynchronous queues and batch execution, and use object storage to keep intermediate artifacts, avoiding repeated parsing of the same material.

    When deploying on the cloud, these capabilities are typically provided by general-purpose services: container platforms host inference services and elastic scaling, message queues smooth out task spikes and orchestrate asynchronous work, object storage holds raw material and intermediate results, and logging services with monitoring and alerting handle usage attribution and cost warnings. Baidu AI Cloud has a corresponding product portfolio in these general capabilities, which can be combined as business needs require.

    7. Conclusion

    The essence of a token is the smallest measurable fragment a model reads and generates, and it is simultaneously a performance metric, a unit of cost, and an architectural constraint. Understanding the splitting mechanism explains why Chinese costs more; understanding the asymmetry between input and output explains why long sessions suddenly get expensive; understanding step-by-step agent execution explains why the cost of automated tasks jumps by an order of magnitude. Bringing tokens into budgeting, monitoring, and architecture design is the key step from “being able to use AI” to “being able to afford AI.”