Open Weights Are Not Free Inference: A Breakdown of LLM API Costs
Open weights do not make inference free. This article explains what actually drives LLM API pricing, breaks a single call into input tokens, cache hit ratio, and output tokens, then adds peak-hour and retry multipliers. It also covers why subscription quotas and pay-as-you-go billing are not directly comparable, how to build a cost estimation sheet with real traffic sampling, and six practical levers for reducing spend: context compression, prefix stability, task splitting, tiered routing, budget guardrails, and observability.
1. First, Clear Up a Common Misconception: Open Weights ≠ Free Inference
“A model is already open source, so why is the API still so expensive?” has become one of the most frequent questions in developer communities over the past six months. Behind it lies a confusion between two separate things: the availability of model weights and the marginal cost of inference serving.
Open weights mean anyone can download the parameter files and deploy them independently, but self-hosting is not zero cost. For a single inference request to actually return a result, you need at minimum GPU compute, VRAM, high-speed interconnect networking, data center space and power, the scheduling overhead of the inference framework, and operations plus stability guarantees. The weight files are only the starting point; turning them into a service that can reliably handle concurrency is where the cost mainly comes from.
So API pricing has never been a linear conversion based on parameter count. It is pricing for compute occupancy per unit of time. Understanding this is the prerequisite for reading your bill correctly.
2. What the Bill Is Really Made Of: Three Multipliers Decide the Final Price
The cost of one call can be abstracted into the illustrative formula below (it expresses the logical relationship only and does not represent any vendor’s actual rules):
cost per call ≈ (input tokens × input price × (1 - cache hit ratio))+ (input tokens × cached input price × cache hit ratio)+ (output tokens × output price)
Two external multipliers are then layered on top: a peak-hour coefficient (resources are tight during busy periods, so prices rise) and a retry coefficient (repeated billing caused by failed retries and repeatedly reassembled context).
2.1 Cache Hit Ratio Is the Most Sensitive Variable
In scenarios like intelligent coding and long-document Q&A, the system prompt, project context, and tool definitions often stay unchanged across many requests, and that prefix can be cached and reused. On a cache hit, that portion of the input is billed at a significant discount; the portion that misses is billed at full price.
The key point: cache hit ratio is a property of the scenario, not of the model. For the same model, the hit ratio may approach saturation in a “repeatedly append to a long context” scenario, and may be close to zero in a “brand-new short instruction every request” scenario. Using an average price computed from a high-hit-ratio scenario to forecast every scenario will inevitably distort the result.
2.2 The Input/Output Ratio Is Often Underestimated
Input and output prices usually differ by several times, and intelligent coding tasks are exactly output-intensive: the model has to generate large blocks of code, tests, and refactoring content. When the output token share climbs from 10% to 40%, the total bill can still rise several times over even if the input side enjoys a cache discount. The phenomenon described in the original text — small tasks costing tens of yuan while a task taking a dozen-plus minutes costs over a hundred — comes mainly from this item, not from the unit price itself.
2.3 Subscription Quotas and Pay-As-You-Go Are Two Different Sets of Books
Monthly coding packages look cheap because they shift idle compute risk from the user side to the service side: the vendor averages over overall utilization, spreads the cost of long idle periods, and then caps extreme usage with a quota limit. Pay-as-you-go is the opposite: users pay only for actual consumption but bear the volatility alone.
The two cannot be compared directly. Questioning a pay-as-you-go unit price with a package’s “theoretical average price” is equivalent to questioning retail price with wholesale price.
3. A Reusable Cost Estimation Method
It is worth building an estimation sheet at the selection stage, with at least the following fields:
| Field | Description |
|---|---|
| Average input length | Includes system prompt and historical context |
| Average output length | Share of code/text generation |
| Cache hit ratio | Sampled from real traffic, not estimated |
| Peak-hour share | Determines whether an uplift coefficient applies |
| Retry rate | Repeated consumption caused by failures and timeouts |
Sample estimation script:
# Measures usage structure only; no specific API is involveddef estimate_cost(samples, price_in, price_out, cache_hit_ratio, cache_discount):total = 0.0for s in samples:cached = s.in_tokens * cache_hit_ratiofresh = s.in_tokens - cachedtotal += fresh * price_intotal += cached * price_in * cache_discounttotal += s.out_tokens * price_outreturn total / len(samples)
Once you have the real distribution, you will find that differences in bills usually come from structure rather than from the listed price.
4. Cost Optimization Checklist
- Compress context: inject only the necessary files and snippets, avoid concatenating the whole repository; context length amplifies both cost and latency linearly.
- Improve prefix stability: put unchanging content at the very front of the prompt and variable content after it, so the cache hits as often as possible.
- Split tasks: break large tasks into small verified steps, avoiding a single generation failure that invalidates a whole block of output and forces a rerun.
- Tiered routing: hand simple intent recognition and formatting to smaller models, and call larger models only for complex reasoning.
- Set budget guardrails: configure usage caps and alerts per project, so abnormal consumption is detected within minutes.
- Build observability: use logging services and monitoring alerts to record input/output/cache hits per request, so cost attribution has a basis.
5. Conclusion
“Open” lowers the barrier to deployment, not the physical cost of inference; API prices reflect compute occupancy and resource scheduling strategy, not whether a model is public. For developers, there are three genuinely controllable levers: usage structure, cache hit ratio, and model tiering. Quantifying these three and folding them into an everyday observability system improves actual spending far more than arguing about unit prices. If you need elastic capacity and unified governance, you can combine general capabilities such as the container platform, logging service, and monitoring alerts offered by Baidu AI Cloud to build a model invocation cost management system that supports attribution and quota limits.
