Self-Hosting LLMs vs. Pay-per-Token APIs: Which Costs Less?
Compare the economics of self-hosted LLM inference and pay-per-token cloud APIs using model size, quantization, concurrency, and total operating costs. This article explains how to estimate token costs, identify a break-even point, account for hidden expenses, and decide when a hybrid deployment makes sense.
Self-Hosted LLMs or Pay-per-Token APIs?
As large language models move into production for AI agents, code generation, and knowledge-base question answering, many teams face the same decision: buy GPUs and run inference themselves, or pay for cloud API calls by the token?
The answer depends less on the deployment model itself than on workload economics. A useful comparison requires consistent assumptions, realistic benchmarks, and a clear view of both direct and hidden costs.
1. Establish a Consistent Basis for Comparison
Before comparing prices, fix three variables: model size, quantization precision, and concurrent load. Without these assumptions, cost estimates can lead to very different conclusions.
- Model size: For agent workloads, smaller models may struggle with reliable instruction following and tool use unless they receive task-specific fine-tuning. In practice, dense models in the high-20-billion-parameter range—around 27B—can serve as a practical starting point for cost-effective local deployment. Smaller models may require additional fine-tuning investment, while larger models substantially increase memory and compute requirements.
- Quantization precision: Low-precision inference, such as FP8, can roughly halve model memory requirements and reduce compute demand. This can make medium-sized models feasible on consumer or prosumer GPUs.
- Concurrent load: Most of the cost advantage of self-hosting comes from keeping hardware consistently busy. Running only one inference request at a time can make local inference expensive per token.
One counterintuitive consideration is that very large mixture-of-experts (MoE) models are often poor candidates for local deployment. Sparse activation does not eliminate the need to accommodate the model’s total parameters, which can require multiple GPUs or even multiple servers. Cloud providers can spread these costs across large-scale batched inference and may offer the same or larger MoE models at low API prices.
In other words, the strongest case for beating API pricing locally is usually a dense model that runs efficiently on one GPU or a small multi-GPU setup.
2. Model the Hardware Cost of Self-Hosting
Consider the type of modified, high-memory GPU used in the source-market example: 48 GB of VRAM at approximately RMB 23,000 per card. This configuration can accommodate an FP8-quantized model of roughly 27B parameters together with its KV cache. These prices are illustrative, not a claim about availability or pricing in other markets.
Token throughput needs to be evaluated in two separate stages:
- Prefill, or input processing: Under high-concurrency, long-input benchmark conditions—for example, 32 concurrent requests with 8K-token inputs and 256-token outputs—a mature inference framework using FP8 can deliver aggregate prefill throughput of several thousand tokens per second on a single card. Prefill-only tests may exceed 4,000 tokens per second.
- Decode, or output generation: Autoregressive generation produces tokens sequentially and is constrained by memory bandwidth. Aggregate decode throughput is typically in the hundreds of tokens per second.
As a rough lifetime-capacity estimate, a GPU costing around RMB 24,000 could process tens of billions of prefill tokens or several billion decode tokens. The actual total depends on how consistently it is used over its service life, and the cost calculation must also account for electricity, cooling, and depreciation.
The basic metric is:
Local cost per token = Total ownership and operating cost ÷ Total tokens processed
This is the key measure for comparing self-hosting with API prices. Because prefill and decode have different throughput characteristics, their costs should be evaluated against the workload’s actual input/output mix rather than treated as interchangeable.
Benchmark realistic traffic. Use load-testing scripts with variable input and output lengths and a defined concurrency level. Do not base a purchasing decision on the perceived speed of a single chat session. Sustained batched inference that heavily utilizes the KV cache can differ in efficiency from occasional requests by more than an order of magnitude.
3. Model Pay-per-Token API Costs
Cloud APIs typically charge separate rates for input and output tokens. Output tokens often cost several times more than input tokens.
In the illustrative pricing range discussed here, input prices for models around 27B parameters and larger can range from a few tenths of a renminbi to several renminbi per million tokens, with higher rates for output. These figures are market-dependent and should be replaced with the relevant provider’s quoted prices when making a decision.
The API cost structure is straightforward: pay for what you use, without owning idle inference hardware or operating the serving infrastructure yourself.
Part of the API price covers:
- Data-center infrastructure, networking, disaster recovery, and elastic scaling.
- Ongoing inference optimization, including continuous batching, speculative decoding, and prefix caching.
- Flexibility to upgrade models or switch between model options.
For teams with highly variable traffic or frequent changes in model requirements, avoiding fixed hardware investment is often the more economical choice.
4. Make the Decision with Three Cost Assessments
Assessment 1: Workload Scale and Break-Even
Estimate monthly API spending by separating input and output consumption:
Monthly API cost = Monthly input tokens × Input rate + Monthly output tokens × Output rate
Use matching units—for example, millions of tokens if the API is priced per million tokens.
Then estimate monthly self-hosting costs by depreciating the hardware over 24–36 months and adding electricity and operational labor.
The point at which the two monthly costs are equal is the operating break-even point. Hardware payback is a separate question: how long it takes accumulated savings to recover the upfront investment.
In practice, self-hosting has a chance of paying back within six to twelve months only when inference demand remains consistently high—for example, multiple concurrent agent tasks running throughout the working day. Occasional bursts are not the same as sustained utilization.
Assessment 2: Hidden Costs
Self-hosting involves more than buying GPUs. Ongoing expenses and engineering work include:
- Driver and inference-framework upgrades.
- GPU memory fragmentation.
- KV-cache management for long contexts.
- Hardware failures and spare parts.
Cloud APIs introduce a different set of concerns:
- Compliance requirements when data leaves your environment.
- Network latency.
- Vendor lock-in.
List both sets explicitly. A comparison that includes hardware prices but ignores operational work—or includes API prices but ignores data-handling constraints—is incomplete.
Assessment 3: Model Capability Requirements
If the application depends on the capabilities of a very large MoE model, local deployment is generally difficult to justify on cost alone because the hardware requirements are substantial.
If a model around 27B parameters meets the application’s quality requirements, demand is steady, and the data is sensitive, self-hosting has a much clearer value proposition.
The model must satisfy the workload before its token price becomes meaningful.
5. Practical Recommendations
- Benchmark before buying. Rent a suitable environment and test the target model, quantization configuration, and concurrency pattern. Measure real prefill and decode throughput before deciding how many GPUs to purchase.
- Use a hybrid architecture as a fallback. A practical approach is to route frequent, standardized inference requests to local infrastructure and send overflow traffic or more demanding requests to a cloud API. A routing layer can balance cost against model capability. Model inference services such as those offered by Baidu AI Cloud are one example; availability and suitability should be checked for the intended deployment.
- Recalculate regularly. GPU prices, quantization techniques, and API rates change quickly. Revisit the break-even calculation quarterly and adjust the share of traffic assigned to each deployment option.
Conclusion
Choosing between self-hosted LLMs and cloud APIs is a unit-economics decision, not a matter of preference.
Keep model size and workload assumptions consistent, use load-test results instead of subjective impressions, and include hidden costs on both sides. For many teams, a hybrid strategy that evolves with demand is more economical than committing entirely to either local hardware or cloud APIs.
