LLM API Billing Rules and Cost Optimization: Why the Same Unit Price Can Lead to Different Bills

    This article explains why comparing LLM API unit prices alone is not enough to estimate real costs. It breaks down token-based billing components such as input, output, cache hits, cache writes, subscription plans, and overage fees, then presents a practical framework for workload profiling, cost estimation, and engineering-level optimization.

    1. Why the Same List Price Can Produce Different Bills

    When teams compare LLM API services, a common approach is to check each platform’s unit price table. If two providers show the same standard input price and output price, it is easy to assume there is no cost difference. In practice, the final bill is determined by multiple factors. The standard unit price is only one part of billing. Whether batch jobs receive a discount, whether repeated requests trigger caching, whether a plan includes an allowance, whether peak and off-peak periods are priced separately, and whether the region and model version change can all affect the final amount.

    Cost comparison should therefore return to “the result of the same usage under different billing rules.” Looking only at a unit price table cannot reveal actual spending.

    2. What Makes Up LLM API Billing

    Most LLM APIs bill by tokens. A token is the smallest metering unit the model uses to process text. Chinese and English text have different token conversion ratios; refer to the provider’s documentation for details. A single call usually incurs the following types of costs:

    • Input token cost: the length of the user prompt, context, and conversation history.
    • Output token cost: the length of the model-generated response. Output unit prices are usually higher than input unit prices because generation requires computing each token one by one.
    • Cache hit cost: when a request prefix matches a recent request, the provider can reuse already computed results, and the matched portion is billed at a lower unit price.
    • Cache write cost: some services charge separately for newly written cache and set different prices by cache time-to-live (TTL).

    The structure of a monthly bill can be summarized as:

    1. Monthly bill = uncached input cost + cache hit cost + cache write cost + output cost + plan fixed fee + overage fee
    2. Uncached input cost = uncached input tokens × input unit price
    3. Cache hit cost = hit tokens × cache-hit unit price
    4. Cache write cost = written tokens × cache-write unit price (by TTL tier)
    5. Output cost = output tokens × output unit price

    Once this structure is clear, the directions for reducing cost become clear: reduce unnecessary output, improve cache hit rates, move tasks that can be completed offline to discounted channels, and let plan allowances cover stable baseline load.

    3. Five Types of Billing Rules That Affect the Bill

    1. Batch offline discounts

    Some services offer batch APIs where jobs are submitted asynchronously and results are returned within an agreed time window. Providers usually bill these at a lower price than real-time calls. These APIs are suitable for data cleaning, label generation, document summarization, offline evaluation, and other tasks that are not latency-sensitive. The key is to identify which tasks do not require an immediate response. Moving those tasks from the real-time channel to the batch channel can directly lower the bill.

    2. Caching mechanisms

    There are two types of caching, and they need to be accounted for separately.

    The first is automatic caching. When the provider detects a repeated request prefix, it automatically reuses the already computed portion. To improve hit rates, place fixed content (system instructions, role settings, knowledge base snippets) at the beginning of the prompt and put variable content (user questions, timestamps, random IDs) at the end. Reversing the order makes every request prefix different, so caching almost never takes effect.

    The second is cache write billing. Some services charge an additional fee for writing to cache and divide it into tiers based on TTL. A longer TTL may have a higher write unit price, but in scenarios with long intervals between requests, it can avoid repeated writes. When choosing a TTL, calculate based on the average request interval and reuse count rather than simply selecting the longest tier.

    3. Subscription plans and overage billing

    Plans usually involve paying a fixed fee monthly or weekly in exchange for a certain allowance of call usage, with usage beyond that billed on demand. Whether a plan is cost-effective depends on how stable actual usage is. When usage is stable over time and above the plan threshold, a plan has an advantage. When usage fluctuates widely and peaks are short, on-demand billing is more flexible. Some plans also restrict which models are available, so confirm whether the models you use are covered.

    4. Time-based and regional differences

    Some services apply different prices or allowance rules at different times, such as separate billing for peak and off-peak periods. In addition, the same model deployed in different regions may have different unit prices, and overseas regions are often priced higher than domestic regions. When choosing a region, consider price, network latency, and data compliance requirements together. Scheduling requests to lower-cost time periods is a common practice, but only if the business can accept the corresponding response time.

    5. New-user credits and model iteration

    Some services provide a certain amount of free credits for newly opened accounts. These are suitable for testing and validation and should not be treated as a long-term cost assumption. In addition, model versions are updated; older versions may stop accepting new users and be retired on an agreed date. When migrating to a new version, reevaluate output length, prompt effectiveness, and caching behavior in addition to the unit price, because these changes all affect the bill.

    4. A Framework for Choosing a Billing Model

    Technical teams can choose a billing approach based on business characteristics. A general framework is below.

    • Offline batch tasks: prioritize batch APIs. When task volume is large and timeliness requirements are low, discount benefits are most obvious.
    • Real-time interactive tasks: prioritize response speed first, then reduce costs through caching and output control.
    • Stable high-load services: evaluate subscription plans. First collect the average daily token usage and peak values for the past three months, then calculate the break-even point between the plan and on-demand billing.
    • Services with large fluctuations: rely mainly on on-demand billing and set budget caps and alerts.
    • Teams with existing cloud infrastructure: connecting to model services within the same cloud environment can reduce cross-network transmission and operational costs. If workloads run on Baidu AI Cloud, you can verify the current model billing details in the corresponding console.

    Before choosing, it is advisable to create a usage profile recording input length distribution, output length distribution, request frequency, the proportion of tasks that can be processed offline, and cache reuse rate. Without this data, any price comparison lacks a basis.

    5. Cost Estimation Example

    Assume a business uses 500M input tokens and 100M output tokens per month, with half of the input hitting cache. The unit prices below are hypothetical values for calculation only and do not represent the prices of any specific service:

    • Input unit price: CNY 10 per million tokens
    • Cache-hit unit price: CNY 1 per million tokens
    • Output unit price: CNY 40 per million tokens

    Without caching:

    1. Input cost = 500 × 10 = CNY 5,000
    2. Output cost = 100 × 40 = CNY 4,000
    3. Total = CNY 9,000

    With caching enabled, uncached input is 250M tokens:

    1. Uncached input cost = 250 × 10 = CNY 2,500
    2. Cache hit cost = 250 × 1 = CNY 250
    3. Output cost = 100 × 40 = CNY 4,000
    4. Total = CNY 6,750

    Caching alone saves 25%. If some of these tasks can go through the batch channel and that channel is assumed to offer a 40% discount, the cost for the corresponding portion can fall further. The combined result of the two optimizations reflects real cost far better than looking at any single unit price.

    6. Engineering-Level Cost Reduction Methods

    Billing rules are only external conditions. Engineering implementation determines whether those rules can be fully used.

    1. Stabilize prompt structure

    Keep system instructions, examples, and specification documents fixed at the beginning of requests, and avoid inserting timestamps or request IDs into them. You can use version numbers to identify prompt templates and update them consistently when the version changes, reducing meaningless prefix changes.

    2. Control output length

    Set a maximum output token count in requests and specify the output format clearly in the prompt. For example, require results to be returned as JSON fields to avoid long explanations generated by the model. When output unit prices are high, this often provides the largest benefit.

    3. Split real-time and offline queues

    Build two processing paths. The real-time path handles user requests, and the offline path handles batch tasks. Offline tasks are first queued and then submitted together by window. The queue can be implemented with a general message queue component, and the submission time, completion time, and cost of each task should be recorded.

    4. Monitoring and budget alerts

    Track token usage and costs by project, module, and model, and set alert thresholds for daily and monthly budgets. When abnormal growth occurs, it should be possible to quickly locate the specific prompt version or business interface. Monitoring data can be written to a log service and pushed through monitoring and alerting components.

    5. Retries and idempotency

    During network jitter or rate limiting, retries can lead to duplicate billing. Set idempotency keys for requests to prevent the same task from being submitted multiple times. Retry policies should use exponential backoff and limit the maximum number of attempts.

    6. Rate limiting and degradation

    Set concurrency and rate limits for each business to prevent sudden traffic from causing overage costs. When the budget approaches its cap, you can automatically degrade to a lower-cost processing path, such as shortening context or switching to summary mode.

    7. Implementation Checklist

    Before going live or adjusting a billing plan, check each item:

    • Have input, output, and cache-hit data for the past three months been collected?
    • Have real-time tasks and offline tasks been separated, and has the applicability of the batch channel been evaluated?
    • Have the models, allowances, and overage rules covered by the plan been confirmed?
    • Have the unit prices and latency of the selected region been verified?
    • Has the model version lifecycle been confirmed, and has a migration timeline been planned?
    • Has the prompt prefix been fixed, and has the actual cache hit rate been measured?
    • Have output length limits and budget alerts been set?
    • Have idempotency controls been added for retries and batch submissions?

    Cost optimization is an ongoing process. Every model update, prompt adjustment, or business growth should trigger a rerun of the usage profile and validation of assumptions against actual bills. Billing decisions based on data are more reliable than simply comparing list prices and better support long-term cost management.