LLM API Selection and Cost Optimization: A Practical Guide

    This guide explains why the lowest per-token price does not always mean the lowest total cost when choosing an LLM API channel. It covers how to build a unified pricing baseline with weighted input/output rates, currency and unit normalization, and separate cache pricing, along with three counterintuitive findings about official versus reseller channels, model version availability, and channel-specific discounts. It also provides a repeatable verification workflow, engineering techniques for cost reduction such as tiered routing, context management, caching, batching, output limits, and observability, plus a checklist of common mistakes to avoid.

    1. Background: Why a Low Unit Price Does Not Mean a Low Total Cost

    When integrating large model capabilities into real projects, a frequent and easily underestimated problem is that the same model with the same capabilities can be priced several times apart across different access channels, and price levels do not correlate reliably with the nature of the channel (official direct access versus third-party resale). Many teams compare only a single number on the official pricing page during selection, then find that the actual bill deviates severely from expectations.

    There are usually three causes of this deviation:

    • Channel pricing is not synchronized: Reseller pricing is maintained independently by the channel and may include markups, subsidies, or promotional periods, so it is not in sync with the model provider’s official pricing.
    • Versions are inconsistent: A channel may offer a previous-generation, lightweight, or domain-specialized version rather than the flagship version promoted by the provider, so a direct price comparison leads to the wrong conclusion.
    • Measurement bases are not unified: Input and output unit prices differ substantially, and cache-hit prices are calculated separately. Without weighting, comparison results have almost no reference value.

    Therefore, the first step in selection is not to find the “cheapest channel,” but to establish a verifiable and reproducible price comparison method.

    2. Establishing a Unified Measurement Basis for Horizontal Comparison

    2.1 Weighted Unit Price Instead of List Price

    In real workloads, the ratio of input tokens to output tokens is often not 1:1. For intelligent coding and AI Agent applications, for example, context and code snippets are repeatedly fed in, so the input share is high, while generated results are relatively long, so the output share is usually higher. A common engineering approximation is to weight 30% input and 70% output:

    1. weighted unit price = input price × 0.3 + output price × 0.7

    For long-document summarization, the ratio may reverse; for conversational question answering, the output share is even higher. The key point is: once the basis is fixed, use the same ratio for every channel across the whole process, otherwise the comparison table itself is noise.

    2.2 Currency and Unit Normalization

    Different channels may display prices in different currencies and billing units (per million tokens, per thousand tokens). In practice, fix one conversion rate and unit (for example, normalize everything to CNY per million tokens), and explicitly note the conversion basis and capture time in the table so that later reviews remain traceable.

    2.3 List Cache and Batch Processing Separately

    In scenarios with cache reuse, the input price for cache hits is usually significantly lower than the regular input price. This portion should not be mixed into the main table but measured separately as “optimized cost,” otherwise the real bill will be over- or underestimated.

    3. Three Counterintuitive Findings About Channel Differences

    After checking the same set of models across multiple channels one by one, you typically reach a few conclusions that run counter to intuition, and they directly determine the selection strategy:

    Finding 1: Official direct access is not necessarily the most expensive, and third parties are not necessarily cheaper. Reseller prices are set independently by the channel, so it is entirely possible for a resale price to be far above the official price, with multiples of several times not being rare. Treating “resale must be more expensive” or “resale must be cheaper” as a premise is a common starting point for losing control of the bill.

    Finding 2: The flagship version is not available on every channel. Newly released flagship models are often available first through official channels, while third-party channels may still be on the previous generation or offer only lightweight or specialized versions. The correct approach here is to mark “no same version on this channel” rather than forcing numbers together from different generations, which would make the entire comparison table meaningless.

    Finding 3: Discount levels are a channel attribute, not a model attribute. The same channel may offer discounts on different models ranging from steep cuts to close to list price. This means channel selection should be decided per model, not locked to a single provider for the whole project.

    4. An Actionable Verification Process

    It is better to make price comparison a one-off script plus periodic re-checks than to read pages manually:

    1. Lock the comparison target: Define a triple of “model + version + context specification”; any mismatch means the items are not comparable.
    2. Enumerate the channel list: Official direct access, model services on major cloud platforms, third-party aggregation platforms, overseas aggregation gateways, and record each one.
    3. Capture and record metadata: Price, currency, billing unit, cache price, capture time, and a note on the page source.
    4. Normalize and weight: After unifying currency and units, apply the weighting formula to produce comparable numbers.
    5. Mark gaps: Anything with no same version, no public pricing, or a dynamically rendered page that cannot be captured must be explicitly marked, with no speculative filling.
    6. Run periodic regression: Prices and versions change, so re-run on a fixed cycle and archive historical results for trend analysis.

    A sample data structure can be very simple:

    1. {
    2. "model": "general-purpose LLM - flagship",
    3. "version": "x.y",
    4. "channels": [
    5. {"name": "official direct", "input": 5.32, "output": 18.0, "cache": null, "currency": "CNY/M"},
    6. {"name": "cloud platform A", "input": 20.40, "output": 60.0, "cache": 5.0, "currency": "CNY/M"},
    7. {"name": "aggregation platform B", "status": "no_same_version"}
    8. ],
    9. "weighted_ratio": {"input": 0.3, "output": 0.7},
    10. "captured_at": "2026-08-06"
    11. }

    5. Engineering Techniques for Cost Optimization

    Price comparison only optimizes the upper bound; real bill reduction depends on architectural measures:

    • Tiered routing: Split requests by difficulty, sending simple tasks to lightweight models and complex reasoning to flagship models. Routing can be done with rules, a small classification model, or confidence thresholds.
    • Context governance: Trimming history, summarization and compression, and reranking retrieved snippets directly reduce input tokens; the gains are especially clear in input-heavy scenarios.
    • Cache reuse: Cache stable system prompts, tool definitions, and long document prefixes, with hit portions billed at the cache price.
    • Batching and asynchrony: Merge requests for offline tasks and use off-peak windows and batch channels.
    • Output length constraints: Explicitly cap maximum generation length and use structured output to avoid invalid, redundant output driving up cost.
    • Observability: Bring token usage, cache hit rate, and per-request cost into logging services and monitoring/alerting systems, tagged by business line, so the source of cost anomalies can be located.

    A simplified routing example:

    1. def route(prompt: str, need_strong_reasoning: bool):
    2. # the lightweight model handles high-confidence simple requests, the flagship model covers complex reasoning
    3. if not need_strong_reasoning and len(prompt) < 2000:
    4. return "light_model"
    5. return "flagship_model"

    6. Common Pitfalls Checklist

    • Comparing only input prices while ignoring output prices, causing severe budget overruns in output-heavy scenarios.
    • Comparing different generations of versions and wrongly concluding that “a channel has extremely high cost performance.”
    • Ignoring cache prices and cache hit rates, which distorts the cost model.
    • Binding the whole project to a single channel and giving up the gains from choosing channels per model.
    • Leaving no capture time or source notes in the comparison table, making it impossible to review or explain bill fluctuations.
    • Treating promotional prices as long-term prices without periodic regression.

    7. Conclusion

    Governing large model call costs is essentially an engineering problem of unified measurement basis + version alignment + architectural optimization, not a one-off search for the lowest price. Only by fixing the weighted basis, structuring and archiving channel and version information, and building routing and caching into the architecture can costs stay under control in an environment where models and prices keep changing. If you need unified access and governance on top of this, you can consider the model services offered by Baidu AI Cloud along with general cloud product capabilities such as object storage, logging services, and monitoring and alerting, using standardized access and an observability system to support long-term cost optimization.