Cost-Aware LLM Routing Under Time-of-Day Pricing

    This article explains how time-of-day (peak vs. off-peak) LLM pricing changes application cost models and why model selection must move from hardcoded constants to runtime policy. It covers a four-layer routing strategy chain, a unified adapter layer for low-cost model switching, prefix and semantic caching, off-peak batch scheduling, output budgets, and cost observability with attribution metrics. Readers will learn how to build a cost-aware calling architecture that turns price volatility into an optimizable engineering variable.

    1. From Falling Unit Prices to Time Sensitivity: Pricing Models Are Changing Architecture Assumptions

    Over the past two years, price competition among LLM providers led many teams to a default assumption: per-call prices would keep falling, so architecture only needed to care about quality and latency, and cost would naturally amortize as usage scaled. That assumption breaks down when supply is tight and demand grows fast. A clear recent shift in the industry is time-of-day pricing: prices differ across periods within the same day, with peak-hour output prices potentially several times the off-peak rate. At the same time, multiple model services have made several rounds of price adjustments within a year, with the overall average trending upward.

    Note that this article does not discuss any specific vendor’s pricing; it treats time-of-day billing as a general billing paradigm. What matters to developers is not “which provider is cheaper,” but: when price becomes a function of time, an application’s cost model must shift from after-the-fact accounting to up-front decision-making.

    In traditional architectures, model calls are usually hardcoded inside a business function:

    1. def summarize(text):
    2. return client.chat.completions.create(
    3. model="writing-model-standard",
    4. messages=[{"role": "user", "content": text}]
    5. )

    This is fine when unit prices are stable, but under time-of-day pricing it creates three hidden risks:

    1. Time-window risk: the same code can cost several times more when run during morning peak hours than late at night;
    2. Task mismatch risk: simple classification, extraction, and rewriting tasks get routed to high-priced models;
    3. Single-point dependency risk: when one service is rate-limited or fails, the business becomes unavailable.

    So the first step in cost governance is not “find a cheaper model,” but to elevate model selection from a code constant to a runtime policy.

    2. Why Time-of-Day Pricing Amplifies Cost Volatility

    The underlying logic of time-of-day pricing is resource scheduling: compute is scarce during peak hours, so prices rise; resources sit idle off-peak, so prices drop. For application owners, this means cost is no longer determined by token count alone, but by token count × time-window factor × model tier.

    A single request’s cost can be abstracted as:

    1. cost = (input_tokens * p_in + output_tokens * p_out) * peak_factor

    where peak_factor is greater than 1 during peak hours and close to the baseline off-peak. Output tokens are usually more expensive than input tokens, so long-form generation, code generation, and multi-turn agent loops are the most time-sensitive.

    This leads to a counterintuitive conclusion: optimizing prompts to reduce output length often lowers peak cost more than switching models. Output unit price is typically several times the input price, and output length is determined by task complexity, leaving more room to compress.

    Another easily overlooked cost comes from caching. Most services offer a significant discount on “cache-hit input,” which means stable prefixes such as system prompts, tool descriptions, and long documents, if retransmitted every time, amount to continuously paying the miss price. Placing stable content up front and reusing it is the most direct cost-reduction lever under time-of-day pricing.

    3. Cost-Aware Routing: Turning “Model Selection” into a Policy Chain

    The core idea of cost-aware routing is to compute a “task profile” for each request, then choose an execution path based on budget, time window, and quality thresholds. A practical policy chain has four layers of decision:

    1. Task tiering: does it need reasoning, long context, or structured output;
    2. Time-window check: is it currently peak, and is the remaining budget sufficient;
    3. Candidate ranking: among candidates that meet the quality bar, sort by estimated cost ascending;
    4. Failure fallback: when the primary candidate times out or is rate-limited, switch to the next candidate instead of returning an error directly.

    The sample code below shows a minimal viable routing skeleton. The interface is abstracted in a common industry-compatible call form; replace it with your own gateway in practice:

    1. import time
    2. from dataclasses import dataclass
    3. @dataclass
    4. class Candidate:
    5. name: str
    6. tier: str # "light" | "standard" | "heavy"
    7. price_in: float
    8. price_out: float
    9. def is_peak(now=None):
    10. hour = (now or time.localtime()).tm_hour
    11. weekday = (now or time.localtime()).tm_wday
    12. if weekday >= 5: # treat weekends as off-peak
    13. return False
    14. return (9 <= hour < 12) or (14 <= hour < 18)
    15. def estimate(c: Candidate, tin: int, tout: int, peak: bool):
    16. factor = 2.0 if peak else 1.0
    17. return (tin * c.price_in + tout * c.price_out) * factor
    18. def route(task_tier: str, tin: int, tout: int, candidates):
    19. peak = is_peak()
    20. # During peak, downgrade light tasks to the light tier; defer heavy work to off-peak where possible
    21. if peak and task_tier == "light":
    22. allowed = [c for c in candidates if c.tier == "light"]
    23. elif peak and task_tier == "heavy":
    24. allowed = [c for c in candidates if c.tier in ("standard", "heavy")]
    25. else:
    26. allowed = list(candidates)
    27. allowed.sort(key=lambda c: estimate(c, tin, tout, peak))
    28. return allowed, peak

    The key to a routing policy is not the code but measurable quality gates. It is recommended to maintain a small regression suite per task type, recording accuracy, structured-output success rate, and average latency; only allow a lower-tier candidate to take traffic when it is above the gate. Otherwise cost reduction turns into rework, and the secondary calls from rework often cost more than the savings.

    4. Unified Adapter Layer: Making Switching Cost Approach Zero

    Multi-model routing presupposes a unified calling method. In engineering, an adapter layer is usually added between the business and model services, responsible for three things:

    • Protocol normalization: map different services’ requests and responses to a unified internal structure, so business code depends only on the internal interface;
    • Capability declaration: use configuration to describe each candidate’s context length, structured-output support, and streaming support;
    • Observability: record model tier, time window, input/output tokens, cache-hit status, and cost estimate for every call.
    1. {
    2. "task": "code_review",
    3. "quality_gate": {"schema_ok": 0.98, "latency_ms": 8000},
    4. "candidates": [
    5. {"tier": "light", "weight": 0.2},
    6. {"tier": "standard", "weight": 0.6},
    7. {"tier": "heavy", "weight": 0.2}
    8. ],
    9. "policy": {"prefer_offpeak": true, "max_retry": 2}
    10. }

    With a unified structure, you can do canary releases and rollbacks: a new model first takes a small share of traffic, and if metrics degrade it automatically falls back; when one service misbehaves, switching is just a configuration change, with no business code changes. This is also the key to avoiding “handing your cost fate to a single vendor.”

    5. Caching, Batching, and Off-Peak Scheduling

    Under time-of-day pricing, the gains from scheduling and caching often exceed those from switching models:

    1. Prefix caching: fix system prompts, tool descriptions, and long-document summaries as a stable prefix to raise cache-hit rates and lower input cost;
    2. Semantic caching: build a vector index for high-frequency similar requests and return directly on a hit, suitable for Q&A and retrieval scenarios;
    3. Offline batching: non-real-time tasks such as report generation, log attribution, and bulk labeling are queued into off-peak windows;
    4. Output budget: set a maximum output token count and structured-field limit per task to avoid long-tail requests inflating the average;
    5. Budget circuit breaker: set daily budgets per tenant or business line, and automatically downgrade to the light tier or queue when nearing the threshold.

    A practical approach is to introduce a “task queue + time-window scheduler”: the real-time path keeps only necessary calls, and the rest enter a queue consumed in batches by the scheduler during off-peak. This smooths peak pressure and locks most cost into low-price windows.

    6. Observability and Cost Attribution

    Without attribution there is no optimization. It is recommended to collect at least these dimensions: business identifier, task type, model tier, whether peak, input/output tokens, cache hits, retry count, and final cost estimate. With this data you can answer three questions: which task types contribute the main cost, which calls can be pushed down to the light tier, and whether off-peak window utilization is saturated.

    You can further set cost-budget alerts and unit-business-cost metrics, such as “average cost per thousand ticket summaries.” When unit cost rises, check output length and retry rate first, rather than immediately switching models.

    7. Conclusion

    Time-of-day pricing is not a short-term promotion, but a normal mapping of compute supply and demand onto price. For developers, the right response is not chasing one vendor’s low price, but building a cost-aware calling architecture: a unified adapter layer isolates differences, routing policy decides by task and time window, caching and batching compress wasted consumption, and observability keeps the policy tunable. When model selection becomes configuration rather than hardcoding, price volatility turns from a risk into an engineering variable you can actively optimize.