Large Language Model API Peak and Off-Peak Pricing: A Practical Guide to Cost Optimization
This article explains how large language model API pricing works and how to reduce costs without sacrificing output quality. It corrects the common mistake of budgeting against an outdated price list, breaks down the three-layer pricing structure of input, cache hits, and output tokens, and adds the time-based dimension of peak and off-peak rates. A generic cost formula and a sample coding session show why off-peak work can cost roughly half as much as the same work during peak hours. The article also covers three frequent pitfalls, a practical optimization checklist including time-based scheduling, prefix stabilization, output constraints, model tier routing, and observability, plus general steps for connecting these services to AI coding tools.
1. First, Fix a Common Mistake: An Outdated Price List Is the Most Expensive Cost Trap
When teams estimate their large language model API budget, the most common error is not a wrong formula. It is using an outdated price list. Model service pricing changes frequently, and discounted prices, permanent prices, and time-based prices often succeed one another within a few months. A quote that looked like “a 90% discount” at some point in time may already have been replaced by a new pricing structure.
So the first step in any cost discussion is not “what is the unit price?” but “which version of the price list, verified on which date, are we using?” A practical approach is to record the verification date of the pricing page in internal documentation and add a periodic check to your CI or release process, so stale data does not settle in as the de facto standard.
This article does not cite specific numbers from any particular vendor. Instead, it abstracts the three-layer pricing structure now common across the industry. Readers can substitute the numbers from the pricing page of whichever service they actually use, and the conclusions remain fully general.
2. Breaking Down the Pricing Structure: Three Layers Determine the Final Bill
Billing for mainstream large language model APIs usually consists of three parts. Understanding the order-of-magnitude differences among them is the prerequisite for optimization.
- Input (cache miss): Priced per million tokens, this is the main cost source in long-context scenarios.
- Cache hit: Reusing an existing computation result for a repeated prefix (system prompt, repository context, long documents) typically costs only a few percent of the normal input price, a difference of one to two orders of magnitude.
- Output: The generation-side unit price is significantly higher than the input side, generally in the range of two to four times.
Layer a time dimension on top of this and you get time-based pricing: for the same model, certain peak hours on weekdays are billed at the base price, while hours outside peak periods, plus weekends and holidays, are billed at the off-peak price. The off-peak price is commonly around half the peak price. Peak hours are usually chosen to align with the working hours of the main user base, which in local time often means the daytime hours when people are writing code and doing reviews. In other words, the model is most expensive exactly when you need it most.
3. Converting Prices into the Cost of a Real Session
An abstract formula is more useful than a unit price. Let the number of new input tokens be I, cache-hit tokens be C, and output tokens be O, with input unit price p_in, cache unit price p_cache, and output unit price p_out (in USD per million tokens). The cost of a single session is:
Cost = (I * p_in + C * p_cache + O * p_out) / 1_000_000
Plug in a typical coding session: 50,000 new input tokens, 200,000 cache-hit tokens, and 30,000 output tokens.
def session_cost(i, c, o, p_in, p_cache, p_out):return (i * p_in + c * p_cache + o * p_out) / 1_000_000# Using the general structure "peak price = off-peak price x 2, output = input x 3"low = session_cost(50_000, 200_000, 30_000, 0.66, 0.022, 1.98)high = session_cost(50_000, 200_000, 30_000, 1.32, 0.044, 3.96)print(round(low, 4), round(high, 4)) # roughly 0.097 and 0.19
Two key conclusions follow. First, the off-peak price is about half the peak price, so the same workload costs twice as much during peak hours. Second, compared with an earlier “permanent price at one quarter,” today’s off-peak rate is about twice as expensive and the peak rate about four times as expensive. In other words, estimating today’s bill with an old price list understates it by more than half, which distorts budget reviews.
4. Three Frequent Pitfalls
Output is far more expensive than input. The output unit price is around three times the input price, which means “writing fewer tokens” pays off more than “reading fewer tokens.” Capping output length, asking for the conclusion before the details, and avoiding having the model restate entire blocks of code are all direct cost measures.
No cache reuse means paying full price. The cache-hit price is extremely low, but only if the prefix is byte-for-byte stable. Fix your system prompt, project conventions, and repository structure description, and place them at the very front of the request. Do not insert timestamps, random IDs, or changing logs on every turn, or the prefix hash will change and invalidate the entire cache.
Making new decisions from old conclusions. Prices, rate limits, and context lengths all change. Managing the “verification date plus key unit prices” centrally as environment variables or configuration items is more reliable than scattering them across documents.
5. An Actionable Optimization Checklist
- Time-based scheduling: Move non-interactive tasks such as batch refactoring, batch commenting, offline evaluation, and log analysis to off-peak hours and weekends; for interactive coding, compress context turns as much as possible.
- Prefix stabilization: Template and version-control your prompts, and place dynamic content at the end.
- Output constraints: Set a maximum output length, request chunked responses, and produce a summary first.
- Model tier routing: Send lightweight tasks (completion, renaming, formatting, simple Q&A) to smaller or lower-cost model tiers, and switch back to higher-capability tiers only for complex reasoning and long-chain planning. In practice, the lightweight tier often costs around one quarter of the high-capability tier.
- Observability: Track token consumption by day, by business line, and by model tier, recording input, cache hits, and output separately, so you can pinpoint which layer a cost anomaly comes from.
6. General Steps for Connecting to AI Coding Tools
Most AI coding tools support a custom model service address. If the target service offers both an OpenAI-compatible and an Anthropic-compatible endpoint, choose the one that matches your toolchain. Usually you only need to configure three items: the service base URL, the model name, and the access token.
export ANTHROPIC_BASE_URL="https://<your-service-base-url>"export ANTHROPIC_AUTH_TOKEN="<your-access-token>"# Specify the model name in the tool configuration, for example <your-model-id>
After connecting, run a round of baseline measurement: fix a set of representative tasks, record the actual token distribution and cost under both peak and off-peak periods, and then decide your routing thresholds. If you host model services on a cloud platform such as Baidu AI Cloud, you can combine logging services with monitoring and alerting to observe call volume, latency, and cost in a unified way, making cost governance part of routine operations rather than an after-the-fact accounting exercise.
7. Conclusion
Time-based pricing turns “is it expensive?” from a unit-price question into a scheduling question. What really determines the bill is three things: when you make the call, whether the cache prefix is stable, and whether output is constrained. Build price management anchored to a verification date, a cost model centered on a general formula, and an optimization strategy driven by tiered routing, and you can push unit cost into a reasonable range without changing results, instead of relying on an old quote that can expire at any time.
