LLM API Peak and Off-Peak Pricing: A Practical Guide to Cost Optimization

    This article explains why time-based (peak and off-peak) LLM API pricing breaks one-dimensional cost models, and how to build a two-dimensional model where token structure sets the baseline and the time window sets the multiplier. It covers the supply-side reasons behind time-of-day pricing, a reusable per-session cost formula with worked examples, and four cost levers: controlling output length, reusing prefix caching, tiered model routing, and off-peak batch scheduling. It also outlines the token-level observability metrics needed at the gateway and the engineering checks to watch during integration and migration.

    1. First, a Common Misjudgment: An Outdated Price List Is More Dangerous Than No Price List

    In discussions about inference cost, the most common mistake is not “not knowing the price” but “estimating today’s bill from an outdated memory of prices.” When an LLM API moves from a promotional discount to long-term pricing and then introduces a time-of-day (peak/off-peak) billing structure, the absolute unit price often changes very little, but the billing dimension shifts from one to two: cost is no longer determined by token volume alone, but also by the time window in which a request occurs.

    This has an engineering consequence: any “price per million tokens” hardcoded into a budget sheet, financial model, or cost dashboard will quickly become inaccurate. The reliable approach is to pull unit prices out of code and documentation and read them at runtime from configuration or a single source-of-truth cost table, with an effective timestamp attached:

    1. # Example: pricing config with effective date, so unit prices are never hardcoded in business logic
    2. pricing:
    3. model_tier: reasoning_pro # high-capability reasoning tier
    4. currency: USD
    5. unit: per_1M_tokens
    6. windows:
    7. off_peak: # off-peak window
    8. input: 0.66
    9. cache_hit: 0.022
    10. output: 1.98
    11. peak: # peak window
    12. input: 1.32
    13. cache_hit: 0.044
    14. output: 3.96
    15. peak_schedule_utc: "Mon-Fri 01:00-04:00, 06:00-10:00"
    16. effective_from: "2026-08-16"

    Note that the actual numbers should always be taken from the provider’s live pricing page; the magnitudes above only demonstrate how to use a cost model.

    2. Why Peak/Off-Peak Pricing Exists: Inference Is an “Electric-Grid-Like” Load

    Time-of-day pricing is not a marketing tactic but an inevitable result of how compute supply works. LLM inference closely resembles grid load:

    • Poor capacity elasticity: To serve peak concurrency, a cluster must provision accelerators and memory for the peak, and that capacity sits idle and depreciating during troughs.
    • Variable batching efficiency: During peaks, dense requests fill dynamic batches (continuous batching) more easily, so compute cost per token is lower; during troughs, sparse requests leave batches underfilled, and fixed overheads such as scheduling and memory occupancy are spread across fewer tokens.
    • Time-varying upstream resource costs: Power, data-center capacity, and some elastic resources themselves carry peak/off-peak price differences.

    Splitting price by time is essentially passing “idle cost” and “peak scarcity cost” to callers as a price signal, so deferrable workloads automatically yield. For developers this is both a constraint and an opportunity: latency-insensitive batch workloads should naturally be scheduled into off-peak windows.

    The conversion needs particular care. If peak is defined as weekdays 01:00–04:00 and 06:00–10:00 UTC, that maps to 09:00–12:00 and 14:00–18:00 Beijing time on weekdays—exactly the core hours when people are at work writing code; weekends and public holidays are typically billed as off-peak all day. This means interactive coding is inherently priced higher than overnight batch runs, and cost optimization must distinguish the two workload types.

    3. Doing the Math: A Reusable Cost Formula

    Let new input tokens be $T{in}$, cache-hit tokens be $T{hit}$, and output tokens be $T_{out}$. The cost of a single session is:

    $C = \frac{T{in}\cdot p{in} + T{hit}\cdot p{hit} + T{out}\cdot p{out}}{10^6}$

    Take a typical coding session: 50K new input, 200K cache hits, 30K output.

    • Off-peak: $ (50000\times0.66 + 200000\times0.022 + 30000\times1.98)/10^6 \approx 0.097 $ USD
    • Peak: $ (50000\times1.32 + 200000\times0.044 + 30000\times3.96)/10^6 \approx 0.194 $ USD

    Two key conclusions follow from the structure:

    1. Output is the main cost driver. In this example output is only about 12% of total tokens but accounts for roughly 61% (off-peak) to 61% (peak) of the cost. The reason is that the output unit price is typically several times the input price—the output phase requires token-by-token autoregressive decoding and cannot reuse existing KV cache.
    2. The peak/off-peak gap is a pure multiplier. The same workload costs twice as much at peak as off-peak, regardless of token structure. So “moving deferrable tasks to off-peak” is a zero-risk, pure-gain optimization, equivalent to a straight 50% discount.

    4. Four Cost Levers That Actually Work

    1. Output Length Governance (Biggest Payoff)

    Since output carries the highest unit price, controlling generation length takes priority over trimming input. Practical measures include: explicitly instructing “give only conclusions and the minimal change, do not re-paste entire files”; using structured output to constrain redundancy; switching long-form generation to segmented continuation with a cap per segment; and separating “explanation” from “code” so the model does not repeatedly restate context.

    1. # Example: budget guardrail that falls back to a shorter reply strategy when exceeded
    2. MAX_OUTPUT_TOKENS = 1200
    3. def call_model(prompt, budget=MAX_OUTPUT_TOKENS):
    4. resp = client.chat.completions.create(
    5. model="reasoning-pro",
    6. messages=prompt,
    7. max_tokens=budget,
    8. )
    9. usage = resp.usage
    10. return resp, {
    11. "in": usage.prompt_tokens,
    12. "out": usage.completion_tokens,
    13. }

    2. Prefix Cache Reuse (Drive Repeated Context to Rock Bottom)

    The cache-hit unit price is typically only a few percent of the input price, making it the largest price gap in the whole structure. A hit requires the prefix to be byte-for-byte stable, so prompt organization should follow “stable first, volatile last”:

    • Put the system prompt, tool descriptions, coding conventions, and repository structure summary at the very front and never change them;
    • Always place per-turn changing content (new user instructions, timestamps, random IDs) at the end;
    • Do not insert the current time, random numbers, or polling sequence numbers into the system section—these seemingly harmless dynamic fields invalidate the entire prefix cache;
    • For long-document analysis, use “load once, ask many follow-ups” instead of resending the full text every turn.
    1. [stable prefix · cacheable]
    2. system: role/conventions/output format constraints
    3. repo: directory structure and key interface summary
    4. --------------------------------
    5. [volatile suffix · not cached]
    6. user: the specific request for this turn

    3. Tiered Model Routing (Cover Traffic by Value, Not Always the Strongest Model)

    There is a several-fold price gap between the high-capability reasoning tier and the lightweight tier. A sound architecture puts a cheap classifier or rule layer in front to split traffic: comment edits, formatting, small single-file fixes, and simple Q&A go to the lightweight tier (whose unit price is on the order of one quarter of the high-capability tier); cross-file refactoring, complex defect localization, and algorithm- or reasoning-intensive tasks are escalated to the high-capability tier. Routing decisions should be observable and traceable, with an automatic escalation threshold for “consecutive lightweight-tier failures” so success rate is not sacrificed to save money.

    4. Scheduling and Batching (Arbitrage on the Time Dimension)

    Put non-real-time tasks such as daily report generation, code scanning, document summarization, batch refactoring, and offline evaluation into a queue and schedule them into off-peak windows; keep only interactive requests during peak hours. Combined with request coalescing and concurrency control, this lowers unit price while improving throughput stability.

    5. Observability: No Measurement, No Optimization

    The prerequisite for cost governance is making tokens a first-class metric. Instrument uniformly at the gateway layer and record at least: model tier, the billing window of the request time, input/cache-hit/output token counts, whether the cache was hit, per-request and cumulative cost, and a task label (interactive/batch).

    1. ts=2026-11-23T10:12:03Z window=peak tier=pro
    2. in=48213 hit=198540 out=2871 cost=0.1873 task=interactive

    With fully dimensioned measurement data, you can answer the questions that actually matter: is cost growth coming from call volume, output inflation, or a drop in cache hit rate? In practice the most common anomaly is a sudden drop in cache hit rate, usually caused by a “harmless” prompt change.

    6. Engineering Notes on Integration and Migration

    To use a self-built or third-party model service inside an AI coding tool, the mainstream approach is to keep the interface protocol compatible: when the server exposes both a generic OpenAI-style and an Anthropic-style endpoint, the latter can be adopted by changing the client’s base URL, auth token, and model name, with no business code changes. During migration, watch four things: first, compatibility differences in streaming output and tool calling (function calling / tool use); second, the context window and maximum output limit; third, error codes and retry semantics (whether rate limits and timeouts are retryable); fourth, whether the metering basis matches the bill.

    Where cost is under control, you can also rely on general capabilities from cloud platforms such as Baidu AI Cloud to close the engineering loop: use object storage to archive request and response samples, a message queue for peak shaving and off-peak scheduling, a container platform to host an elastic inference gateway, and log and monitoring services to build a cost dashboard with threshold alerts.

    7. Conclusion

    As pricing evolves from a “discount price” to a “time-of-day price,” the real lesson is not how much the unit price rose, but that the cost model must upgrade from one dimension to two: token structure sets the baseline, and the time window sets the multiplier. The four engineering levers—compress output, reuse prefix caching, tiered model routing, and off-peak batch scheduling—cover the vast majority of the optimization space, and none of them requires sacrificing generation quality. Finally, remember one discipline: any unit price hardcoded in code, documentation, or a budget sheet will go stale. Making pricing configurable and metering fine-grained is the only way to keep cost governance under control in the long run.