LLM API Cost Optimization: Why the Same Unit Price Can Double Your Bill

    Many teams choose an LLM API by unit price alone, then discover their monthly bill is nearly double a peer's bill on the same model at the same price tier. This article explains that unit price is only one coefficient in the billing formula, not the bill itself. It breaks down the token-based billing structure across input, cache-hit, and output tiers, then walks through four rules that drive real cost differences: batch discounts, prompt caching, subscription versus pay-as-you-go, and off-peak scheduling. It also covers commonly overlooked factors such as one-time free quotas, regional pricing, model-tier routing, and model version lifecycle. Finally, it offers an actionable optimization workflow and a decision checklist to keep inference costs under control.

    1. Same Unit Price, So Why Is the Bill Twice as High?

    Many teams evaluate LLM APIs by looking at a single number: the price per million tokens. The assumption is that picking the platform with the lowest unit price means the job is done. Then the month-end bill arrives, and they find that—using the same model at the same price tier—their bill is nearly double that of the team next door.

    The root cause is this: the unit price is only one coefficient in the billing formula, not the bill itself. A real monthly bill is essentially the sum of the following expression across different request types:

    1. Monthly bill = Σ (tokens of a given request type × unit price of its tier × discount/multiplier)

    The “request type” determines which unit price applies, and the “discount/multiplier” is set by the platform’s rules. So what really determines the size of your bill is your traffic structure (how much can be cached, how much can be run offline in batches, whether call timing is controllable) and whether you are correctly using the cost rules the platform provides.

    Put differently, cost optimization is not a procurement question of “pick the cheapest vendor.” It is an engineering question of “how to organize your calls.” Let’s first break down the billing structure completely.

    2. Breaking Down the LLM API Billing Structure

    Almost all mainstream LLM APIs charge per token, and this is further split into three tiers whose price scales differ dramatically:

    Billing tier Relative magnitude (illustrative) Typical characteristics
    Input (prompt) Baseline Tokens consumed by the prompt on each request
    Cache hit About 1/10 of input When a cached repeated prefix is hit, only an extremely low price applies
    Output (completion) About 5× input Tokens generated by the model; the highest unit price

    Two easily overlooked facts follow from this:

    1. Output costs far more than input. A “long input, short output” scenario (such as long-document classification) and a “short input, long output” scenario (such as long-form generation) have completely different cost structures. You can’t judge cost by input price alone.
    2. The cache-hit price may be as low as one-tenth of the standard input price. If your requests contain a lot of reusable, stable content (system prompts, fixed examples, long reference documents), using caching well can yield order-of-magnitude savings.

    With that in mind, we can write a general cost-estimation function that turns “the bill” from an estimate into something computable:

    1. def estimate_cost(input_tokens, cached_tokens, output_tokens, price):
    2. """
    3. price: unit price per million tokens, shaped like
    4. {"input": 20.0, "cache": 2.0, "output": 100.0}
    5. Returns the cost of this request (in the same billing unit as the platform).
    6. """
    7. M = 1_000_000
    8. billable_input = max(input_tokens - cached_tokens, 0) # the hit portion is charged at the cache price
    9. input_cost = billable_input / M * price["input"]
    10. cache_cost = cached_tokens / M * price["cache"]
    11. output_cost = output_tokens / M * price["output"]
    12. return input_cost + cache_cost + output_cost

    With this estimation skeleton in place, we can go through, one by one, which rules can pull the final number down.

    3. The Four Rules That Really Separate the Bills

    When the unit price is the same, teams whose bills differ by half almost always owe it to how they combine the four rules below.

    3.1 Batch Discount: Trading Latency for Price

    For tasks that do not require a real-time response, many platforms offer a batch interface whose price is usually only about half the standard call price (commonly 50–60% of it). The trade-off is that response latency rises from “seconds” to “minutes or even longer.”

    Typical use cases: offline data cleaning, batch summarization, content-moderation batch runs, evaluation scoring, and generating training data offline. These tasks shouldn’t compete for the same price as real-time requests in the first place.

    Deciding whether to use batch takes a single condition—is there a hard real-time latency requirement:

    1. def should_use_batch(latency_sla_seconds, batch_available=True):
    2. # Prefer batch to get the discount when there is no real-time requirement
    3. return batch_available and latency_sla_seconds is None

    A team that can move 30% of its calls from real-time to batch can, from this alone, save roughly 15% of the bill.

    3.2 Prompt Caching: Making Repeated Prefixes Cheap

    This is the most underrated rule. The mechanism: for a prefix that is identical on every request (system prompt, fixed few-shot examples, long reference document), the platform automatically reuses and caches it, with a short default time-to-live (say, a few minutes). Once a cache hit occurs, these tokens are charged only at the very low “hit price.”

    The key lies in prefix design: put stable, unchanging content at the very front of the prompt, and the user input that changes every time at the end. That way you maximize the hit length.

    1. def build_prompt(system_rules, few_shot_examples, long_reference, user_query):
    2. # The more stable and earlier a part is, the more likely it hits the cache and gets the low price
    3. parts = [
    4. system_rules, # almost never changes → put it first
    5. few_shot_examples, # changes relatively little
    6. long_reference, # reusable when asking multiple questions about the same document
    7. user_query, # changes every time → put it last
    8. ]
    9. return "\n\n".join(p for p in parts if p)

    Note that some platforms charge separately for “writing to the cache,” or make the cache valid only within a limited time window. So a caching strategy should serve high-frequency, prefix-stable scenarios. Occasional calls may actually be unprofitable because of the write cost.

    3.3 Subscription Plans vs Pay-as-You-Go: Finding the Break-Even Point

    Beyond metered pricing, many platforms also offer subscription-style token plans: a fixed monthly fee covers a certain usage, and anything beyond that is settled metered.

    • Pay-as-you-go: suited to businesses with volatile traffic, uncertain total volume, or still in a validation phase. You don’t pay for idle capacity.
    • Subscription plans: suited to stable-usage, call-intensive real-time businesses. When your monthly usage stays reliably above a certain threshold, a subscription-plus-overage combination often costs less than pure pay-as-you-go (saving 10–20% or even more when the load is locked in and calls are dense).

    The key to the decision is calculating the break-even point: plug historical call volume into both options’ pricing and compare the monthly totals, rather than choosing on a hunch.

    3.4 Off-Peak Scheduling: Moving Deferrable Calls to the Trough

    Some platforms offer discounts for specific periods (such as overnight off-peak hours). If your business has calls that can be delayed but are not suited to the batch interface (for example, notification generation that needs a fast response but not a real-time one), you can use a simple task queue to schedule them into the off-peak window.

    In practice, you just add a queue and scheduler layer on the client:

    1. Submit request → decide whether it can be deferred
    2. ├─ No → call immediately (real-time)
    3. └─ Yes → enqueue → the scheduler consumes them together during the off-peak window

    For teams that can move a good portion of their calls to off-peak hours, the bill can drop considerably further. This rule “stacks” with the batch discount, but it applies to different scenarios: batching sacrifices minute-level latency, while off-peak scheduling sacrifices hour-level latency.

    4. Four Details That Are Easy to Overlook

    Beyond the four rules above, the following points are often missed at settlement time:

    Free quotas are one-time; don’t build your architecture around them. New models or new users often come with a one-time free token quota. It can help with early validation, but once usage grows it stops applying, and it should not be treated as part of a long-term cost model.

    Regional differences change the unit price. The same model is often about 10% more expensive in certain regions. When choosing a region, weigh latency, price, and data compliance together rather than looking at price alone.

    Model-tier selection saves real money. Not every task needs a flagship large model. Relatively simple tasks like classification, extraction, formatting, and intent recognition can be routed to lighter, cheaper models; reserve expensive, strong-reasoning models only for requests that genuinely need complex reasoning. Doing this routing well usually lowers the overall bill noticeably.

    Watch model-version migration and retirement. Older model versions gradually stop being offered to new users and are eventually retired. Planning migration to the successor version ahead of time avoids the rework risk of a forced switch and often lets you enjoy the successor’s better cost-performance. Any cost estimation should factor in the “version lifecycle.”

    5. Implementation: An Actionable Cost-Optimization Workflow

    Stringing the rules above together yields a reusable engineering workflow:

    1. Instrumentation and classification. Tag every call: task type, whether it has a real-time requirement, whether the prefix is stable and cacheable, whether it can be deferred. Without this data layer, all the later optimization is impossible.
    2. Build an estimation model. Use the estimate_cost function from Section 2 to formalize the estimated-bill formula, hook it into monitoring, and make “how much each call costs” quantifiable and attributable.
    3. Follow the decision tree. For each request, decide in sequence: can it go to batch? can it hit the cache? is it suited to subscription? can it be off-peak scheduled? Replace guesswork with a clear decision chain.
    4. Govern the cache prefix. Standardize prompt templates, put stable content first, and periodically evaluate hit rate and write cost.
    5. Review the bill by dimension. Break the bill down by business line, task type, model, and region to find the biggest cost contributors and optimize them specifically.

    This workflow applies broadly to the LLM services offered by major cloud platforms (such as Baidu AI Cloud), because most of them support common capability categories like token-based billing, prompt caching, batch tasks, and subscription plans. When implementing it, always follow each platform’s current official pricing rules, and don’t rely on outdated data.

    6. Cost-Optimization Decision Checklist

    • Have tasks that don’t require a real-time response been moved to the batch interface?
    • Does the prompt follow “stable content first, changing content last” to maximize cache hits?
    • For stable-usage real-time businesses, have you compared the break-even point between subscription plans and pure pay-as-you-go?
    • Have deferrable calls been scheduled into the off-peak window?
    • Have simple tasks been routed to lighter models?
    • Was the region choice weighed across latency, price, and compliance?
    • Are you tracking the version lifecycle and migration plan of the models you use?

    Conclusion

    Back to the opening question: when the unit price is the same but the bill is twice as high, the reason was never in that single number, “unit price,” but in whether you understand the billing structure and actively use the platform’s cost rules correctly. Treat cost optimization as an ongoing engineering practice—first instrument and classify, then build an estimation model, then push costs down one rule at a time with batching, caching, subscriptions, and off-peak scheduling, and review regularly. Only then can you keep LLM inference costs stably within a reasonable range, instead of regretting the bill at month-end.