How to Effectively Reduce LLM Token Consumption

    Token consumption directly affects LLM cost, usable context, and inference latency. This article explains practical ways to reduce unnecessary tokens across prompt design, output constraints, structured data representation, conversation context management, and engineering controls, including a lossless compact table-like format for large structured inputs.

    Why Token Consumption Matters

    In commercial LLM usage, billing is generally based on the number of input and output tokens. Excessive token consumption creates three problems:

    1. It directly increases invocation cost, especially in high-frequency and long-text scenarios.
    2. It consumes the limited context window, pushing out information that actually matters.
    3. Longer inputs and outputs mean slower inference and a worse user experience.

    Reducing unnecessary token consumption is therefore a way to optimize cost, performance, and output quality at the same time.

    Control Input Tokens at the Prompt Level

    Input-side token waste is often the most severe. Consider the following measures:

    1. Keep system prompts concise. Remove repeated background explanations, verbose pleasantries, and meaningless formatting descriptions. Express requirements in concise, instruction-oriented language. Because the system prompt is resent in every conversation turn, even saving a few dozen tokens can have a significant cumulative effect.

    2. Provide only necessary context. Before feeding a long document to the model, apply retrieval-based filtering and include only the passages relevant to the current question rather than the entire document.

    3. Use delimiters to clarify structure. Use simple delimiters to separate instructions from data instead of relying on lengthy explanatory text such as “the following is the data” or “the above is the data.”

    Constrain Output to Avoid Verbosity

    Output tokens usually cost more than input tokens, so controlling output length has a more direct return:

    1. Specify the output format explicitly. State directly in the prompt, for example, “Return only the result, with no explanation” or “Answer in no more than 50 words,” and provide examples (few-shot). The model will then significantly reduce introductory and repetitive text.

    2. Request structured output. Ask the model to return JSON, a table, or another fixed format. This naturally suppresses redundant natural-language descriptions.

    3. Set length and detail levels. For example, require “List the answer in bullet points, with no more than one line per point.” This controls output size through granularity constraints.

    4. Prevent the model from restating the input. In some scenarios, the model tends to repeat the question before answering. Explicitly prohibit this in the instructions.

    Structured Data Compression: A Compact Token-Oriented Markup Format for LLMs

    When structured data such as database records, table data, or object arrays must be sent to an LLM, the traditional JSON format carries significant structural overhead: quotes, colons, braces, and repeated field names are all split into separate tokens. A token-oriented compact structured markup format addresses this by rewriting data in a more compact and tokenizer-friendly way while preserving lossless expression.

    The following example contains two user records and compares three representations.

    JSON:

    1. {
    2. "users": [
    3. { "id": 1, "name": "Alice", "role": "admin" },
    4. { "id": 2, "name": "Bob", "role": "user" }
    5. ]
    6. }

    YAML:

    1. users:
    2. - id: 1
    3. name: Alice
    4. role: admin
    5. - id: 2
    6. name: Bob
    7. role: user

    Compact markup format:

    1. users[2]{id,name,role}:
    2. 1,Alice,admin
    3. 2,Bob,user

    The design logic is clear: treat the object array as a table. users is the key name, [2] declares the array length, and {id,name,role} declares the column names once. Each subsequent line is a record, with fields separated by commas. Field names are no longer repeated for every record, and braces and quotes are greatly reduced.

    This type of format has several key characteristics:

    1. Lossless and reversible. It can be converted bidirectionally to and from JSON without losing information. Backend systems can continue using JSON for program-to-program data exchange, and the format conversion happens only at the layer where data is sent to the model. This is a typical middle-layer or prompt-layer optimization.

    2. Greatest benefit for large arrays. For large-scale object arrays with a uniform structure, field names appear only once and punctuation overhead is minimized. Compared with formatted JSON, this can typically reduce token consumption by 30%–60%.

    3. Built-in validation information. The format explicitly carries constraints such as array length, which the model can use for self-checking during generation or parsing and can help reduce errors such as missing or extra rows. Some implementations also provide strict parsers to validate the compliance of model output.

    It is important to note the clear boundaries of this approach. It optimizes the representation cost of data before it enters the model; it does not replace JSON’s role in server-to-server transmission. In addition, a compact format may slightly affect the model’s accuracy in understanding the data. In practice, evaluate it before adoption: the benefits are significant in scenarios with large data volume, uniform structure, and machine-parsing-oriented use. For small datasets or complex nested structures, it may not be worth introducing.

    Manage Conversation Context and Control Historical Accumulation

    In multi-turn conversations, historical messages are repeatedly sent to the model, causing token usage to grow linearly with each turn or even faster. Common practices include:

    1. Sliding window. Keep only the most recent turns of conversation.

    2. Historical summary compression. Periodically use the model to compress earlier conversations into short summaries and replace the original history with those summaries.

    3. Externalize key information. Store long documents and large result sets externally, such as in a database or cache, and keep only reference IDs in the context. Retrieve relevant snippets on demand when needed.

    Engineering-Level Optimizations

    1. Response caching. Cache responses for identical or highly similar requests to avoid repeated invocations.

    2. Model tier routing. Use smaller, lower-cost models for simple tasks and escalate to larger models only for complex tasks.

    3. Choose tokenizer-friendly language expressions. Express the same meaning with more concise wording. Chinese, English, and code have different token efficiency under different tokenizers, so test and choose formulations that consume fewer tokens.

    4. Establish token monitoring. Record input and output token counts for each invocation at the application layer, identify abnormal consumption points, and continuously iterate on prompts and data formats.

    Conclusion

    Reducing LLM token consumption is a system-level effort: seek precision at the prompt level, simplicity in output constraints, compactness in structured data, savings in context management, and caching and routing at the engineering level. Among these, the compact structured markup format optimized for LLMs provides a new optimization path for large-scale data feeding. By rewriting JSON into a table-like compact representation, it can save 30%–60% of tokens under lossless conditions while balancing cost and context utilization. Developers should start with monitoring, quantify each consumption point, and then combine the methods above in a targeted way to gradually build economical and efficient LLM applications.