How to Handle LLM API Price Hikes with Time-of-Day Billing
This article breaks down how time-of-day pricing changes the cost of large language model API calls, using a real agent task as an example. It shows how to build a cost model based on cache hit rate, input-to-output ratio, and wasted turns, then applies five practical levers: maximizing prefix caching, shifting deferrable workloads off peak hours, tiered model routing, compressing input context, and setting budget guardrails. Readers will learn how to keep bills predictable and close to pre-hike levels after a peak/off-peak price adjustment.
1. Starting from a Real Bill: What Changed Before and After the Hike
A typical coding agent task has just finished. The runtime reports the following execution profile: 28 interaction turns, 136 execution steps, an average first-token latency of 1.8 seconds, a generation speed of roughly 138 tokens/s, and a prompt cache hit rate of 97%. If the task had run more turns, the hit rate would likely have climbed toward 99%. The task consumed about 27.49 million billed tokens in total, and cost about RMB 1.49 before the price change.
These numbers are worth discussing because they expose the cost structure of LLM calls very clearly: money is not spent on the number of characters generated, but on the context that is replayed over and over. Twenty-eight turns and 136 steps mean the same system prompt and the same repository context were sent to the model repeatedly. Without a caching mechanism, the bill would be on a completely different scale.
According to a price adjustment announced by a cloud provider, the new prices take effect at 00:00 on August 17, and the day is split into peak and off-peak periods: 9:00–12:00 and 14:00–18:00 each day are peak, and all other times are off-peak, with peak prices roughly twice the off-peak prices. For the lightweight tier, the three off-peak prices are about RMB 0.05 / 1.5 / 4.5 per million tokens, doubling at peak to RMB 0.10 / 3 / 9; for the stronger tier, off-peak prices are about RMB 0.15 / 4.5 / 13.5, and peak prices are RMB 0.30 / 9 / 27.
Assuming the structure of input, output, and cache hits stays unchanged, the same workload would cost roughly: lightweight tier about RMB 2.87 off-peak and RMB 5.73 at peak; stronger tier about RMB 8.60 off-peak and RMB 17.20 at peak. On a per-unit basis, the lightweight tier is a little over RMB 10 per 100 million tokens off-peak and a little over RMB 20 at peak; the stronger tier is about RMB 31 off-peak and about RMB 62 at peak.
It is important to stress that these estimates are only a reference for order of magnitude. Before this, the official announcement said only that API service pricing was planned to rise overall in the near future, with a relatively large increase expected, and gave no numbers. Every specific increase was speculation until the formal notice landed. What is truly reusable is not a particular price, but the estimation and optimization method below.
2. Build a Cost Model Before Judging Whether It Is Expensive
Whether something is “expensive” cannot be judged by feeling; you need to break the bill into computable quantities. The cost of an LLM call can be abstracted as:
Cost per task =input tokens × input unit price × (1 - cache hit rate × cache discount)+ output tokens × output unit price+ extra consumption from retries and failed turns
Three variables determine the direction of optimization:
- Cache hit rate: in multi-turn agent tasks, the prefix is highly repetitive, so the hit rate is the biggest cost lever;
- Input-to-output ratio: agent tasks have input far larger than output, so they are more sensitive to the input unit price;
- Wasted turns: error retries and repeated context rebuilding amplify both input and output at the same time.
Turning these three quantities into observable metrics is the prerequisite for handling any price change. Without measurement, a price hike can only be accepted passively.
3. Five Practical Ways to Cut Costs
1. Push the Cache Hit Rate as High as Possible
A stable prefix is the core of cache friendliness. The system prompt, tool definitions, and long-term repository notes should sit at the very front of the context and stay byte-for-byte stable; move volatile content such as timestamps, random IDs, and retrieval results to the back. An illustrative way to organize messages:
[Stable segment] System prompt + tool schema + project conventions[Semi-stable segment] Summary of prior conversation[Volatile segment] This turn's retrieved snippets, timestamp, new user input
Also avoid changing tool definitions or the system prompt midway through a session, which invalidates the entire prefix cache. Raising the hit rate from 97% to 99% often means a double-digit cost reduction in long tasks.
2. Trade Time-of-Day Scheduling for Price
Since peak is about twice off-peak, move deferrable batch tasks out of peak hours: run regression evaluations, batch document generation, log clustering, and offline data cleaning at night; keep interactive, low-latency requests in peak hours. In engineering terms, you only need a scheduling gate:
def is_peak(now, peak_ranges=((9, 12), (14, 18))):return any(s <= now.hour < e for s, e in peak_ranges)def submit(task, now):if task.deferrable and is_peak(now):queue_delay(task, until=next_off_peak(now))else:run_now(task)
This can be implemented with a queue platform and scheduled jobs, without changing the cost model itself.
3. Add Tiered Model Routing
Not every request needs the strongest model. Split tasks by difficulty: intent recognition, format conversion, and summary extraction go to the lightweight tier; multi-step reasoning, code refactoring, and complex troubleshooting go to the strong tier. A simple routing sketch:
def route(req):if req.max_steps <= 2 and req.output_tokens < 800:return "light" # lightweight tierif req.needs_strong_reasoning:return "strong" # strong tierreturn "light"
From the original bill, the strong tier costs about three times the lightweight tier for the same workload, and in practice did not lead significantly, so “default to strong” is the easiest cost to cut.
4. Compress the Input, Not the Requirement
For retrieval-augmented scenarios, control the number of recalled items and snippet length, and rerank before sending to the model; for long documents, use layered summarization; for conversation history, apply rolling compression that keeps only conclusions and to-dos. The goal is to change “replay the full context every turn” into “carry only the necessary increment each turn.”
5. Set Up Budget Guardrails
Set a token budget and alerts for each project, and track consumption separately for peak and off-peak; set a maximum number of turns and steps per task to avoid abnormal retries blowing up the bill. An observability setup usually consists of three pieces—a logging service, monitoring and alerting, and a usage dashboard—which is a common industry practice.
4. Decision Guide: Split by “Willingness to Tinker”
- Not willing to change the architecture: move tasks entirely to off-peak hours, keep using the lightweight tier, and accept a roughly doubled cost, which is acceptable in most scenarios;
- Willing to do a bit of engineering: layer on prefix cache governance, tiered model routing, and budget alerts, which usually pushes the bill back close to pre-hike levels;
- Strong tier models: unless there is a clear benefit from complex reasoning, do not use them as the default; their cost-effectiveness drops further after the price change.
5. Conclusion
The price hike itself is not the problem; the problem is whether the bill is explainable, predictable, and optimizable. Break cost into three variables—cache hit rate, input-to-output ratio, and wasted turns—then constrain them with time-of-day scheduling, tiered models, and budget guardrails, and any price adjustment becomes just a parameter change rather than something out of control. In a phase where compute prices keep fluctuating, what is truly scarce is certainty—and certainty comes from your understanding of the bill’s structure, plus a sensible combination of the general metering, monitoring, and scheduling capabilities offered by platforms like Baidu AI Cloud.
