LLM API Pricing Evolution and Cost Optimization Practices

    This article explains how large language model API pricing has shifted from permanent discounts to time-of-use billing, and what that means for engineering teams. It breaks down the current peak and off-peak rates, shows a real coding-session cost comparison, and presents four practical optimization levers: controlling output length, maximizing cache reuse, routing tasks across model tiers, and scheduling batch jobs off-peak. A sample scheduling function and integration notes for AI coding tools are included.

    1. The Bill That “Permanent Discounts” Got Wrong: The Pricing Model Has Changed

    When estimating LLM API costs, many teams still rely on a conclusion they saw months ago: a flagship model’s price was cut to one quarter of its original rate, so that number goes into the budget sheet and is never revisited. The problem is that API pricing is not a one-time pricing event but a continuously evolving policy. The situation described in the original source is typical: a discount was first locked in as a permanent price, then peak/off-peak time-of-use pricing was introduced, and the old price list was retired entirely.

    The current structure, as verifiable on the public pricing page, is time-based billing (USD per million tokens):

    • Off-peak: input 0.66, cache hit 0.022, output 1.98
    • Peak: input 1.32, cache hit 0.044, output 3.96
    • Peak windows: Monday to Friday, 1–4 and 6–10 UTC, corresponding to 9–12 and 14–18 Beijing time on weekdays; weekends and holidays are billed at off-peak rates all day

    In other words, the same request costs roughly twice as much off-peak as the old “quarter price,” and about four times as much at peak. Continuing to estimate today’s bill with the old answer typically underestimates it by more than half.

    2. Why Vendors Introduce Peak/Off-Peak Pricing

    Peak/off-peak pricing is fundamentally about smoothing supply and demand. Inference cluster load is heavily concentrated during daytime working hours, while nights and weekends leave substantial compute idle. Using price signals to shift deferrable batch workloads into off-peak windows is more economical than simply adding capacity. For users, the implication is direct: cost is no longer determined only by “how many tokens you call,” but also by “when you call them,” which extends cost optimization from prompt engineering to scheduling engineering.

    3. Working Through a Real Session

    Take a typical coding session: 50,000 new input tokens, 200,000 cache-hit tokens, and 30,000 output tokens.

    • Off-peak: 0.05×0.66 + 0.2×0.022 + 0.03×1.98 ≈ USD 0.097
    • Peak: 0.05×1.32 + 0.2×0.044 + 0.03×3.96 ≈ USD 0.194
    • Old “quarter price”: about USD 0.05

    Three conclusions follow: cache hits reduce the cost of 200,000 tokens to nearly negligible; output accounts for only 30,000 tokens but contributes more than 60% of the cost; and the choice of time window alone creates a 2x difference.

    4. Four Actionable Optimization Levers

    1. Control output before trimming input. Output is priced at roughly three times input, so compressing verbose explanations, requiring structured short answers, and limiting maximum output length yield far more savings than cutting prompts.
    2. Maximize cache reuse. Put stable system prompts, coding conventions, and repository structure notes in a fixed prefix instead of resending them every turn; the cache-hit rate is only one thirtieth of the input rate.
    3. Route tasks by tier. Send routine completion, formatting, and comment generation to a lightweight model (the lightweight tier’s off-peak input is 0.15 and output is 0.6, about one quarter of the flagship tier), and switch back to the flagship tier for complex reasoning.
    4. Shift batch jobs off-peak. Deferrable tasks such as log analysis, bulk refactoring, and documentation generation should be scheduled for nights and weekends.

    Illustrative scheduling logic:

    1. def pick(price_table, tokens, task_tier, ts):
    2. tier = "light" if task_tier == "simple" else "pro"
    3. peak = is_peak(ts) # weekdays 9-12, 14-18 (local time)
    4. p = price_table[tier]["peak" if peak else "offpeak"]
    5. cost = (tokens["new_in"] * p["in"]
    6. + tokens["cached"] * p["cache"]
    7. + tokens["out"] * p["out"]) / 1e6
    8. return tier, cost

    5. Common Integration Approach in AI Coding Tools

    Mainstream AI coding tools typically support two interface styles: OpenAI-style and Anthropic-style. For the latter, you can fill in the tool’s environment variable base URL, set the model name to the specific model, and add an authentication token—no client modification required.

    1. export ANTHROPIC_BASE_URL="https://<your-gateway-address>"
    2. export ANTHROPIC_AUTH_TOKEN="<your-token>"
    3. # Set the model name according to the official pricing page

    In production, it is advisable to build a lightweight gateway layer that handles pricing-model validation, time-window routing, cache-hit-rate monitoring, and budget alerts, using monitoring, alerting, and logging services to track daily average cost trends per task type.

    6. Conclusion

    The “quarter price” is just a historical snapshot. What actually determines the bill is three things: the unit price structure (input/cache/output), the time of the call, and the model tier selected. Incorporating these three into daily engineering practice can cut costs by several times. In model service practice on platforms such as Baidu AI Cloud, the same recommendation applies: establish a periodic review mechanism based on the official pricing page rather than relying on outdated conclusions for budgeting.