A Guide to Time-Based Pricing and Cache Cost Optimization for LLM Inference

    As LLM applications transition from trials to large-scale production, inference costs have become a critical metric that engineering teams must continuously optimize. Model service platforms are now adopting refined pricing strategies, introducing time-based pricing (peak vs. off-peak) and differential rates for cached and uncached tokens. This guide abstracts these pricing models into general engineering challenges. It explores how to establish cost models, design scheduling strategies to migrate off-peak loads, and improve cache hit rates through prompt engineering and system design. Additionally, it provides practical cost reduction strategies for online services and outlines a monitoring framework to balance latency, quality, and cost.

    As LLM applications transition from trials to large-scale production, inference cost has become a core metric that engineering teams must continuously optimize. Recently, some model service platforms have begun adopting more refined pricing strategies. On one hand, they are differentiating the unit prices for cached input tokens, uncached input tokens, and output tokens. On the other hand, they are introducing time-based pricing, charging higher rates during peak business hours and lower rates during off-peak hours. This trend sends a clear signal: inference cost is no longer determined solely by call volume, but rather by call timing, input structure, cache reuse rate, and output length.

    For developers and enterprise users, understanding this mechanism and adjusting the architecture accordingly is far more valuable than simply waiting for price reductions. This article does not focus on any specific product but abstracts time-based pricing and cache billing into a general technical challenge, discussing how to build cost models, design scheduling strategies, and implement these practices in engineering.

    1. The Essence of Time-Based Pricing: Guiding Load Migration via Price Signals

    Time-based pricing is not a new concept; sectors like electricity, cloud computing, and CDN bandwidth have long utilized similar approaches. The core logic is that platform resource scarcity varies across time periods. By leveraging price differences, platforms encourage users to migrate deferrable tasks to off-peak periods, thereby improving overall resource utilization.

    In LLM inference scenarios, peak hours typically concentrate on weekday mornings and afternoons (e.g., standard working hours), while the rest of the time is considered off-peak. If peak prices are several times higher than off-peak prices, executing the same batch of offline tasks at different times can result in significantly different costs.

    Therefore, teams must first distinguish between two types of workloads:

    1. Online real-time loads: User interactions, customer service Q&A, code completion, and content moderation. These are latency-sensitive and usually cannot be arbitrarily migrated.
    2. Offline deferrable loads: Batch summarization, data annotation, document parsing, benchmark running, and report generation. These have relatively relaxed completion time requirements and are suitable for migration to off-peak hours.

    For online loads, the optimization focus is not “avoiding peaks” per se, but rather reducing invalid token consumption during peak hours. For offline loads, tasks can be concentrated in low-price periods through queues, scheduled scheduling, and budget controls.

    A simple scheduling principle is:

    • Online requests: Guarantee SLA, prioritize cache hits, prompt compression, and output length control.
    • Nearline tasks: Allow minute-level delays; shave peaks where possible.
    • Offline tasks: Allow hour-level delays; schedule for batch execution during off-peak hours.
    • Urgent tasks: Set up whitelists and budget caps to prevent unconstrained calls.

    2. Why Cache Hits Significantly Affect Cost

    In token-billed inference services, inputs are typically divided into “cache hit” and “cache miss” components. The cache hit portion can reuse existing computed results, resulting in a lower unit price; the missed portion requires recomputation at a higher price. Output tokens are generally billed separately based on generation volume.

    This means that the same input length can yield entirely different costs depending on how the context is organized. For instance, an application with a long system prompt that remains stable across multi-turn conversations is more likely to benefit from caching. Conversely, applications that concatenate large amounts of changing content, frequently adjust order, or have unstable prefixes will see a noticeable drop in cache hit rates.

    The cost of a single request can be abstracted as:

    1. Single Cost =
    2. (Input hit tokens × Hit unit price
    3. + Input miss tokens × Miss unit price
    4. + Output tokens × Output unit price)
    5. × Time period price coefficient

    If the average input tokens is I, cache hit rate is h, output tokens is O, hit unit price is c_hit, miss unit price is c_miss, output unit price is c_out, and peak coefficient is m, the average cost C can be represented as:

    1. C = (I × (h × c_hit + (1 - h) × c_miss) + O × c_out) × m

    From this formula, the levers for reducing cost include:

    • Increase h: Improve the cache hit rate.
    • Reduce I: Compress the input context.
    • Reduce O: Control the output length.
    • Choose the right time period: Lower m.
    • Optimize call structure: Reduce repetitive input and invalid context.

    Among these, the cache hit rate is often the most overlooked but offers the most room for optimization.

    3. Engineering Methods to Improve Cache Hit Rate

    Improving the cache hit rate is not as simple as “turning on caching”; it requires systematic design in prompt structure, session management, and request routing.

    1. Keep Prefixes Stable

    Caching is generally friendlier to stable prefixes. Teams should place long-term unchanged system instructions, role definitions, and output format constraints at the beginning, and place per-request variable content at the end. Avoid inserting highly variable information like timestamps, random IDs, or user nicknames into system prompts.

    2. Unify Templates and Order

    The same type of task should use a unified prompt template with a consistent field order. If different developers arbitrarily adjust templates, cache reuse rates will drop. It is recommended to manage templates in code repositories and publish them via version control.

    3. Reuse Conversation Context

    In multi-turn dialogues, reuse existing conversation context as much as possible instead of re-stitching the full history each time. For long conversations, strategies like summary compression, key fact extraction, and segmented memory can be used to reduce invalid historical tokens.

    4. Pre-cache High-Frequency Knowledge

    For high-frequency reuse content like product documentation, policy terms, and knowledge base fragments, you can design stable context blocks and use session stickiness to ensure the same type of request hits the same prefix. Note that cached content should have time validity management to prevent long-term reuse of outdated information.

    5. Monitor Hit Rate, Not Just Call Volume

    It is recommended to track cache hit rates by tenant, business line, prompt template, and time period. If the hit rate of a template suddenly drops, it usually indicates a change in template structure, unstable context order, or scattered request routing.

    4. Time-Based Scheduling and Cost Model Example

    The following parametric example illustrates how to calculate the cost of different scheduling strategies. The code only demonstrates a general cost model and is not tied to any specific platform or quote.

    1. from dataclasses import dataclass
    2. @dataclass
    3. class Price:
    4. hit_input: float
    5. miss_input: float
    6. output: float
    7. peak_multiplier: float = 1.0
    8. def is_peak(hour: int, weekday: int) -> bool:
    9. # weekday: 0=Monday, 6=Sunday; example peak windows are weekdays 9-12, 14-18
    10. if weekday >= 5:
    11. return False
    12. return (9 <= hour < 12) or (14 <= hour < 18)
    13. def request_cost(input_tokens: int,
    14. hit_rate: float,
    15. output_tokens: int,
    16. price: Price,
    17. peak: bool) -> float:
    18. hit_tokens = input_tokens * hit_rate
    19. miss_tokens = input_tokens * (1 - hit_rate)
    20. base = (
    21. hit_tokens * price.hit_input
    22. + miss_tokens * price.miss_input
    23. + output_tokens * price.output
    24. )
    25. return base * (price.peak_multiplier if peak else 1.0)
    26. def batch_cost(tasks, price: Price, run_hour: int, weekday: int) -> float:
    27. peak = is_peak(run_hour, weekday)
    28. total = 0.0
    29. for t in tasks:
    30. total += request_cost(
    31. t["input_tokens"], t["hit_rate"],
    32. t["output_tokens"], price, peak
    33. )
    34. return total

    In real-world systems, this logic can be integrated into task queues: offline tasks enter a low-priority queue, and the scheduler determines the execution window based on the current time period, remaining budget, and task deadline. For online services, a real-time channel is retained while adding metrics such as cache hit rate, average input length, output length, and cost per request.

    5. Cost Reduction Strategies for Online Services

    Online services cannot simply avoid peak hours, but peak costs can be lowered through the following methods:

    1. Prompt compression: Remove redundant instructions, use structured fields, and reduce repetitive background.
    2. Output constraints: Clearly specify maximum output length, format requirements, and stop conditions to prevent the model from generating irrelevant content.
    3. Tiered routing: Use lighter inference configurations for simple classification, extraction, and rewriting tasks; escalate to complex reasoning only when necessary.
    4. Result caching: Implement application-level caching for high-certainty queries, such as reusing answers for identical questions and parameters.
    5. Batch merging: Combine multiple small requests into batch tasks to reduce repetitive context and call overhead.
    6. Budget and quota: Set daily budgets, peak budgets, and alert thresholds by business line to prevent anomalous calls from inflating costs.

    6. Monitoring and Governance Loop

    Cost optimization is not a one-time configuration but a continuous governance process. It is recommended to establish the following monitoring dimensions:

    • Track request volume, token consumption, and cost hourly.
    • Track cache hit rate and miss reasons by template.
    • Track cost per request and budget execution rate by business line.
    • Set alerts for abnormal growth during peak hours.
    • Regularly review low-hit-rate templates and high-output-length tasks.

    The ultimate goal is not to blindly reduce costs, but to find an explainable balance among latency, quality, and cost. Time-based pricing and cache billing provide teams with a more refined optimization space, but they also require the engineering system to have stronger observability and scheduling capabilities. By writing cost models into code, scheduling strategies into queues, and monitoring metrics into dashboards, teams can translate price adjustments into sustainable engineering gains.