How to Cut LLM API Costs: Peak and Off-Peak Pricing and Cache Billing

    Some LLM providers now charge different rates by time of day and split input billing into cache hits and misses. This article explains the three parts of an API bill, how to estimate the cost of a single task, how to keep request prefixes stable so cache hits stay high, and how to schedule tasks and monitor cache performance.

    1. Why Price Changes Are Raising Bills

    Some LLM providers have changed their API pricing and introduced peak and off-peak rates. Some developers report that the same automated task costs more per hour when it runs during the day than they had estimated.

    The main change is that billing has become more granular. Pay-as-you-go pricing used to depend only on the total number of tokens. Now the unit price can change with the time of day, and cache hits are billed separately from cache misses. Developers have noticeably more variables to consider when they plan costs.

    In most cases, a bill rises because of how requests are structured, not because of a single increase in the price list. Two common causes are an unstable prefix that breaks caching, and running tasks that could have been deferred during expensive hours.

    2. The Three Parts of a Bill

    The cost of a single call usually has three parts.

    Cost item What is billed Relative unit price Common mistake Where to check
    Input cost Uncached input tokens Medium Counting only the user question and missing system instructions and tool definitions Input price on the platform’s pricing page
    Cached input cost Input tokens that match a cached prefix Low Assuming that similar content is enough to hit the cache Platform caching documentation
    Output cost Tokens generated by the model Usually the highest Focusing only on input and ignoring the share of output Output price on the platform’s pricing page

    When cache hits happen. Caching usually requires the request prefix to match a previous request exactly. If even one character differs, nothing after that point can hit the cache. Before you use caching, check the following:

    • Minimum cache length: how many tokens a prefix must reach before it is cached.
    • Cache lifetime: how long a cache entry lasts. Tasks that run at long intervals may need to rewrite the cache every time.
    • Write and read pricing: some platforms charge separately for the first cache write, and later reads are billed at a lower rate.
    • Explicit marking: some platforms require you to mark cache segments in the request.

    Pricing rules differ widely between providers. Follow the official documentation for each platform.

    The risk of cache misses. When a cache entry expires, input that was previously billed at the lower cached rate is billed again at the uncached price. In agent applications, system instructions, tool definitions, and task frameworks are sent with every turn. Cache-hit input therefore often accounts for most of the token consumption. Prefix stability directly determines the size of the bill.

    3. How to Calculate the Cost of a Single Task

    You can estimate the cost of a single task with this formula:

    Single task cost = uncached input tokens × input price + cached tokens × cache read price + cache write tokens × cache write price + output tokens × output price

    Cache write tokens appear only when the cache is first created. If the platform has no separate write price, you can ignore this term.

    Use the price in effect when each request runs. If prices vary by time of day, first convert the execution time to the time zone that the price table uses. For example, suppose the price table uses Beijing time, and a task runs at midnight UTC. You must add 8 hours before you can decide whether the task falls in a peak or off-peak period. Platforms define peak hours differently. Some use the time zone of the provider’s location, while others use Beijing time or UTC. Do not skip the conversion step.

    The following example illustrates the calculation. The prices are fictional and only show the method. They do not represent any real platform.

    Assume a single task includes the following:

    • Fixed prefix (system instructions, tool definitions, task framework): 30,000 tokens
    • User content that changes per request: 2,000 tokens
    • Model output: 3,000 tokens

    Assume the uncached input price is 10 yuan per million tokens, the cache-hit input price is 2 yuan per million tokens, and the output price is 40 yuan per million tokens.

    Case 1: The fixed prefix fully hits the cache.

    • Uncached input: 2,000 × 10 ÷ 1,000,000 = 0.020 yuan
    • Cached input: 30,000 × 2 ÷ 1,000,000 = 0.060 yuan
    • Output: 3,000 × 40 ÷ 1,000,000 = 0.120 yuan
    • Total: 0.200 yuan

    Case 2: The prefix misses the cache entirely because a timestamp is mixed into it.

    • Uncached input: 32,000 × 10 ÷ 1,000,000 = 0.320 yuan
    • Output: 3,000 × 40 ÷ 1,000,000 = 0.120 yuan
    • Total: 0.440 yuan

    The cost in Case 2 is about 2.2 times the cost in Case 1. The entire difference comes from whether the cache hits. The output cost is the same in both cases.

    If the same task runs during off-peak hours, replace the input and output prices with the off-peak prices and recalculate with the formula. We recommend saving a cost template for each task type. When prices change, you only need to update the price parameters.

    4. Fixed Request Prefixes

    Caching depends on whether the beginning of each request stays the same. The basic approach is to put unchanging content first and changing content last.

    Unchanging content includes:

    • System instructions
    • Tool definitions
    • Task framework and output format conventions
    • Fixed example samples

    Changing content includes:

    • The current user question
    • The data to be processed in this request
    • Runtime information, such as request IDs and timestamps

    Prefix stability checklist:

    1. Does the system instruction include the current time, date, or a random ID?
    2. Is the order of the tool list the same in every request?
    3. Is the key order fixed in structured content such as JSON?
    4. Are spaces, line breaks, and punctuation identical to earlier requests?
    5. Are version numbers managed in one place, rather than added to each request on the fly?

    Counterexample. One developer added “Current time: 2026-11-25 00:08” to the end of the system instructions. The time differs in every request, so the prefix no longer matches earlier requests and the cache almost never hits. The fix is simple. Move the time into the user message as variable content, and keep the system instructions unchanged.

    5. Task Tiering, Scheduling, and Hit Rate Monitoring

    Tier tasks by how quickly they need results. You can group tasks into three types:

    • Immediate tasks: users are waiting for the result, such as online Q&A. These tasks can only run when needed, so they usually cannot move to off-peak hours.
    • Deferrable tasks: results are needed within a few hours, such as a second-pass content review or report generation.
    • Batch tasks: these can run overnight as long as they finish before the deadline, such as large-scale data labeling or offline summarization.

    Conditions for off-peak scheduling. A task is a good fit for off-peak hours only if all of the following are true:

    • The business can accept additional delay.
    • The task does not depend on external data that must be updated in real time.
    • The queue has enough capacity to finish all tasks before the deadline.
    • The results have a clear deadline and a fallback for timeouts.

    Metrics to monitor:

    • Cache hit rate = cached tokens ÷ total input tokens
    • Cache token share: the proportion of cache-related tokens in total consumption, which shows whether the prefix design works well
    • Cost per task: calculated with the formula in the previous section and tracked separately for each task type
    • Off-peak savings = estimated cost of the same task at peak prices − actual off-peak cost

    Example alert thresholds. These numbers are starting points. Adjust them based on your historical data.

    • Trigger an alert if the cache hit rate stays below 80% for two consecutive hours.
    • Trigger an alert if the cost of a task type exceeds 1.5 times its seven-day baseline.
    • Trigger an immediate alert if the hash of the fixed prefix changes. This usually means someone changed the system instructions or tool definitions.

    6. Common Mistakes

    • Ignoring time zone conversion, and assuming a peak-hour task runs during off-peak hours.
    • Running deferrable tasks during peak hours and paying higher rates for no reason.
    • Mixing timestamps, request IDs, or randomly ordered content into the prefix, which causes cache misses.
    • Looking only at unit prices and ignoring the output share. Output usually has the highest price, so long responses are often the main source of cost.
    • Ignoring cache lifetime. Tasks that run at long intervals may need to rewrite the cache every time.

    7. Risks and Considerations

    • A cached prefix may contain business data, user information, or internal rules. Before you use a platform, confirm its data retention period, privacy policy, and whether it uses your data for model training.
    • Scheduling tasks for off-peak hours increases completion time. Before launch, assess how this delay affects your service level agreements.
    • Prices, peak hour definitions, and caching rules may change. Review your cost templates regularly against the official pricing pages and announcements.