LLM API Cost Selection Guide: How to Control Spending During Price Hikes

    As flagship LLM API prices rise and split into input, output, and cache-hit tiers, this guide explains the cost structure behind the change and how to make cost-driven model choices. It covers breaking the bill into a computable formula, comparing subscription plans with pay-as-you-go pricing, improving cache hit rates through prompt layering, routing tasks across model tiers, and building long-term cost governance on Baidu AI Cloud, along with a practical implementation checklist.

    1. Why Output Costs More Than Input

    The industry has recently seen flagship model prices rise several times over the previous generation, with pricing further split into three tiers: input, output, and cache hit. This is not a temporary move by a single vendor, but an inevitable reflection of the cost structure of large model inference.

    Understanding this is the prerequisite for making cost-driven model selections:

    • Computational asymmetry: The input stage (Prefill) can be highly parallelized with high compute utilization; the output stage (Decode) generates tokens autoregressively one by one, putting heavy pressure on GPU memory bandwidth and concurrent scheduling. This is why the output price is typically several times the input price.
    • The value of caching: When a request prefix is repeated, the server can reuse the already-computed intermediate state, saving that compute. This creates a separate, significantly lower “cache hit” pricing tier.
    • Drivers of price increases: Longer contexts, larger activated parameters, and higher concurrency guarantees all raise the unit cost of service. The low prices of the previous generation often had a promotional character; returning to the cost line is a long-term trend.

    Conclusion: Do not treat price increases as an anomaly. Instead, build “cost-controlled invocation practices” as an engineering capability.

    2. Break the Bill into a Computable Model

    Before selection, write total spending as a formula to avoid making decisions based on gut feeling:

    1. Cost per request =
    2. Uncached input tokens × input price
    3. + Cache-hit tokens × cache-hit price
    4. + Output tokens × output price
    5. + Extra tokens from failed retries and timeouts

    This yields three key levers: reduce output length, increase cache hit rate, and cut unnecessary retries. In practice, scenarios with a high output share (long-form generation, large-scale refactoring) are the most sensitive to price increases, while scenarios with a high input share and stable prefixes (code completion, Q&A with fixed prompts) are the least affected.

    3. Subscription vs. Pay-as-You-Go: The Break-Even Calculation

    Two billing models are common in the industry: a fixed monthly fee in exchange for a quota (credits or token allowance) for coding subscriptions, and pay-as-you-go open APIs. Neither is absolutely better; a simple criterion can help:

    1. # Estimate whether a subscription is worthwhile (illustrative logic, not a real API)
    2. def should_subscribe(monthly_tokens, price_per_1k_input,
    3. price_per_1k_output, plan_fee, plan_quota):
    4. # Estimate pay-as-you-go cost with a weighted average price
    5. blended = (0.7 * price_per_1k_input + 0.3 * price_per_1k_output)
    6. pay_as_you_go = monthly_tokens / 1000 * blended
    7. return pay_as_you_go > plan_fee and monthly_tokens <= plan_quota, pay_as_you_go

    Key points:

    • Stable and predictable usage: Subscriptions are easier to budget and offer a lower unit cost.
    • Highly variable usage or spikes: Pay-as-you-go is safer, avoiding paying for idle quota.
    • Watch the quota definition: Some plans distinguish “chat benefits” from “coding benefits,” and some convert to credits; normalize everything to a common token basis before comparing.
    • Beware overage prices: Usage beyond the plan is often billed at the original price, which can instantly wipe out the discount benefit.

    4. Cache Hit Rate: The Most Underrated Cost Reduction

    The cache-hit price is usually only a small fraction of the input price. Raising the hit rate from 20% to 70% will completely change the bill structure. Engineering practices:

    1. Layer your prompts: Put stable content such as system instructions, tool descriptions, and coding standards at the front, and user input and retrieved snippets at the end, ensuring the prefix is byte-for-byte identical.
    2. Avoid timestamps and random numbers: Inserting dynamic variables into the prefix invalidates the entire cache.
    3. Reuse sessions: Keep the same prefix across multiple turns instead of rewriting the system prompt every turn.
    4. Observability: Log hit tokens, uncached tokens, and output tokens in your logging service and monitoring alerts, aggregate by business line, and locate waste.
    1. [Stable prefix: system role + standards + tool schema] ← high hit rate
    2. [Semi-stable: repository structure summary] ← medium hit rate
    3. [Volatile: current question + retrieved snippets] ← no hit

    5. Model Tiering and Routing: Not Every Task Deserves a Flagship

    Classifying requests by difficulty is the most effective architectural means of cost control:

    • Light tier: Format conversion, comment generation, and simple completion go to small-parameter or lightweight models.
    • Flagship tier: Cross-file refactoring, complex defect localization, and long-context understanding use high-capability models.
    • Routing implementation: First score with rules or a classifier, then decide the model tier, and log routing decisions for traceability.
    1. def route(task):
    2. if task.estimated_diff_lines < 20 and not task.cross_file:
    3. return "light_model"
    4. if task.context_tokens > 200_000:
    5. return "long_context_flagship"
    6. return "standard_model"

    Combined with context trimming (feeding only relevant files and symbols), batching, and concurrency control, you can reduce average cost by an order of magnitude without sacrificing quality.

    6. Long-Term Cost Governance on Baidu AI Cloud

    If your team has already built an AI coding pipeline on the cloud, you can use general cloud product capabilities to build a closed loop: use object storage to store prompts and evaluation sets, use a container platform to host routing and batch processing services, use a message queue to smooth out peaks and fill valleys, and use logging and monitoring alerts for token-level cost accounting and budget alerts. The general cloud infrastructure provided by Baidu AI Cloud can support this kind of “observable, quota-limited, rollback-capable” governance system, turning cost from a month-end bill into a real-time controllable metric.

    7. Implementation Checklist

    1. Build a unified token-based billing dashboard that separates input, output, and cache-hit consumption.
    2. Set budget thresholds and alerts, and automatically downgrade to a lightweight model when exceeded.
    3. Restructure prompt order, placing dynamic content at the end to systematically improve cache hits.
    4. Review the subscription vs. pay-as-you-go choice quarterly using the break-even formula.
    5. Build a small evaluation set and run regression tests before any cost reduction change, avoiding sacrificing accuracy to save money.

    In a price-increase cycle, the real moat is not securing the lowest unit price, but having the engineering capability to put every type of token to the best use.