LLM Token Costs: How Language and Output Structure Affect Your Bill

    LLM token costs depend on more than text length. Tokenization varies across languages, while formats such as JSON add structural overhead. This article explains how to measure these effects, compare models using representative workloads, and optimize prompts and application architecture without sacrificing output quality.

    1. Introduction: Tokenization and Formatting Drive Cost Differences

    Large language model APIs typically charge by the token, but token counts are not the same as word or character counts. Text in Chinese, English, code, and JSON can produce very different token counts after tokenization.

    Two factors account for much of this variation: how a tokenizer splits text in different languages, and how much structural markup an output contains. This article calls these effects the language tax and the structure tax, respectively, and outlines a practical approach to measuring and reducing them.

    2. The Language Tax: Why Tokenization Varies Across Languages

    2.1 Tokenizer Training Bias

    Many widely used model tokenizers have been built primarily around English-language corpora. Common English words and word roots can often be represented as single tokens, making tokenization relatively compact.

    Chinese, Hindi, Arabic, and other languages may be split into smaller fragments by these tokenizers, sometimes down to byte-level units. As a result, expressing comparable information can require more tokens.

    This difference reflects tokenizer design and the distribution of its training data. It does not, by itself, indicate how well a model understands a language.

    2.2 Measuring the Language Tax

    A reproducible measurement starts with an English reference text and parallel translations into the target languages. Count the tokens for each version using the tokenizer associated with the target model, then calculate:

    1. Language tax ratio = Target-language token count / English token count

    Some public comparisons have reported token counts approaching three times the English baseline for Hindi and approximately 1.6 times for Chinese on certain models. Spanish and French have generally shown smaller increases.

    However, these comparisons do not always consistently identify model versions, tokenizer versions, or source corpora. Treat the figures as directional references, not universal constants.

    Differences between models can be substantial. A model optimized for a particular language may have a much lower ratio. Before selecting a model, measure token consumption using your own workload and the target model’s tokenizer.

    2.3 Implications for Model Selection

    At millions of requests, language-related token differences can materially affect costs.

    Consider a bilingual Chinese–English customer support system. If Chinese requests consume substantially more tokens, their share of total spending will exceed their share of request volume. Measurements like these can help a team decide whether different languages should be served by different models.

    3. The Structure Tax: Why JSON and HTML Can Use More Tokens

    3.1 How Structured Output Adds Overhead

    Consider this simple JSON response:

    1. {
    2. "name": "zhangsan",
    3. "age": 28,
    4. "city": "beijing",
    5. "occupation": "software_engineer",
    6. "tags": ["python", "nlp", "llm"]
    7. }

    The response contains relatively little substantive information, yet generating it requires keys, colons, quotation marks, braces, and commas in addition to the values. Longer keys and deeper nesting generally add more tokens.

    Some teams have reported that deeply nested JSON can consume several times as many output tokens as a plain-text description containing equivalent information. The actual ratio depends on key length, nesting depth, and the model, so it must be measured on representative data.

    Indentation and whitespace also contribute to token counts. Some tokenizers encode runs of spaces or indentation as separate tokens. Across large request volumes, this less visible overhead can accumulate.

    3.2 When Structured Output Is Worth the Cost

    • Machine-consumed output: Structured formats are necessary when results feed database writes, frontend rendering, or API integrations. The additional tokens are part of the cost of reliable integration.
    • Human-readable output: For chat responses, summaries, and written content, reduce unnecessary markup and prefer plain text or lightweight Markdown.
    • Multistep workflows: Saving intermediate stage results as JSON can substantially increase total token consumption within a request or workflow.

    3.3 Mixed-Language Prompts and Tokenization

    Development prompts often combine Chinese instructions with English file paths, function names, and variable names. For example, an instruction might ask the model to modify parseName in utils/string_parser.py so that it handles input containing spaces.

    Language boundaries and symbol-heavy regions can change how text is split into tokens, often increasing the count. However, switching languages does not itself trigger an extra charge. The resulting token sequence determines usage.

    Whether a mixed-language prompt uses more tokens—and by how much—must be checked with the target model’s tokenizer.

    4. Engineering Evaluation and Optimization

    4.1 Establish a Reproducible Baseline

    1. Select representative samples. Cover the main languages, instruction types, and output formats used by the application.
    2. Control the test settings. Keep settings such as max_tokens, temperature, and system prompts consistent across comparisons. Pin and record the appropriate tokenizer version for each model.
    3. Calculate expansion ratios. Use English plain text as the reference and measure token-count changes across language–format combinations.
    4. Convert usage into cost. Combine measured token counts with each model’s pricing and expected request volume.

    Record results in a table, with one row per language–format–model combination:

    Sample Language Output format Model Tokens, input/output Unit prices Estimated request volume Total cost
    Sample A Chinese JSON Model X To measure To verify To estimate To calculate
    Sample B English Plain text Model X To measure To verify To estimate To calculate

    Calculate total cost by multiplying input and output token counts by their respective prices, adding the two amounts, and multiplying by request volume:

    1. Total cost =
    2. [(Input tokens × Input price per token)
    3. + (Output tokens × Output price per token)]
    4. × Request count

    Ensure that pricing units are consistent before calculating totals.

    4.2 Prompt-Level Optimization

    • Simplify instructions. Remove unnecessary qualifiers and background information. Describe the task directly.
    • Constrain the response. Ask for only the required fields or a concise answer to reduce redundant output.
    • Compact the structure. For programmatically parsed responses, consider shorter keys, no indentation, and compact formatting. Abbreviated keys reduce readability, so document their meanings in the interface specification.
    • Test the instruction language. Where appropriate, try a language with a lower measured token cost. However, this may reduce semantic precision or harm the experience for non-English users. Before rolling it out, run A/B tests comparing task quality, user satisfaction, and cost. Adopt the change only if quality is maintained.

    4.3 Application-Level Optimization

    • Cache reusable results. Caching fixed-template responses and answers to frequent questions can avoid repeated model charges. Semantic caches require particular care: include template versions and important parameters in cache keys, set expiration times, and invalidate entries when source data changes. Remove sensitive information from cached user content, and do not share user-specific entries across users.
    • Batch compatible requests. Combine small tasks into one call and use delimiters to distinguish them. First verify that the model can reliably answer every subtask separately; otherwise, batching can reduce quality.
    • Set output limits. Use max_tokens to cap response length and prevent excessively long outputs.
    • Estimate usage before calling the model. Use a local tokenizer to estimate input tokens. Truncate or summarize oversized text before submission, using this check as a cost-control gate.

    4.4 Hidden Costs of Reasoning

    Some models generate intermediate reasoning content while handling complex tasks. Whether those tokens are billable depends on the provider and the specific model. Check billing records and the official documentation rather than assuming that every model charges in the same way.

    If the application only needs the final result, ask for a direct answer. Where an explanation is useful, request a short, bullet-point summary with a length limit. A shorter visible response should not be assumed to eliminate any separately billed internal reasoning.

    Multilingual support is becoming an increasingly important model capability. Relevant directions include expanding non-English training corpora, improving tokenization so that common Chinese characters and words can be represented as whole units more often, and incorporating structured data during training to reduce formatting overhead.

    Another direction is cost-aware model routing. A system can estimate token consumption across candidate models based on the input language and expected output format, then select a model using both price and service quality.

    Whether routing produces real savings depends on the overhead and accuracy of the routing decision itself. It needs to be validated against production traffic.

    6. Conclusion: Monitor Token Usage as a First-Class Metric

    Token consumption depends on language, output format, tokenizer behavior, and prompt design. A single optimization is unlikely to deliver large savings on its own; meaningful improvements usually require a combination of measures.

    Track token usage as a dedicated operational metric, refresh estimates regularly using real workload data, and repeat evaluations whenever a new model or tokenization approach is introduced. This makes it easier to balance cost and quality as application usage grows.