LLM Tokens Explained: Tokenization, Billing, and Optimization Practices

    This article explains what tokens are in large language models, why models tokenize text before processing it, and why there is no fixed conversion rate between tokens and Chinese characters or words. It covers what a single API call actually includes, how context windows work, how token-based billing is calculated, what prompt caching does and does not do, how token counts affect latency, and practical ways for developers to reduce token costs. It also outlines how to build an observable token management system. Readers will gain a clear, engineering-oriented understanding of tokens as a measurable and manageable resource for building reliable and cost-controlled LLM applications.

    1. What Is a Token: The Bridge from Text to Model Input

    In text-based large language models, a token is the discrete unit produced after a tokenizer processes text. It may correspond to a complete word, part of a word, a single Chinese character, several characters, punctuation, a space, or an even finer-grained byte fragment.

    A token is therefore not equal to “one character” or “one word.” More precisely, it is the basic unit the model uses to receive and generate text under a specific set of tokenization rules.

    After a user submits text, the system typically goes through the following process:

    Raw text → tokenization → sequence of token IDs → vector representation → model computation → output token sequence → reconstruction into text

    The tokenizer converts text into tokens and maps each token to an ID. The model then uses an embedding layer to turn these IDs into vectors and performs computation over them within the context. When generating a response, a typical autoregressive language model predicts the next token step by step until a stopping condition is met or a generation limit is reached.

    Note that tokenization is only an encoding process; it does not mean the model has already “understood” the text. Semantic processing happens in the subsequent model computation, and the role of the same token in different contexts may also differ.

    2. Why Models Tokenize First

    If text were processed purely character by character, sequences could become very long, increasing computation and storage overhead. If a separate ID were created for every complete word, the vocabulary could become too large and would struggle to cover new words, spelling variations, and technical terms.

    Subword tokenization is a common compromise: high-frequency fragments can serve as more complete units, while low-frequency words are split into smaller pieces. This keeps the vocabulary size manageable while still representing text that is not directly catalogued.

    For example, a long English word may be split into a root and a suffix; a Chinese phrase may map to several tokens, or partly merge into a larger fragment. These are only illustrations—the actual result depends on the tokenizer’s vocabulary, algorithm, and preprocessing rules.

    Some tokenization schemes also preserve the relationship between spaces and text fragments. As a result, words that look identical may not have exactly the same encoding at the start of a sentence versus in a position with a leading space.

    This also explains why you cannot accurately estimate model usage by simply “counting words.”

    3. There Is No Fixed Conversion Rate Between Tokens, Chinese Characters, and Words

    “How many tokens does one Chinese character correspond to” is a common question, but there is no fixed answer that applies to all models.

    Factors that affect token count include:

    • The tokenizer’s vocabulary size and how it was built;
    • The language distribution in the corpus used to build the vocabulary;
    • Whether the text contains rare characters, technical terms, or foreign languages;
    • The arrangement of digits, punctuation, spaces, and line breaks;
    • Whether it contains program code, structured data, or long identifiers.

    Therefore, “one Chinese character is roughly equal to several tokens” can only serve as an empirical estimate under specific conditions, not as a universal technical rule. Nor should a higher Chinese token count be simply attributed to “Chinese being a foreign language to the model.” Different models can encode different languages with markedly different efficiency, which must be judged through actual measurement.

    1. Natural Language Text

    Frequently occurring words or fragments in everyday expression may have more compact encodings. Rare personal names, uncommon characters, and special symbols may be split into more fragments.

    2. Numbers and Structured Text

    Phone numbers, dates, long digit strings, and nested structures cannot be converted proportionally by character count. Different tokenizers may split numbers in different ways.

    3. Code and Identifiers

    Variable names, indentation, brackets, operators, and strings all consume tokens. Long and uncommon identifiers often require multiple fragments, but the exact count should still be based on the actual tokenization result.

    The most reliable engineering approach is to use a token-counting method that matches the target model. If an API provides actual usage information, treat it as the basis for cost accounting rather than relying on character-count estimates over the long term.

    4. What a Single Call Actually Includes

    The content in the input box that users see is usually only part of the model’s input.

    The actual input may also include:

    • System-level instructions;
    • Conversation history;
    • The user’s current question;
    • Reference material retrieved from a search;
    • Tool definitions and tool return results;
    • Encoding related to message roles and formatting.

    Some message-wrapping information may participate in encoding through special tokens, with the specific handling determined by the model and service implementation.

    For example, a user may type only a short question, but if the system attaches lengthy rule descriptions, several rounds of history, and multiple passages of reference material, the final input token count can still be very large.

    Output tokens also cannot always be equated with the number of characters the user finally sees. Some services may separately account for other generation processes; whether and how they are billed requires checking the corresponding service’s public documentation. A single billing method cannot be generalized into a universal rule for all models.

    5. Context Window: Capacity Limits Are Not a Guarantee of Understanding

    The context window can be understood as the boundary of the token capacity a model can process in a single inference. For many text generation services, the input content and output budget must jointly satisfy the limits set by the model or service, and there may also be separate maximum input length or maximum output length constraints.

    For planning, you can use the following budget relationship:

    Input token budget + output token budget + reserved margin ≤ available context capacity

    This is an engineering planning method and does not replace a specific service’s limit documentation.

    The reserved margin is important. Reference material length can vary, and data returned by tools may exceed expectations. If the window is filled to capacity, the system becomes prone to request failures, content truncation, or insufficient output space.

    In addition, “being able to hold long text” does not mean “being able to reliably use every piece of information in it.” The longer and more mixed the text, the more easily the model is distracted by irrelevant content.

    More effective practices include:

    1. Removing history unrelated to the current task;
    2. Compressing earlier conversation into a structured summary;
    3. Prioritizing highly relevant fragments during retrieval;
    4. Retaining the original evidence behind key conclusions;
    5. Clearly stating the current question, task boundaries, and output requirements.

    When compressing content, take special care to preserve high-risk information such as amounts, dates, negative conditions, and scope of applicability, so that the summary does not change the factual meaning.

    6. How Token-Based Billing Is Calculated

    Pricing input and output tokens separately is one common billing model. Models, services, invocation modes, and purchasing methods may differ, and it should not be assumed that all services use the same rules.

    The most basic formula is:

    Total cost = input tokens ÷ billing unit × input unit price

    • output tokens ÷ billing unit × output unit price

    The following demonstration uses entirely hypothetical prices and does not represent any real service’s pricing.

    Assume:

    • Input price is 2 yuan per million tokens;
    • Output price is 6 yuan per million tokens;
    • A request has an actual input of 1,200 tokens;
    • An actual output of 1,800 tokens.

    Then:

    Input cost = 1,200 ÷ 1,000,000 × 2 = 0.0024 yuan

    Output cost = 1,800 ÷ 1,000,000 × 6 = 0.0108 yuan

    Total cost = 0.0132 yuan

    If there are 100,000 calls per day with exactly the same usage each time, the daily cost is 1,320 yuan.

    Real workloads usually involve a mix of long and short requests, retries, abnormal outputs, and traffic fluctuations, so a budget cannot be based on a single sample. A more robust approach is to track average usage, high-percentile usage, and peak concurrency, and to factor failed retries into the budget.

    7. A Cache Hit Does Not Mean “A Similar Question Was Asked”

    In the context of token billing, caching often refers to reusing the computation results of an input prefix. This is not the same as “the system found a question with similar meaning and directly returned an old answer.”

    Typically reusable content includes fixed system instructions, repeated background material, and stable tool definitions. If a subsequent request meets the service’s matching conditions, part of the computation results may be reused.

    Whether a hit occurs may also depend on:

    • Whether the prefix content and order are identical;
    • Whether the minimum length required for caching is met;
    • Whether the cache is still within its validity period;
    • Whether the request configuration meets reuse requirements;
    • Whether the service provides the corresponding capability.

    Therefore, “roughly the same meaning” does not guarantee a cache hit, nor should all caches be assumed to offer a fixed discount.

    In engineering practice, you can place stable content at the front and the user’s question and dynamic material at the back, reducing unnecessary changes to the shared prefix. This is only an organizational approach that favors reuse; the actual effect must be verified through usage records.

    At the same time, distinguish computation caching from answer caching: the former reuses part of the inference preparation work, while the latter directly reuses historical answers. Answer caching requires additional handling of permissions, data updates, and error-propagation risks.

    8. How Token Count Relates to Response Speed

    Token count affects not only cost but also runtime efficiency.

    When the input is long, the model must process more context, which usually increases the computation overhead before the first output token appears. When the output is long, a typical autoregressive model must perform more generation steps, and the overall completion time often grows accordingly.

    However, response time cannot be determined by token count alone; it is also affected by model size, hardware, concurrent scheduling, cache state, network transmission, and service load. It is not possible to promise that “halving the tokens will definitely make it twice as fast.”

    When evaluating application performance, it is recommended to observe separately:

    • First output token latency;
    • Total time to complete a full response;
    • Actual number of output tokens;
    • Generation throughput per unit time;
    • Latency changes under high concurrency.

    Streaming output lets users see partial content sooner, but it does not inherently reduce final token usage or necessarily lower total cost.

    9. How Developers Can Reduce Token Costs

    1. Trim Repetitive Prompts, Not Necessary Constraints

    Repeated role descriptions and irrelevant background increase usage. You can organize the task, constraints, input, and output requirements separately and remove redundant phrasing.

    But security requirements, permission boundaries, and key business conditions must not be removed merely to save tokens. Real optimization means reducing redundancy, not reducing necessary information.

    2. Control the Relevance of Retrieved Material

    Do not stuff an entire document into the context by default. Retrieve relevant fragments around the question, remove duplicate passages, and retain source locations for easy verification and tracing.

    For questions that rely on multiple pieces of evidence, avoid over-trimming, or you may save input while reducing answer completeness.

    3. Manage Conversation History

    Keeping raw conversation in the short term and using validated summaries over the long term, while storing task state separately, is a common practice. Summaries should record confirmed facts, unresolved questions, and current constraints, rather than only general conclusions.

    4. Limit Output According to Business Needs

    Tasks such as classification and field extraction usually do not need lengthy explanations. Specifying fields, format, and the necessary scope of explanation can reduce ineffective output.

    But overly tight output limits can also cause truncation or missing fields, so a reasonable budget should be chosen through sample testing.

    5. Reduce Ineffective Retries

    After a call times out or a connection is interrupted, do not immediately resend indefinitely. Set a reasonable number of retries, check task status, and apply deduplication in the business flow. Otherwise, repeated calls can amplify costs and even cause duplicate business operations.

    10. Building an Observable Token Management System

    For enterprise applications, token management should be part of routine monitoring, not something handled only when the bill looks abnormal.

    It is recommended to record, for each request, the task category, model configuration, input and output usage, cache usage, response time, failure reason, and retry count. When user data is involved, follow a data-minimization principle and avoid unnecessarily storing complete sensitive text just to track costs.

    Analysis metrics can include:

    • Average cost per successful task;
    • Input and output distribution per task category;
    • Cache hit rate;
    • Proportion of long requests and abnormal retries;
    • Tokens consumed per unit of business result.

    The ultimate optimization goal should not be simply “fewer tokens is better,” but finding the right balance among accuracy, security, latency, and cost. A shorter request that often fails may, once retries and manual correction are counted, be more expensive than a single complete and reliable call.

    Conclusion

    Tokens are an important entry point for understanding how large language models work. They connect text encoding, context capacity, the generation process, invocation costs, and application performance, but they cannot be summarized by a fixed character-to-token conversion ratio, nor simply equated with computation volume or service quality.

    For developers, the reliable practical path is: use a counting method that matches the model, account for costs based on actual usage, set budgets for context and output, identify redundancy through monitoring, and validate optimization results against business quality. Only by treating tokens as a measurable, manageable engineering resource can LLM applications be both usable and controllable.