How LLM Token Billing Works and Practical Cost Optimization

    This article explains how token-based billing works for large language models and why tokens, rather than character or word counts, are the standard billing unit. It covers input/output split pricing, cache-based tiered pricing, a breakdown of typical request costs, and six actionable cost optimization techniques, along with common misconceptions and engineering recommendations for tracking and attributing token usage.

    1. What a Token Really Is: From “Characters” to the Model’s Minimum Processing Unit

    When people first encounter tokens, they often assume a token equals a single character or word. This assumption is especially misleading for Chinese text. A token is not a linguistic unit. It is a high-frequency fragment identified by the model’s tokenizer during pre-training, and it is the smallest unit the model actually reads and generates.

    The key takeaway is that token count is determined by tokenization rules, not by the number of characters you see. The same semantic content can have very different token densities across languages and domains. General technical documentation, code, and mixed-language content typically expand into more tokens than everyday conversational Chinese.

    A schematic way to inspect this looks like the following (pseudocode, illustrating the idea only, not any specific API):

    1. # Pseudocode: abstract process of "text -> token sequence"
    2. tokens = tokenizer.encode(text)
    3. print(len(tokens)) # input token count used for billing
    4. print(tokenizer.decode(tokens)[:50]) # reconstruct fragments to inspect granularity

    This matters because the billing anchor is the token, not the character count. If you estimate budgets by character count, you can easily underestimate by 30% or more.

    2. Why Billing Uses Tokens Instead of Character Counts

    The computational complexity of a large model is tied to sequence length, and the cost of attention computation rises quickly as context length grows. Character counts cannot reflect actual compute consumption, for three reasons:

    1. Inconsistent segmentation granularity: the same word may be split into one or several tokens depending on the corpus.
    2. Asymmetric cross-language cost: non-Latin scripts, code symbols, emoji, and JSON structures often produce more tokens.
    3. Context accumulates: in multi-turn conversations, historical messages keep occupying input tokens, so cost grows in a roughly linear, additive way with each turn.

    Tokens are therefore the only reproducible and auditable unit of measurement. They make different models and vendors comparable and allow enterprises to perform precise cost attribution.

    3. Mainstream Billing Model: Separate Pricing for Input and Output

    Current industry billing has largely converged and can be summarized in one formula:

    1. Cost per request = input tokens × input price + output tokens × output price

    There are two key design points:

    • Input and output are priced separately, and the output price is usually significantly higher than the input price. This is because the generation phase is autoregressive decoding token by token and cannot be parallelized in a single pass the way input can.
    • Caching is priced in tiers. When a request prefix overlaps with prior content, the cache-hit portion is billed at a lower price, while the non-hit portion is billed at the standard rate.

    The formula then expands to:

    1. Input cost = cache-hit tokens × cache price + non-hit tokens × standard input price

    The engineering implication is that your prompt structure directly determines your bill structure. Placing stable, unchanging content at the front and variable content at the back can significantly improve cache hit rates. This is the highest return-on-investment move in cost optimization.

    4. Doing the Math: Breaking Down the Cost of a Typical Request

    Suppose a request contains a Chinese question of about 500 characters and the model returns an answer of about 1,000 characters. As a rule of thumb, Chinese text is roughly “1 Chinese character ≈ around 1 token,” and answers longer than questions are the norm, so output tokens clearly outnumber input tokens.

    In the common case without any cache hit, cost is dominated by the output side. For an easy-to-grasp relative ratio: if input is 500 tokens and output is 1,000 tokens, and the output price is several times the input price, then output often contributes more than 70% of the total cost for that single request.

    Generalizing this to business scenarios yields three judgments:

    • Long-form generation scenarios (report writing, code generation, document summarization) are naturally more expensive because output makes up a large share.
    • Retrieval-augmented scenarios (RAG question answering) have long inputs and short outputs, so cost is input-dominated, and caching and prefix reuse deliver the most value here.
    • Batch offline tasks can be brought into an acceptable cost range by merging requests and capping output length.

    It is recommended that teams run a small-scale load test with real corpus data before launch, measure the average input/output token distribution, then multiply by unit prices to get a credible monthly budget rather than estimating by feel.

    5. Six Actionable Cost Optimization Techniques

    1. Compress input: remove redundant background, examples, and pleasantries; apply extractive summarization to long documents before feeding them to the model.
    2. Reuse structured prefixes: place system instructions and knowledge base fragments in fixed positions to improve cache hit rates.
    3. Cap output length: set reasonable limits on generation to prevent the model from expanding without restraint.
    4. Tiered model routing: route simple intent classification and format conversion to lightweight models, and invoke high-capability models only for complex reasoning.
    5. Streaming and early stopping: use satisfaction checks to terminate generation early and reduce wasted output tokens.
    6. Build observability: use logging services and monitoring/alerting systems to record token consumption per call and attribute cost by business line.

    When deploying in the cloud, it is common to gateway model capabilities, placing a self-built service layer in front to handle authentication, rate limiting, caching, and metering. The backend can combine container platforms for elastic scaling, use message queues to smooth out traffic spikes, and use object storage to archive long-text corpus data. These are all general product categories, and specific parameters should follow the actual integration documentation.

    6. Common Misconceptions and Engineering Recommendations

    • Misconception 1: A token equals a character count. You must measure empirically, especially for mixed Chinese-English and code scenarios.
    • Misconception 2: Caching always works. Caching depends on prefix consistency; dynamically concatenated timestamps and random IDs will break hits.
    • Misconception 3: Looking only at unit price, not structure. At the same unit price, different prompt organization can make bills differ by several times.

    The final recommendation is to treat tokens as a first-class engineering metric: estimate the order of magnitude during requirements review, add instrumentation during development, and attribute cost by business dimension during operations. General metering and monitoring capabilities offered by cloud vendors such as Baidu AI Cloud can serve as a reference path for putting this methodology into practice, but real cost advantage comes from continuously governing input/output structure, not from finding some “cheaper switch.”