Cost Optimization for LLM APIs After Price Hikes: A Practical Guide
As LLM API pricing shifts to peak and off-peak models, cost control now depends on more than just reducing call volume. This article breaks down how time-of-day multipliers, model tiers, and cache hit rates reshape your bill, then walks through five practical optimization paths—off-peak scheduling, model routing, context reuse, batching, and usage governance—with code examples and a reusable cost estimation model to help you establish a baseline and lock in savings.
1. Understand the New Cost Structure First
A cloud provider recently moved its LLM service to peak/off-peak pricing. On weekdays, 9:00–12:00 and 14:00–18:00 are classified as peak hours, with unit prices roughly double those of off-peak periods. For a high-capability model tier, the output price changed from 6 CNY per million tokens to 27 CNY during peak hours and 13.5 CNY off-peak—an increase of about 350% over the original price. The input price for cache hits rose from 0.025 CNY to 0.3 CNY, an increase of roughly 11x. If your previous monthly API spend was 100 CNY and concentrated during daytime hours, the bill could climb to 400–500 CNY before any changes are made.
The key takeaway is not “how much did prices go up,” but that the cost structure has changed. Costs used to be driven mainly by total token volume. Now they are determined jointly by “total tokens × time-of-day multiplier × model tier × cache hit rate.” Optimization strategies must therefore evolve from “make fewer calls” to “restructure usage.”
A reusable estimation model:
Monthly cost ≈ Σ(input tokens × input unit price + output tokens × output unit price) × time-of-day multiplier- discount savings from cache hits
Start by aggregating the past 30 days of call logs across four dimensions—time period, model tier, cache hit or miss, and input/output ratio—to establish a baseline before optimizing. Otherwise, it is easy to optimize in the wrong direction.
2. Five Actionable Optimization Paths
Path 1: Off-Peak Scheduling Without Changing Models
Move deferrable batch tasks (content generation, data cleaning, summary archiving, offline evaluation) to off-peak hours, cutting costs by roughly half. Implementation requires only a scheduling layer:
PEAK = {(9, 12), (14, 18)} # Peak hours on weekdaysdef is_peak(dt):return dt.weekday() < 5 and any(a <= dt.hour < b for a, b in PEAK)def submit(task, dt):if task.deferrable and is_peak(dt):queue_delay(task, until="22:00") # hand off to a delay queueelse:run_now(task)
It is also recommended to use a message queue for peak shaving and valley filling, and to set idempotency keys to avoid duplicate billing from retries. Limitation: ad-hoc daytime requests are still billed at peak rates, and the base unit price has already moved up, so off-peak scheduling only “halves” costs rather than “restoring the old prices.” This approach suits individuals and small teams with modest call volumes and flexible timing.
Path 2: Model Tiering with Lightweight Alternatives
Stratify tasks by difficulty: route intent recognition, format conversion, classification and tagging, and short-text rewriting to lightweight models (for example, a Flash-class tier with an off-peak output price of about 4.5 CNY, one-third of the high-capability tier). Reserve the high-capability tier for complex reasoning and long-form generation only. The key to implementation is building an evaluation set before splitting traffic, using accuracy and manual spot checks to hold the quality floor:
def route(req):if req.task_type in {"classify", "extract", "format"} or req.tokens < 800:return light_modelreturn strong_model
Path 3: Improve Caching and Context Reuse
The 11x increase in cache hit pricing compresses the room for “saving money through caching,” but reducing repeated prefixes still works. Approaches include: fixing system prompts, knowledge base snippets, and tool descriptions as a stable prefix; applying semantic-level caching to high-frequency Q&A; and splitting long documents into reusable paragraph blocks. Set a TTL and version number for the cache to avoid returning stale results after knowledge updates.
Path 4: Batching and Request Consolidation
Batch interfaces typically offer price discounts for non-real-time scenarios. Consolidating multiple small requests into a single call can significantly reduce the duplicated instruction overhead in billed tokens. Example:
{"batch": [{"id": "1", "text": "..."},{"id": "2", "text": "..."}]}
Path 5: Usage Governance and Observability
Establish cost attribution by business line, environment, and caller; set caps on input and output length; configure monitoring alerts and circuit breakers for abnormal amplification (such as retry storms or oversized contexts). Without measurement there is no optimization—a cost dashboard should be a standard part of the launch checklist.
3. Decision Recommendations
First use a three-dimensional baseline of “time period × tier × cache” to locate the main cost sources. Then implement off-peak scheduling, tiering, caching, and batching in order. Finally, lock in the gains with governance mechanisms. If migrating to related Baidu AI Cloud services, you can combine general-purpose capabilities such as its container platform, message queue, logging service, and monitoring and alerting to build scheduling and cost observability systems, avoiding lock-in to a single billing model.
