MaaS Cache Billing and How to Lower LLM Call Costs

    A cloud MaaS platform now charges cache-hit input tokens at 20% of the standard input price while leaving other prices unchanged. This article explains the KV Cache basis of that discount, how tiered billing works, and practical prompt and conversation patterns that raise cache hit rates and cut API spend.

    As large language models spread across industries, model as a service (MaaS) has become a standard way for enterprises to access AI capabilities. As usage grows, inference token cost often becomes a core engineering concern. Recently, a cloud vendor updated billing on its MaaS platform: input tokens that hit the cache are priced at 20% of the previous input rate, while other prices stay the same. The change reflects more mature KV Cache reuse in the inference stack and gives application teams a new lever for cost control. This article covers the mechanism, the billing logic, and engineering practices for using cache to reduce large-model call cost.

    How Cache Hits Work in MaaS

    In a conventional API call, every request recomputes the full input. That includes tokenization and embedding of the prompt, plus attention at every Transformer layer. For long context or multi-turn chat, much of that work is repeated and wastes compute.

    Prompt caching, also called context caching, addresses this with KV Cache from Transformer inference. As the model processes an input sequence, it produces and stores a Key and Value matrix for each token. If a later request shares an identical prefix with a previous one, the engine can read the stored KV Cache from GPU memory or fast memory instead of running the heavy self-attention forward pass again.

    A cache hit means the input prefix of the current API request matches a record already in the MaaS cache pool. After a hit, computation drops sharply and cost shifts mainly to memory reads. That is why a provider can offer the cached portion at a lower price, and it is the technical basis for pricing cache-hit input at 20% of the original rate.

    What Differentiated Billing Means for Developers

    Traditional MaaS billing is usually flat usage pricing: input tokens and output tokens each multiplied by a fixed unit price. With caching, billing becomes tiered:

    1. Standard input: input that misses the cache is billed at the standard price.
    2. Cache-hit input: the matched prefix is billed at a discount, such as 20% of the original price.
    3. Output: generated tokens are billed at the standard price.

    This pushes application design from “ship the feature” toward treating function and cost together. If many requests share the same system instructions, background knowledge, or few-shot examples, careful layout can push the cache hit rate above 80% and cut overall API cost by half or more.

    Engineering Practices That Raise Cache Hit Rate

    Using the discount depends on raising the hit rate of API requests. The following approaches are effective.

    1. Standardize prompt structure and freeze the prefix

    Matching is usually strict prefix matching. A small change—spaces, newlines, or the order of variables—can miss the cache. Design prompts as a static prefix plus a dynamic suffix.

    Put stable content first: system settings, role description, and fixed rules. Put the user’s variable input last. Do not insert timestamps, random values, or session IDs into the fixed prefix.

    2. Manage few-shot examples consistently

    Few-shot prompts often concatenate examples into the request. For cache hits, those examples should be the same across requests, not randomly sampled each time. If different scenarios need different examples, route requests so that the same scenario shares the same example prefix.

    3. Truncate conversation history carefully

    In multi-turn chat, growing history easily causes misses. A common mistake is rewriting history after each turn, for example by compressing it into a summary. Keep historical messages unchanged. When the context window is full, delete whole messages from the oldest end rather than editing content in the middle.

    Code Example: A Cache-Friendly Request

    The following generic API call shows how to structure a request for a high cache hit rate:

    1. import json
    2. import requests
    3. # Call a MaaS platform with a generic OpenAI-compatible protocol
    4. API_URL = "https://api.example-maas.com/v1/chat/completions"
    5. API_KEY = "your_api_key"
    6. # 1. Define a static, reusable system prefix
    7. SYSTEM_PROMPT = """
    8. You are a professional data analysis assistant. Your task is to produce a structured JSON analysis report from the data the user provides.
    9. The report must include these fields:
    10. - summary: a brief overview of the data
    11. - insights: a list of key insights
    12. - recommendation: recommended actions
    13. Follow the output rules strictly: ...(hundreds of words of rules omitted here)
    14. """
    15. def call_model(user_input: str, history: list):
    16. # 2. Build the message list: system prompt -> history -> current user input
    17. # Keep the system prompt and history as a stable prefix
    18. messages = [
    19. {"role": "system", "content": SYSTEM_PROMPT}
    20. ]
    21. # Append history unchanged
    22. messages.extend(history)
    23. # Place the changing user input last
    24. messages.append({"role": "user", "content": user_input})
    25. headers = {
    26. "Content-Type": "application/json",
    27. "Authorization": f"Bearer {API_KEY}"
    28. }
    29. payload = {
    30. "model": "industry-common-llm-v1", # generic model name
    31. "messages": messages,
    32. "temperature": 0.7,
    33. "max_tokens": 1024
    34. }
    35. response = requests.post(API_URL, headers=headers, data=json.dumps(payload))
    36. return response.json()
    37. # Example call
    38. history_context = [
    39. {"role": "user", "content": "Q3 2023 sales were 5 million."},
    40. {"role": "assistant", "content": "Noted. Q3 2023 sales of 5 million have been recorded."}
    41. ]
    42. new_question = "Q4 2023 sales were 6 million. Please generate the report."
    43. result = call_model(new_question, history_context)
    44. print(result)

    As long as SYSTEM_PROMPT and history_context stay the same, every request that only changes new_question can hit the cache on all preceding tokens and sharply reduce input cost.

    Conclusion

    A large discount on cache-hit tokens is a sign that AI infrastructure is maturing. For enterprises and developers, it is both a chance to lower operating cost and a test of whether the application layout is sound. In future AI engineering, optimizing prompt cache hit rate will be a basic skill, similar to optimizing database queries. With general cloud monitoring and logging from platforms such as Baidu AI Cloud, teams can build a cost dashboard, track cache hit rate in real time, and balance technology choices against product iteration.