How to Estimate LLM API Token Costs After a Price Increase

    A practical guide to estimating LLM API costs after price changes: why input, output, and cached tokens matter, which variables drive the bill, a simple cost model, and how to evaluate value without jumping to a full model switch.

    How to Estimate LLM API Token Costs After a Price Increase

    Why “price per 1M tokens” is not enough

    When developers evaluate LLM API cost, a common question is: “How much is 1 million tokens?” The answer is rarely a single number. Billing is usually split into three dimensions:

    1. Input tokens (prompt / input): context sent to the model, including system prompts, conversation history, and retrieved content.
    2. Output tokens (completion / output): the model’s generated response.
    3. Cached tokens (cache read / cached input): repeated input prefixes that some providers bill at a lower cache rate.

    Unit prices for these three types often differ by several times. Output is typically several times more expensive than input. Comparing a single marginal price outside a real workload can badly misestimate actual spend.

    Four variables that shape the real bill

    1. Asymmetric input and output prices

    In common pricing structures, output is often 3–10× the input rate. That means:

    • For long summarization, code generation, and report writing, output dominates, so output price drives cost.
    • For retrieval QA and knowledge-base queries, input dominates (large context injection), so input price drives cost.

    Choosing a model by input price alone often underestimates generation-heavy workloads.

    2. Input/output token mix

    A practical formula is:

    1. cost ≈ input_tokens × input_price
    2. + output_tokens × output_price
    3. + cached_tokens × cache_price

    Assume input is $2 per million tokens and output is $12 per million tokens:

    Scenario Input tokens Output tokens Cost per call
    Summarization (long output) 3,000 1,500 $0.024
    Knowledge-base QA (long input) 12,000 300 $0.0276

    Cheap input still adds up at high volume. Low unit price is not the same as low total cost.

    3. Caching for frequently repeated context

    If system prompts, few-shot examples, or retrieval prefixes repeat across many requests, context caching can cut cost. Cache hits are often about one-tenth of standard input price. Whether caching is worthwhile depends on:

    • reuse of the same prefix above about 50%;
    • prefix length much larger than the changing tail;
    • whether cache TTL matches request spacing.

    4. Context length and tiered pricing

    Long-context work (for example full-document analysis) often sits in higher price bands. Many providers use tiers: one rate within 128K, higher rates beyond that. Fitting more into a long window is not automatically cheaper. Retrieval compression and chunking are often more economical.

    Build a simple cost model in code

    Instead of estimating by hand each time, keep prices and usage in one function:

    1. def estimate_cost(
    2. input_tokens: int,
    3. output_tokens: int,
    4. cached_tokens: int = 0,
    5. input_price: float = 2.0, # USD per million tokens
    6. output_price: float = 12.0,
    7. cache_price: float = 0.2,
    8. ) -> dict:
    9. """Estimate per-call cost from per-million-token prices."""
    10. m = 1_000_000
    11. cost = (
    12. input_tokens / m * input_price
    13. + output_tokens / m * output_price
    14. + cached_tokens / m * cache_price
    15. )
    16. return {
    17. "total_cost": round(cost, 6),
    18. "input_cost": round(input_tokens / m * input_price, 6),
    19. "output_cost": round(output_tokens / m * output_price, 6),
    20. "cache_cost": round(cached_tokens / m * cache_price, 6),
    21. }
    22. # Example: one RAG Q&A call
    23. print(estimate_cost(input_tokens=8000, output_tokens=400, cached_tokens=5000))

    Log input, output, and cache-hit tokens per request, then aggregate by day and product line to get a real baseline. Without measurement, there is no optimization.

    A value framework after a price increase

    If a primary model gets more expensive, you do not have to migrate immediately. Evaluate as follows.

    1. Profile the actual task mix

    Use recent traffic: average input length, average output length, cache hit rate, and peak concurrency. Apply candidate price tables to that distribution, not to idealized samples.

    2. Tier selection instead of a full swap

    • Hard reasoning and code refactoring: keep a high-capability tier and control volume.
    • High-frequency simple tasks (classify, extract, rewrite): move to a lower-cost tier.
    • Offline batch jobs: prefer batch endpoints with discounts when available.
    • Long-context tasks: compress or chunk first rather than relying on a huge window.

    3. Compress and cache before switching models

    Before changing models, do three things:

    1. Tighten the system prompt: drop redundant instructions and unused examples.
    2. Control output length: ask for concise answers and limit list size.
    3. Enable caching: put stable prefixes in a cacheable region.

    These steps often cut token use by 30%–60% without a quality drop.

    4. Validate quality against cost

    After a switch or optimization, run a fixed eval set. Keep scored examples and re-run after each change. Track cost versus pass rate so savings do not come at the expense of product quality.

    Cost-control checklist

    • Token caps: set max tokens on output so a single bad request cannot inflate the bill.
    • Circuit breakers: alert on retries, concurrency, and unusually long inputs.
    • Budget alerts: monthly budgets and alerts per project or API key.
    • Separate environments: use cheaper tiers or sampled traffic in test.
    • Review prices regularly: keep the price table in config so a change is a single update.
    • Track cache hit rate: if it is below expectation, check prefix stability.
    • Use batch where possible: non-realtime work can take batch discounts.

    Closing

    LLM API prices move. Value for money is not a static number; it depends on task mix, token structure, and optimization. Build your own cost observability and estimates, and let real data drive selection: compress first, then cache, then tier, and only then switch models. Treat tokens as a measurable, tunable resource so cost stays controllable and quality stays stable when prices change.