LLM API Pricing: How to Evaluate and Reduce Inference Costs

    The cheapest LLM API per token is not always the cheapest way to complete a task. This article explains how input, output, and cached tokens are priced, how to benchmark models by cost per successful outcome, and how to reduce inference spending through prompt compression, caching, model routing, output limits, and batch processing. It also covers when self-hosting an open-weight model may make economic sense.

    As LLM providers compete on price, engineering teams must compare changing rates while keeping production AI bills under control. A rate card tells you what a token costs, but it does not tell you how many tokens or retries a model needs to deliver a usable result. Start by understanding how requests are billed, then measure costs on your own workloads.

    1. Understand the three layers of LLM API pricing

    Most LLM APIs charge by the token. Three parts of the pricing model matter when estimating inference costs:

    1. Separate input and output rates. Output tokens often cost three to six times as much as input tokens. In conversational applications, limiting response length can therefore have a bigger impact than shortening the prompt. For illustration, input might cost $2–$5 per million tokens and output $10–$30 per million tokens. A lightweight tier might charge around $1 for input and $6 for output per million tokens.
    2. Cache-hit discounts. Some providers discount repeated prompt prefixes, such as system instructions or long context templates. On a cache hit, the rate for those input tokens can drop to one-tenth of the standard input rate or less. For production workloads that rely heavily on templates, this can substantially reduce overall spending.
    3. Model tiers. Providers often offer flagship, balanced, and lightweight models, with prices differing by a factor of three to five. The goal is not to choose the cheapest tier, but to match the model to the difficulty of the task.

    2. Compare cost per successful outcome, not price per token

    A per-million-token rate is useful for estimating the cost of a request, but it is not enough to compare models. A better measure is what you pay for a usable result on the same workload:

    1. Inference cost per attempt = (Input tokens × Input price per token)
    2. + (Output tokens × Output price per token)
    3. Cost per successful outcome = Total inference cost / Number of successful outcomes

    Define success according to the task: it might mean a correct answer or a test case that passes. Include the cost of failed attempts and retries in the total. A lower-priced model can end up costing more on complex reasoning tasks if it needs several retries or generates longer responses.

    To compare candidates:

    • Build a fixed evaluation set. A few hundred representative examples from real workloads are enough to get started.
    • Run each model with the same prompts and record its accuracy and token usage.
    • Rank models by cost per successful outcome rather than by their listed token rates.

    3. Five ways to reduce inference costs

    1. Compress and structure prompts. Remove redundant examples and use compact formats, such as JSON instead of long prose, to convey structured information. This can reduce input token usage by 20%–40%.
    2. Reuse cacheable context. Keep stable system instructions and domain-specific context in a consistent prefix so repeated requests can qualify for cache discounts. This can be especially useful in retrieval-augmented generation (RAG) applications that reuse part of their context.
    3. Route requests by task complexity. At the gateway, send straightforward classification, extraction, and formatting tasks to a lightweight model. Reserve flagship models for harder reasoning and generation tasks. A simple routing example looks like this:

      1. def route_model(task):
      2. if task.type in ("extract", "classify", "format"):
      3. return "light-model"
      4. if task.type in ("reason", "write", "code"):
      5. return "flagship-model"
      6. return "balanced-model"
    4. Limit output length. Set a max_tokens cap and keep structured outputs concise. For example, if the response must be JSON, request only the fields the application needs. This directly reduces spending on the more expensive output tokens.

    5. Check batch and asynchronous pricing. Where providers offer discounted batch or asynchronous inference, use it for workloads that do not need an immediate response, such as offline data processing or document batches.

    4. When self-hosting an open-weight model makes sense

    An API is not the only option. Enterprises can also deploy open-weight models on their own infrastructure. The economics depend on three trade-offs:

    • GPU utilization changes the cost per token. With self-hosting, you pay for GPU capacity rather than individual tokens. As more work runs on that capacity, the cost per token falls, potentially reaching a point where self-hosting is cheaper than API usage.
    • Customization can make a smaller model viable. Fine-tuning for a specific domain can bring a smaller model closer to the performance of a larger one on that workload, reducing inference costs.
    • Engineering and operations add costs. Quantization, KV cache management, batch scheduling, and ongoing operations require staff time. At low volumes, that overhead can outweigh the savings.

    As a rough screening criterion, consider running the numbers when monthly demand can sustain GPU utilization above 50% and your team has the skills to operate an inference service. That utilization level is a reason to compare costs, not a universal break-even point.

    5. LLM selection checklist

    1. Identify your task types and how they vary in difficulty, then estimate the share of token usage each model tier would handle.
    2. Measure accuracy and token usage for candidate models on your own evaluation set.
    3. Compare cost per successful outcome instead of relying on listed token prices.
    4. Check whether cache discounts, batch pricing, and model tiers fit your request patterns.
    5. For high-volume workloads, compare the cost of self-hosting with continued API use.
    6. Set up usage monitoring and alerts, break down spending by business line, and track cost per successful outcome over time.

    Conclusion

    Competition on LLM API pricing reflects differences in inference efficiency and the ability to supply compute at scale. Application developers benefit from that competition, but the cheapest provider on paper may not be the cheapest for a particular workload. Rates will change; a repeatable benchmark and a few practical engineering controls give teams a more reliable way to manage long-term inference costs. Platforms such as Baidu AI Cloud’s Qianfan can support this approach by providing unified access to multiple models and cost management tools.