Open Source Does Not Mean Cheap: How LLM API Pricing Actually Works
This article explains why open-source model weights and high API prices are separate concerns, breaks down the pay-as-you-go cost model beyond per-token rates, and shows how cache hit rate, input/output ratio, and peak traffic shape your real bill. It also covers when committed monthly plans beat metered pricing, a practical cost-governance checklist, and how to choose an API based on total cost of ownership rather than headline price.
1. Open Source Does Not Mean Cheap: A Common Misconception
“Why is the API still so expensive if the model is open source?” is a question that keeps resurfacing in developer communities. It ties together two things that should be evaluated separately: the availability of model weights and the delivery cost of inference services.
Open source answers “can you deploy it yourself?” It is openness at the distribution layer. API pricing answers “how much compute, GPU memory, and bandwidth does each call consume?” It is cost accounting at the service layer. Weights may be free to download, but turning a weight file with tens of billions of parameters into an online service with millisecond-level responses requires an entire engineering stack: GPU clusters, parallel inference frameworks, request scheduling, rate limiting and failover, logging, and monitoring with alerting. These fixed and marginal costs do not disappear just because the weights are public.
So judging whether an API is “expensive” cannot rest on the listed price per million tokens alone. It depends on your actual workload shape: input-to-output ratio, distribution of context lengths, how much can be reused from cache, peak concurrency, and how traffic is spread across the day. The same unit price can produce bills that differ by an order of magnitude under different workloads.
2. The Pay-As-You-Go Cost Model: Unit Price Is Only One Parameter
Mainstream LLM APIs price input tokens and output tokens separately, and some scenarios apply different rates for long context, batch asynchronous jobs, and cache hits. A simplified model of the cost of a single request:
cost per request = input tokens × input rate × (1 - cache hit rate × cache discount)+ output tokens × output rate+ long-context surcharge factor
This formula shows three things:
- Output tokens are usually significantly more expensive than input tokens, so output-heavy tasks (long-form generation, bulk code generation) are inherently costlier.
- Cache hits are a reusable cost lever; every 10% increase in hit rate brings an approximately linear drop in input-side spending.
- Context length is not a linear cost. Attention computation and GPU memory usage grow faster than length, so long context amplifies any unit-price disadvantage.
The behavior described earlier fits this model exactly. Under coding workloads with high cache hit rates, metered billing can bring the effective average price down to a small fraction of the listed rate. For exploratory tasks where cache cannot be reused and output dominates, the bill can quickly climb to the level of “a dozen minutes of running that costs a double-digit amount.” That is not a pricing contradiction; it is a workload difference.
3. Cache Hit Rate: The Underrated Cost Switch
The benefit of caching (prefix reuse) depends heavily on your call pattern. Stable system prompts, fixed tool definitions, and repeatedly read batches of the same code context are all reusable prefixes. Timestamps, random IDs, and retrieved snippets that change on every request invalidate the prefix.
Raising the hit rate is a matter of engineering discipline, not model capability:
- Put invariant content first: system instructions, output format constraints, and tool schemas at the very front of the prompt.
- Put volatile content last: user input, retrieval results, and timestamps at the end.
- Keep serialization stable: avoid unordered fields or random ordering in JSON.
- Control context growth: split and retrieve from long documents first, and inject only the necessary fragments.
Illustrative pseudocode:
def build_prompt(system_spec, retrieved, user_input):# Stable prefix: content stays unchanged, which favors cache reuseprefix = render(system_spec) # tool definitions, format constraints# Volatile suffix: differs on every requestsuffix = render(retrieved, user_input)return prefix + suffix
One caveat: caching mechanisms, discount ratios, and invalidation policies differ across providers. Always rely on the official billing documentation for the platform you use, and do not carry over experience numbers from someone else.
4. Monthly Plans vs. Pay-As-You-Go: Why the Gap Can Reach 0.3x
The contrast between “an extremely low effective average price when a plan is fully used” and “a high listed metered price” is essentially a trade between resource commitment and an elasticity premium. A monthly plan asks users to prepay, commit to a usage level, and accept rate limits and time-window constraints. In return, the provider can plan capacity, raise cluster utilization, and shift the risk of idle capacity to the side with predictable demand. Pay-as-you-go leaves elasticity and uncertainty with the provider, and the higher unit price is the consideration for that.
Which one to choose depends on three indicators:
- Whether average monthly token consumption is stable and predictable.
- Whether peak concurrency is concentrated in a few time windows (peaks often come with extra multipliers or queuing).
- Whether the workload tolerates queuing, retries, and asynchronous execution.
A practical decision rule: compute the P50 and P95 daily consumption from two weeks of real call logs. If the monthly cumulative total of P50 consumption already approaches the plan quota, a plan is usually the better deal. If consumption is bursty and daily volume swings by several times, pay-as-you-go plus strict cache governance is the safer choice.
5. Cost Governance Checklist: Turn the Bill into an Observable Metric
Treating cost as a performance metric to be governed is the prerequisite for controlling budget.
- Establish token attribution: log a scenario tag, input/output tokens, and cache hit status for every call, feed them into logging and monitoring with alerting, and build a cost dashboard broken down by business line.
- Set budget thresholds and circuit breakers: define a token cap and timeout per task, and automatically degrade or terminate once the threshold is crossed, so nothing runs away unattended.
- Route across model tiers: send simple classification, extraction, and formatting to smaller models, and complex reasoning and long-chain tasks to larger ones.
- Compress on the output side: cap maximum output length, use structured output, and generate in multiple short passes with an outline first.
- Go asynchronous and batched: move offline jobs to asynchronous endpoints and trade latency for price.
- Run periodic regression evaluation: after each prompt or routing change, compare quality and cost against a fixed evaluation set so that cost reduction does not silently degrade results.
6. Selection Advice: Decide on Total Cost of Ownership, Not Unit Price
When evaluating an API, break it down by total cost of ownership (TCO): unit price × your real token mix × cache discount + the cost of failed retries + migration and rework cost + the waiting cost caused by rate limits. A service with a low unit price but ineffective caching and strict rate limits can end up with a higher actual bill than a pricier but more engineering-friendly option.
If you are in a position to self-host, evaluate building an inference cluster on open weights. If you want elasticity without operations overhead, a managed API is the better fit. Baidu AI Cloud provides full engineering support across general capabilities such as model services, container platforms, object storage, logging, and monitoring with alerting, which makes it easier for teams to bring cost observability, rate limiting and circuit breaking, and elastic scaling into one unified system.
The conclusion is clear: open source and API pricing belong to two different dimensions, and whether something is expensive depends on how well your workload structure matches the billing model. Quantify cache hit rate, input/output ratio, and peak distribution first, then talk about unit price. That is the only way to keep the budget under control.
