# LLM API Cost Optimization: Same Token Price, Half the Bill

    Per-token prices for the same model are nearly identical across major cloud platforms, yet monthly bills for the same workload can differ dramatically. This article explains why: a bill is the product of price, volume, and channel, and the pricing page only shows one of the three. It breaks down the cost model of LLM APIs, walks through the rule sets that actually drive the gap — prefix caching, asynchronous/batch endpoints, prepaid packages and off-peak pricing, and model versions and regions — and provides a worked example where the same usage produces a bill at 70% of baseline. It also includes pseudocode for a cost estimator, a sampling method for measuring your own usage profile, a channel-routing table and selection checklist, and an engineering roadmap that turns "which provider is cheapest?" into "which calls should go through which channel."

    1. Identical Token Prices, Bills That Differ by Half

    When teams start a technical evaluation, the first step is often to open the pricing pages of a few cloud platforms and compare “price per million tokens” for the same model. Once the numbers match, the conclusion is usually “it doesn’t matter which one we pick.”

    That conclusion holds for the per-token rate itself. Hosted model serving mostly follows the same list price across providers, since the cloud platform primarily provides hosting and distribution. Mainstream platforms therefore generally do not compete on per-token price, apart from promotional discounts for new or existing customers. The same applies to comparable tools when demand and price structures are similar: focusing only on the sticker price leads to the wrong conclusion.

    But “same price” does not mean “same bill.” A bill is the result of price, volume, and channel acting together. The pricing page only tells you one of the three. For the same workload, changing only how calls are made can produce a visibly different monthly bill. The reason is usually not on the price sheet, but in a few rules that are easy to overlook:

    What drives the bill How it appears on the pricing page Typical impact
    Input/output mix Two prices listed side by side, with no weighting shown Output is usually more expensive, and it shapes the cost structure
    Prefix caching Only the cache-hit price is listed; hit conditions are not explained The cached portion is billed at the hit price, so the hit rate determines the effective unit price
    Async/batch channels Listed separately by some providers, omitted by others Delay-tolerant workloads often get a discount, but latency ranges from minutes to hours
    Subscriptions, token packages, off-peak rules Listed separately from pay-as-you-go Suited to steady or clearly peaked workloads, but with quota caps and validity periods
    Model versions and regions Priced separately per model and per region Older versions may be retired; remote regions can be more expensive with higher latency
    Workload Typical input/output ratio Where the cost sits
    Long-document summarization, archiving Input far larger than output Input side (caching and batching pay off most)
    Code generation, copywriting Output takes a large share Output side (length control pays off)
    Knowledge-base Q&A (RAG) Depends on the length of retrieved chunks Input side: retrieved chunks and prompt templates

    A simple analogy: two users are on the same ¥30 monthly phone plan. One only makes calls. The other uses both data and calls — most data traffic runs on the bundled allowance, and peak-hour calls are moved to off-peak windows, so about ¥15 a month is enough. LLM APIs work the same way: the requirement hasn’t changed, but routing through the right channel lowers the bill.

    This article offers a practical cost model and a decision method. The goal is to turn “which provider is cheapest?” into an engineering question: “which calls should go through which channel?”


    2. Understand the Bill First: The Cost Model of LLM APIs

    2.1 Breaking Down the Cost of a Single Request

    LLM APIs are generally billed per token. A token is the basic unit of text the model processes. As a rough guide with common tokenizers, about four characters of English map to one token, and a single Chinese character often maps to one or more tokens, depending on the tokenizer.

    The cost of one request can be broken into four parts:

    1. Cost per request = input tokens × input unit price
    2. + output tokens × output unit price
    3. + tokens written to cache × cache write unit price (as billed by the platform)
    4. + duplicate billing from retries and failed calls

    Most platforms distinguish two kinds of input:

    • Uncached input (cache miss): billed at the input rate on the first call or whenever the cache misses;
    • Cache-hit input: the portion that hits the prefix cache is billed at a noticeably lower hit rate.

    This gives the basic form of the monthly bill:

    1. Monthly bill = Σ(cost per request) + unused portion of a subscription or token package

    Total input = uncached input + cache-hit input. This split is the starting point for every optimization strategy that follows.

    The table below is illustrative only. It shows the calculation logic and does not represent any specific vendor price:

    Item Illustrative unit price (¥ per 1M tokens) Notes
    Input (uncached) 20 Billing baseline
    Cache-hit input 2 Usually 10%–25% of the input price
    Cache write Billed separately per platform rules, or free Used to cache a longer prefix
    Output 100 Usually several times the input price

    From this, the effective input unit price can be written as:

    1. Effective input unit price = (1 - hit rate) × input unit price + hit rate × cache-hit unit price
    • The higher the hit rate, the lower the effective unit price;
    • The more lopsided the input/output ratio, the bigger the payoff from optimizing the input side.

    2.2 A Worked Example: Same Usage, Bill Cut to 70%

    Assume a content platform processes 30M input tokens and 3M output tokens per month (a 10:1 input/output ratio). The optimization plan is:

    1. 60% of calls are offline archiving tasks and move to the async/batch channel, illustratively priced at 50% of the standard rate;
    2. For the remaining online calls, the system prompt and fixed knowledge are stable, so the cache hit rate rises from 0 to 50%;
    3. Prices from the table above are used, ignoring cache-write and retry costs.
    Plan Input cost (¥) Output cost (¥) Monthly bill (¥) vs. baseline
    All realtime, pay-as-you-go, no cache 600 300 900 100%
    Offline tasks routed to batch 420 240 660 ~73%
    Plus 50% cache hit rate 390 240 630 70%

    Two things to note:

    • Looking at the batch step alone, input cost falls to ¥420, matching 0.6 × 300 + 0.4 × 600: 60% of input is settled at half price and 40% at the standard rate, which equals 70% of the standard input cost.
    • Caching only affects the online portion: online input drops from ¥240 to ¥210, about 12.5%, which is exactly “online input share 40% × hit rate 50% × per-token reduction 90%.”

    • The higher the offline share, the bigger the batch gain; the more input is concentrated in the prefix, the bigger the cache gain.

    • The two do not conflict and stack. The online/offline split is itself a product design decision, and cost optimization is a by-product.

    2.3 Quantifying the Bill with Code

    When comparing prices, a short piece of pseudocode turns the “prices are the same” conclusion into something computable and reproducible:

    1. # Illustrative code: a cost estimator. Prices are examples only — check the actual pricing page
    2. PRICE = {
    3. "input": 20, # CNY per 1M tokens, uncached input
    4. "cached": 2, # cache-hit input
    5. "output": 100, # output
    6. }
    7. # Async/batch channel discount factor (illustrative); realtime is 1.0
    8. CHANNEL_RATE = {"online": 1.0, "batch": 0.5}
    9. def estimate(tokens_in, tokens_out, cache_hit_ratio=0.0,
    10. batch_ratio=0.0, channel="online"):
    11. """tokens_in/tokens_out: total input/output tokens (in millions)"""
    12. # Split cache hits from uncached input
    13. cached = tokens_in * cache_hit_ratio
    14. miss = tokens_in - cached
    15. cost = (miss * PRICE["input"]
    16. + cached * PRICE["cached"]
    17. + tokens_out * PRICE["output"])
    18. # Apply the discount factor to the batched portion
    19. cost = cost * ((1 - batch_ratio) + batch_ratio * CHANNEL_RATE[channel])
    20. return round(cost, 2)
    21. # Reproduce the example: 30M input + 3M output
    22. print(estimate(30, 3)) # 900.0, fully realtime, pay-as-you-go
    23. print(estimate(30, 3, batch_ratio=0.6,
    24. channel="batch")) # 660.0, 60% routed to batch
    25. print(estimate(30, 3, cache_hit_ratio=0.5, # 630.0
    26. batch_ratio=0.6, channel="batch"))

    2.4 Sampling and Modeling: Compute “Your” Effective Price

    The estimator’s parameters should not come from guesswork but from real usage. Collect request logs for 7 consecutive days (covering a full work week) and measure three things:

    1. Input/output ratio: how much input and output each account for;
    2. Cacheable share: the proportion of “unchanged across requests” tokens in the prompt;
    3. Deferrable share: the proportion of calls that can tolerate minute-level or longer latency.

    Feed the data into the estimator and you get a monthly cost comparison between the “current setup” and “candidate setups.” Quantify your own usage before comparing prices.


    3. The Four Rule Sets That Open the Gap

    3.1 Prefix Caching: Pay Once for Stable Context

    Billing logic. Prefix caching means that when the opening portion of multiple requests is identical (system prompt, tool definitions, fixed knowledge), the platform caches the result of the first computation and bills subsequent hits at the hit price. Details differ by platform, typically including:

    • Whether it is enabled automatically and how the cache scope is defined;
    • The minimum cacheable length;
    • How long the cache is retained (commonly minutes to hours; some platforms allow extension);
    • Whether writing to the cache is billed separately.

    Always read the footnotes on the pricing page or in the billing documentation. Cache-hit and cache-write prices are often buried in footnotes and easy to miss.

    Engineering points:

    • Stable prefix: put the system prompt, tool definitions, and fixed knowledge first and keep the order; put dynamic content (user input, retrieved results, timestamps, random IDs) last;
    • Versioning: when the prompt is upgraded, replace the whole prefix at once so hit-rate changes are observable;
    • Extend retention on demand: longer retention improves hit rates for high-frequency calls but adds cache-write costs — a trade-off to weigh;
    • Set it sensibly: size retention to your latency requirements and avoid holding cache that goes unused for long periods.
    1. # Illustrative prompt layout
    2. [stable prefix: system prompt + tool definitions + fixed knowledge]
    3. [dynamic part: chunks retrieved this turn + conversation history + user input]
    4. # Counter-example: a timestamp at the top makes every prefix different, so the cache never hits
    5. Current time: 2026-03-08 10:23:41
    6. You are a customer support assistant ...

    When it fits and when to be careful:

    • Good fit for long, stable system prompts, infrequently updated knowledge, and high concurrency — for example virtual customer support assistants, coding assistants, and knowledge-base Q&A.
    • Use with caution when knowledge is highly personalized or changes frequently: every prefix change forces a re-write, and write costs can cancel out the hit savings.

    3.2 Async/Batch Channels: Put “Not in a Hurry” Work Last

    Billing logic. Most platforms offer two call modes:

    • Realtime calls: synchronous responses that meet the latency requirements of interactive use;
    • Async/batch: submit a batch of tasks at once, let the platform schedule them on idle capacity, and retrieve results when done.

    Batch cost is usually lower than realtime (industry discounts commonly run around 50%), at the price of returning results with minutes-to-hours latency and no latency guarantee.

    When it fits and when to be careful:

    • Good fit for offline archiving, batch summarization, content moderation, data cleaning and labeling, model evaluation, and rebuilding knowledge-base indexes. These tasks don’t care when they finish but consume large token volumes.
    • Requests where a user is waiting, and chains that require continuous reasoning, should stay on the realtime channel. A model call made mid-way through an agent run is a typical realtime need: changing one step to “wait a few minutes for the result” makes the product experience unacceptable.

    Engineering points:

    • Use a message queue to carry tasks: split by business priority, write results back to object storage or a database, and design retry and idempotency mechanisms;
    • Account per “task” rather than per “request”: one document may need chunked processing across multiple calls, so cost statistics should be able to aggregate to the business object;
    • “Trading time for cost” only works if the business allows it. If the product promises “results immediately after submission,” don’t sacrifice experience to save tokens.

    3.3 Subscriptions, Token Packages, and Off-Peak Rules: Certainty When Usage Is Steady

    Billing logic. Beyond pay-as-you-go, many platforms offer prepaid forms, commonly three:

    • Token packages / top-ups: prepay for a certain token quota at a unit price below pay-as-you-go;
    • Monthly subscriptions: pay monthly for an included quota, with overage billed pay-as-you-go or at an agreed overage rate;
    • Off-peak rules: lower discounts for calls during specific windows (often overnight low-traffic hours).

    What you gain is a lower unit price. What you pay for it:

    • Quota validity and scope (often limited to certain models — confirm model by model whether all the models you use are included);
    • The overage unit price;
    • Waste risk when usage fluctuates.

    Deciding whether it pays: compute the break-even point. Using a monthly subscription as an example:

    1. Package price P = included quota Q × package unit price p
    2. Break-even Q* = P ÷ pay-as-you-go unit price p0
    3. Monthly usage M > Q* → a subscription is usually cheaper (still verify the overage rate and quota validity)
    4. Monthly usage M ≤ Q* → pay-as-you-go is usually cheaper

    A quick calculation with the illustrative prices: a package costs ¥100 per month and includes 10M input tokens.

    • At pay-as-you-go, 10M × 20 ÷ 1M = ¥200, so the subscription saves half;
    • With an overage rate of 1.2× pay-as-you-go, the break-even point is 100 ÷ (24 ÷ 100) ≈ 4.17M tokens;
    • In other words, monthly usage between roughly 4.17M and 10M tokens still favors the subscription, but the savings shrink.

    Don’t agonize over “what if I exceed it” — check the quota cap instead. A common misconception: fear of running out leads teams to buy for the peak. If the combined cost of “package + pay-as-you-go overage” is still below pure pay-as-you-go, then as long as monthly usage is above the break-even point, you should buy, because the overage portion is still price-protected.

    Off-peak rules require checking whether the window overlaps your business peak and trough. If you move most calls into off-peak hours, online response times slow down — you’re essentially trading experience for cost.

    Combination strategy:

    • Steady, long-running core paths: a package covers the baseline, pay-as-you-go covers the overflow;
    • Volatile, fast-growing new services: start pay-as-you-go, run 2–3 months for a stable curve, then consider prepaying.

    3.4 Model Versions and Regions: Two Variables Beyond Unit Price

    Version evolution. Vendors usually set a retirement schedule for older versions: first stop onboarding new users, then retire them entirely, while recommending migration to the new version. The impact on the bill has three layers:

    1. If the business hard-codes model versions throughout the code, retirement means firefighting;
    2. New versions may be more capable but also more or less expensive, which shifts the unit business cost;
    3. When a new version launches, some platforms offer limited-time free quota, so the migration window costs less.

    Strategy: a configurable model layer. Manage model aliases and parameters centrally in code, and have business code reference only logical names:

    1. # Illustrative model config: version info managed centrally for canary rollout and rollback
    2. models:
    3. flagship: # complex reasoning: code generation, long reasoning chains
    4. alias: "<model version alias>" # adjustable as vendor versions evolve
    5. max_output_tokens: 2048
    6. lite: # simple tasks: extraction, classification, format conversion
    7. alias: "<lite version alias>"
    8. max_output_tokens: 512
    9. routing:
    10. default: flagship
    11. fallback: lite # fallback strategy, also used for cost control

    Version upgrades should come with regression tests: compare old and new versions on output quality and cost using a fixed evaluation set, roll out gradually, and keep a rollback switch.

    Regions and networks. Regions can differ in price, latency, and network paths, and cross-border calls may carry a premium on some platforms. Workloads handling sensitive data must prioritize compliance requirements such as data residency. Call the service in the region where your business is deployed — this lowers latency and reduces the compliance and stability risks of cross-border data transfer.


    4. Scenario-Based Decisions: Which Channel for Which Call

    Task type Characteristics Recommended channel Key actions
    Interactive online User is waiting, latency-sensitive Realtime + prefix caching Stable prompts first; control output length
    Long context / knowledge base Large input, reusable prefix Realtime + prefix caching Fixed knowledge up front; replace wholesale after updates
    Batch offline Delay-insensitive, high volume Async/batch Queue to smooth peaks; idempotent retries; account per task
    Steady always-on Stable, predictable usage Prepaid package + pay-as-you-go backstop Compute the break-even point; verify overage rates and validity

    The biggest gains often come from splitting traffic by request characteristics within one workload. A coding assistant is a typical example:

    • Code completion, code explanation: the user is waiting, so use the realtime channel;
    • Function/variable renaming, batch comment generation, commit-message drafts: use the async channel;
    • Everyday completions: route to the lite model;
    • Tricky defect localization, cross-module refactoring plans: hand them to the flagship model.

    Combined this way, average unit cost is clearly lower than “send every request to the most expensive model.”

    4.2 Selection Checklist

    1. Confirm version and region: is the model generally available, when was the pricing page last updated, and is capacity available in the target region;
    2. Verify cache details: hit price, write price, minimum length, retention;
    3. Verify channel discounts: whether async/batch is offered, the discount size, and result latency;
    4. Verify prepaid rules: package quota, overage rate, validity, and whether the models you use are included;
    5. Check free quota: whether new users or new models get free credits, and the term and scope;
    6. Watch rate limits and stability: rate limits, availability commitments, peak-hour behavior;
    7. Account for add-on costs: data transfer, logging and storage, cross-region traffic;
    8. Normalize pricing units: whether priced per token, per 1K tokens, or per 1M tokens — unify units before comparing;
    9. Run a small-traffic test: run your own real traffic on several platforms for a week each, and compare “cost per unit of business” rather than “price per token”;
    10. Keep the ability to switch: wrap model calls in a unified layer and avoid deep lock-in to a single platform.

    5. Engineering Practices That Keep the Bill Down

    5.1 Measure Before Optimizing

    No measurement, no optimization. At minimum, collect these metrics:

    Metric Meaning Optimization direction
    Cache hit rate Share of cache-hit input in total input Prefix stability, knowledge update frequency
    Average output length Output tokens per request Prompt constraints, output budgets
    Cost per unit of business Cost to process one business object (document, ticket, commit) Business-side optimization and routing strategy
    Failure/retry rate Share of failed calls in total calls Timeout settings, parameter validation
    Channel mix Share of realtime, batch, and package traffic Whether channel choices are sound

    5.2 Prompt and Context Governance

    • Retrieve, then rerank: in RAG pipelines, recall first and rerank after, putting only genuinely relevant chunks into the prompt instead of “stuffing everything into the context”;
    • Summarize and compress: compress long documents before reasoning, trading a few extra calls for a large reduction in subsequent input;
    • Structured output: require strict formats (such as JSON) to reduce “explanatory” content from the model and lower output tokens.

    5.3 Semantic Caching in the Application Layer

    Platform-side prefix caching requires an identical opening. The application layer can add a semantic cache:

    • Normalize user questions and compute a fingerprint;
    • When a similar question hits the cache, return the cached answer directly without calling the model;
    • Strictly limit the scope: exclude time-sensitive content and personalized answers.

    5.4 Model Routing and Cascading

    Use a lightweight classifier or rules to send simple requests (classification, extraction, format conversion) to a small model and reserve complex reasoning for a large model. At the same time, set timeouts and failure fallbacks so that “cost reduction” doesn’t turn into “quality reduction.”

    5.5 Quotas and Budget Guardrails

    Set token budgets and rate caps for each team and each business line, with monitoring and alerting (general cloud capabilities such as logging and alerting services are enough). Abnormal traffic (retry storms, malicious bursts) can be intercepted before it reaches the bill.


    6. Rollout Path: From Price Comparison to a Halved Bill

    1. Profile (week 1): sample 7 days of real usage and compute the input/output ratio, cacheable share, and deferrable share;
    2. Model (week 1): feed the sampled data into the estimator to get a baseline cost and how much batch, caching, and packages can each save;
    3. Rework (weeks 2–3): start with the cheapest changes: move offline tasks to batch; reorder prompts so stable content comes first; add a configurable model layer and routing;
    4. Validate (week 4): run a small-traffic canary, compare output quality against cost per unit of business, and confirm no quality was traded for cost;
    5. Institutionalize (monthly): review cache hit rate, channel mix, price changes, and version changes monthly, and keep adjusting the strategy.

    7. Common Pitfalls and How to Avoid Them

    Pitfall What’s wrong with it How to avoid it
    Comparing only “price per 1M tokens” Ignores channels, caching, and usage structure Compare cost per unit of business; profile your usage before comparing prices
    Believing “the pricier model is the better model” Using a large model for simple tasks is both slower and more expensive Use routing and cascading to match models to tasks
    Frequently tweaking prompts Every change invalidates the cache Version prompts and keep fixed content at the head
    Treating “has a discount” as “should use it” Sacrifices latency for waiting users to save tokens Send latency-sensitive tasks to the realtime channel
    Buying packages sized to the peak Unused quota goes to waste Compute the break-even point; package for the baseline, pay-as-you-go for overflow
    Hard-coding versions into business code Version retirement causes outages Configure the model layer centrally and pair it with regression tests

    Conclusion

    Cost governance for LLM APIs is essentially turning “buying tokens” into “running tokens.”

    • Converging unit prices are the norm; bill differences come from rules: caching, batching, subscriptions, and versions.
    • First quantify your own call profile, then choose channels by task characteristics, and finally lock in the savings with measurement, routing, and guardrails.

    Cutting the monthly bill at the same usage and the same quality doesn’t depend on finding “the cheapest provider.” It depends on putting every call in the most appropriate place.