How to Calculate Per-Task Cost After Flagship LLM API Price Hikes

    This article explains LLM API billing with example prices: standard, long-context, and cache-hit rates. It shows how to estimate a single request, compare new vs. old models, and cut cost with caching, shorter outputs, and routing. Prices are USD per million tokens and are for illustration only.

    This article uses example prices to explain how large-model APIs are billed and how to estimate cost. Prices are in USD per million tokens and exist only to walk through the math. Check each vendor’s public list prices and billing rules before you use a model.

    What a price increase actually means

    In the example, the next-generation flagship model’s input and output unit prices are both 2.5× the previous flagship’s example rates. That ratio only shows relative scale. To judge a real vendor, swap in that vendor’s official prices for both generations.

    Vendors rarely disclose cost structure. These three points are technical inferences from how inference works, not official statements:

    1. Larger models: more parameters and activation volume mean more compute per forward pass.
    2. Heavier inference: long context and multimodal input increase KV-cache memory and attention work.
    3. Tight high-end GPU supply: unit compute cost of flagship inference GPUs is hard to amortize in the short term.

    For developers, list price is only the starting point. Within one model, different billing tiers can differ by several times, so understand the structure before talking about total cost.

    How the three billing tiers work

    Most mainstream LLM APIs bill in three ways: standard, long-context, and cache-hit. The example model below is used throughout.

    1. Standard tier: output is 5× input

    If a request’s total input tokens are at most 272K, the standard tier applies: $10/M input tokens and $50/M output tokens.

    The threshold is defined here as total input tokens on a single request, including system prompt, history, user input, and retrieved content. Whether output tokens count, whether cache hits count, and whether the split is per request or per context window all differ by vendor. Read the official billing docs.

    Output is 5× input because generation is autoregressive. Each new token requires a full forward pass. Prefill can process the whole input in parallel; decode cannot, so the marginal cost of an output token is higher.

    Output length often dominates total cost:

    • Request A: 1K input, 2K output. Cost = 1,000 × 10 + 2,000 × 50 = 110,000 → $0.11.
    • Request B: 8K input, 0.5K output, no cache. Cost = 8,000 × 10 + 500 × 50 = 105,000 → $0.105.

    Input length differs by 8×; totals are almost the same. Longer output drives the bill.

    2. Long-context tier: the whole request is repriced past the threshold

    Above 272K, input rises to $20/M and output to $75/M—about 2× and 1.5× the standard rates.

    This is not a surcharge on the overflow only. One token over 272K reprices the entire request. Requests near the threshold need extra care.

    Higher long-context cost follows from:

    • Prefill attention: standard self-attention is O(n²). Doubling length roughly quadruples that work. FlashAttention and similar reduce constants, but long sequences still cost more than short ones.
    • Decode attention and KV cache: each new token reads all past keys/values. Per-token attention is O(n). KV-cache memory also grows linearly with context.
    • Scheduling and concurrency: very long requests occupy hardware longer and retries are more expensive. Providers may lower concurrency per GPU, and that cost shows up in unit price.

    These are principle-based inferences, not vendor statements.

    3. Cache-hit price: leverage on repeated prefixes

    In the example, cached input is $1/M—one-tenth of standard input. A same-tier competitor example is $0.25/M. This article does not pin competitor versions or accounting; compare against official docs.

    Cache helps most when the system prompt is fixed, multi-turn chat is frequent, or agents repeatedly send tool definitions. Most of the input then stays the same and hit rates can be high.

    Confirm two things: whether writing the cache is billed separately, and cache TTL/expiry. Vendors differ a lot; ignore them and your estimate will be wrong.

    Price summary

    Billing item Example price (USD/M tokens) Trigger Notes
    Standard input 10 Total input ≤ 272K Whether cache tokens count: see official docs
    Standard output 50 All output on a standard request Autoregressive decode; higher unit price
    Long-context input 20 Total input > 272K Entire request billed as long-context
    Long-context output 75 All output on a long-context request About 1.5× standard
    Cache-hit input 1 Stable prefix that hits Example assumes the same cache price in both tiers
    Same-tier competitor cache hit 0.25 Comparison only Verify competitor version and accounting

    Estimating cost for a single task

    Whether spend is worth it depends on total cost per task, not unit price alone. You need four numbers: total input tokens, cached tokens among them, output tokens, and the tier implied by total input.

    The function below follows the example rules:

    1. def estimate_cost(prompt_tokens, cached_tokens, output_tokens, threshold=272_000):
    2. # Example assumption: long-context cache-hit price matches standard; check official docs
    3. if prompt_tokens <= threshold:
    4. price_in, price_out = 10, 50
    5. else:
    6. price_in, price_out = 20, 75
    7. price_cache = 1
    8. fresh_tokens = prompt_tokens - cached_tokens
    9. cost = (
    10. fresh_tokens * price_in
    11. + cached_tokens * price_cache
    12. + output_tokens * price_out
    13. ) / 1_000_000
    14. return cost # USD

    Example 1: 300K input, 280K cached, 2K output. Over threshold, so long-context rates apply.

    • With cache: fresh 20K × 20 = 400,000; cached 280K × 1 = 280,000; output 2K × 75 = 150,000. Total 830,000 → about $0.83.
    • Without cache: input 300K × 20 = 6,000,000; output 150,000. Total 6,150,000 → about $6.15.

    Cache cuts this request by about 86%. For long-context apps, cache often matters more than list-price differences.

    Is the new model cheaper?

    Assume both input and output prices are 2.5× the previous generation. If token counts stay the same, cost is 2.5×. The new model only saves money if it uses fewer tokens or raises pass rate.

    Use:

    new task cost ÷ old task cost = 2.5 × (new tokens ÷ old tokens) × (old pass rate ÷ new pass rate)

    A ratio under 1 means the new model is cheaper. If both pass at 60%, new tokens must fall below 40% of old tokens to offset 2.5× pricing. If the new pass rate is 90%, tokens only need to fall below 60% of old, because 2.5 × 0.6 × (60% ÷ 90%) = 1.

    Cost-reduction checklist

    Ordered by typical ROI, with decision thresholds:

    1. Put a stable prefix first. System prompt, tool defs, and standing rules at the start; timestamps, user IDs, and random values later. If cache hit rate stays under 20%, check whether the prefix changes every time.
    2. Track cache hit rate. Log input total, cache hits, and output per request. Above ~50% hits, cache work is usually the highest-ROI change.
    3. Cap output. Set a sensible max_tokens and ask for short, structured answers. If output is more than half the bill, optimize output first.
    4. Control context length. Crossing the threshold reprices the whole request. Near 272K, summarize or truncate. Leave headroom—e.g. start compressing history around 250K.
    5. Tighten prompts. Drop duplicate instructions and unused examples. Shorter fixed text means less billed input every call.
    6. Route by difficulty. Classification, extraction, and format conversion go to smaller models; only hard reasoning hits the flagship. Validate small-model pass rate on a sample set; do not route if it fails.
    7. Use batch APIs for non-realtime work. If the vendor offers a batch discount, confirm scope and window.
    8. Limit retries. Failures that retry are billed again. Cap retries and separate retryable errors from ones that need a changed request.

    How to decide

    Run real task samples on both old and new models. Record tokens and pass rate per task, then apply the ratio above. Switch if the new model is cheaper per successful task or if quality gains have a clear payoff. If neither wins, keep the old model and use the new one only on high-value tasks.