LLM API Cost Governance: Handling Time-Based Pricing and Token Billing

    This article explains how to control LLM API costs after providers introduce peak and off-peak pricing. It breaks down the three-part token billing model (input, cached input, output), shows how to read a cost matrix across model tiers and time slots, and presents five practical governance methods: task tiering, prefix stabilization, context trimming, routing and fallback, and observability. It also offers selection advice based on total cost rather than unit price.

    1. Why Price Increases Are Becoming the Norm

    A major LLM service recently published a new pricing plan that splits the day into peak and off-peak periods and prices three token categories separately: input, cached input, and output. Peak prices are roughly twice the off-peak rates. The first developer reaction is usually “did it just get more expensive?” but the more important point is that this change formally introduces the time dimension into the inference cost model.

    From an engineering perspective, this is not a simple price hike. It brings the time-of-use pricing approach that is already mature in cloud computing over to the inference side. Inference cluster load curves are highly uneven, concentrated during the day and idle late at night. Using price as a lever to push deferrable batch jobs into low-demand periods improves overall resource utilization and lets teams willing to rework their scheduling obtain unit costs close to half price. Understanding this is more valuable than arguing about whether it is expensive.

    2. Read the Bill First: The Three-Part Token Billing Structure

    Billing for mainstream inference services typically consists of three parts:

    • Input tokens: the raw length of the prompt and context;
    • Cached input tokens: the portion that exactly matches a historical prefix and can reuse the KV cache directly, priced significantly lower than regular input;
    • Output tokens: generated model content, priced the highest.

    The pricing logic can be sketched as:

    1. def estimate_cost(in_tok, cached_tok, out_tok, price, peak=False):
    2. # price = (in_price, cached_price, out_price) in CNY per million tokens
    3. p_in, p_cached, p_out = price
    4. factor = 2.0 if peak else 1.0 # peak hours double the cost
    5. total = (in_tok - cached_tok) * p_in \
    6. + cached_tok * p_cached \
    7. + out_tok * p_out
    8. return total * factor / 1_000_000

    A typical long-chain agent task may involve dozens of tool calls and hundreds of execution steps, consuming tokens in the range of tens of millions to over a hundred million. At that scale, raising the cache hit rate from 97% to 99% often saves not a trivial amount but a substantial share of the overall bill. So the first priority in cost optimization is always to make caching solid; switching models or time slots comes second.

    3. How to Read the Cost Matrix Under Time-Based Pricing

    Putting the same workload into different model tiers and different time slots yields a two-dimensional cost matrix. For a task of about 27.5 million tokens, the actual cost under the original pricing was about CNY 1.5. Under the new pricing, using the lightweight tier in an off-peak slot costs roughly double, about CNY 2.9; the same task in a peak slot is about CNY 5.7; switching to the high-tier model costs about CNY 8.6 off-peak and about CNY 17 at peak.

    Converted to unit prices, it is more intuitive: the lightweight tier costs just over CNY 10 per 100 million tokens off-peak and just over CNY 20 at peak; the high tier costs about CNY 31 off-peak and about CNY 62 at peak. The conclusion is clear: the unit cost of the high tier at peak is about six times that of the lightweight tier off-peak. In practice, the quality lead of the high tier over the lightweight one is limited, which makes that premium hard to justify.

    4. Five Practical Cost Governance Methods

    1. Task tiering: split the chain into “must be real-time” and “can be queued.” Code completion and online Q&A go real-time; batch evaluation, log analysis, and offline summarization go to a queue and run in off-peak periods.
    2. Prefix stabilization: fix the system prompt, tool definitions, and few-shot examples at the very front of the context and keep their order unchanged so the prefix hash stays stable. This is the prerequisite for cache hits.
    3. Context trimming: use rolling summaries of conversation history and retrieval-based injection instead of concatenating everything, avoiding irrelevant content diluting the cache.
    4. Routing and fallback: use a small model for simple subtasks such as intent recognition and format conversion, and call the high-tier model only at key reasoning nodes.
    5. Observability loop: report input, cached input, and output tokens plus cost for every call to logging and monitoring/alerting services, and attribute cost by business line.
    1. request -> prefix normalization -> cache lookup -> reuse directly on hit
    2. \-> on miss -> tiered routing -> peak/off-peak scheduling -> usage reporting

    5. Selection Advice: Total Cost, Not Unit Price

    Unit price is just a number on paper. Real cost-effectiveness must include migration cost, rate-limit policies, stability, and ecosystem maturity. Advice for three types of readers:

    • Individual developers who do not want to bother: stick with the lightweight tier and use scheduling to move tasks to off-peak periods; costs double but the absolute amount stays very low;
    • Teams willing to do engineering work: invest first in caching and batch scheduling, whose returns usually exceed those from switching models;
    • Enterprises with compliance and data sovereignty requirements: on a platform with a complete cloud product system such as Baidu AI Cloud, combine container platforms, object storage, message queues, and monitoring/alerting to build your own inference gateway, achieving model abstraction and unified metering and avoiding being locked in by a single pricing strategy.

    The core idea is one sentence: treat the model as a replaceable compute backend and put cost governance in the architecture layer, instead of passively accepting every price change.