Self-Hosting or Pay-per-Token APIs: How to Do the Math on LLM Inference Costs
Teams building with large language models often ask whether to run a model on their own hardware or call a cloud inference API. The answer depends on model size, VRAM capacity, request volume, data sensitivity, and hidden operating costs. This article works through each factor, explains when each option makes financial sense, and describes a hybrid approach that many teams use.
Nearly every team building with large language models faces the same question: should the model run on hardware you control, or should you call a cloud inference service? On the surface, this looks like a trade-off between saving money and saving effort. In practice, it is a systems-level economic problem that involves hardware selection, model size, workload patterns, and hidden costs. This article breaks the problem down and works through the numbers.
1. Start with the Hardware Math: VRAM Is the Hard Limit
Whether local deployment is affordable depends first on whether the target model fits in memory. This article uses a 48 GB VRAM version of a mainstream consumer flagship GPU as the baseline. Cards like this offer strong value on the secondhand and modified-card markets, which makes them a common choice for individuals and small teams.
Take a dense model of roughly 27B parameters. With a common quantization scheme such as 4-bit, the weights alone take about 15 GB. Add the KV cache, activations, and framework overhead, and 48 GB can comfortably support inference, with room left over for fine-tuning.
A larger MoE model changes the picture. MoE models activate fewer parameters per token and run faster, but all expert weights must stay resident in VRAM. Total parameter count therefore sets the memory floor. A MoE model with over 100B total parameters exceeds the capacity of a single 48 GB card, even with aggressive quantization. Splitting the model across multiple GPUs roughly doubles the cost. This explains why many people say that self-hosting a MoE model is the worst deal: you spend several times more money for throughput gains that are often limited.
Another point is easy to overlook: the minimum viable model size. Agent tasks require multiple rounds of tool calls, function orchestration, and long-context understanding. Smaller models, even when used without fine-tuning, often produce malformed tool calls or break task chains. These stability problems turn into large amounts of debugging time. For agent workloads, using a small model to save money is often a false economy.
2. The Cloud Side: The Real Cost of Pay-per-Token Pricing
Cloud inference is usually billed separately for input tokens and output tokens. Output prices are often several times higher than input prices. Based on typical industry pricing, which runs from a few tenths of a yuan to a few yuan per million input tokens, with output priced at a multiple of that, daily calls to a mid-sized model around 27B cost very little.
One key fact that every self-hosting team should consider: many small and mid-sized models that you can run locally are offered free of charge by cloud providers. These models have very low per-request compute costs. Providers would rather offer them free to build user habits and grow their developer ecosystem than design a paid tier for so little compute. If your workload needs only a model under 10B parameters for tasks like summarization, classification, or simple Q&A, self-hosting has almost no cost advantage.
3. Where the Two Options Break Even
Combining these factors yields a simple decision logic:
- Model size: Under 10B parameters, use free or low-cost cloud services. Around 27B dense models, the cost becomes worth calculating. Above hundreds of billions of parameters in MoE form, self-hosting rarely pays off, and the cloud is preferred.
- Request volume: With low daily token volume, a few million tokens or less, pay-per-token is almost always cheaper. With daily volume in the billions of tokens and a stable, predictable workload, self-hosting can overtake the cloud once hardware depreciation is spread across that volume.
- Data sensitivity: This is the one reason self-hosting cannot be replaced by price comparison. If compliance rules forbid data from leaving your premises, the cost calculation no longer decides the question.
- Hidden costs: Self-hosting means you pay for power, cooling, hardware failures, driver and inference framework maintenance, scaling, and high availability. These costs do not appear in the GPU price, but they consume engineering time. Electricity alone is significant. A 400W GPU running 24/7 costs on the order of a thousand yuan per year in electricity, and it may sit idle much of that time.
A rough model looks like this (illustrative pseudocode):
# Decision model (illustrative units; substitute actual quotes)cloud_cost = annual_tokens * price_per_tokenlocal_cost = gpu_price + gpu_price * 0.15 (annual) \+ power_watts/1000 * 24 * 365 * electricity_price \+ engineer_days * daily_costif cloud_cost < local_cost and data_can_leave_premise:choose("pay-per-token")else:choose("self-hosted")
4. A Practical Choice: The Hybrid Strategy
For most teams, the best answer is neither option alone:
- Prototyping and low-frequency calls should use the cloud, including free small-model endpoints, to validate business value quickly.
- High-frequency core workloads should be evaluated for self-hosting only after call volume is proven. A useful threshold is whether the monthly cloud bill can cover hardware depreciation, electricity, and operations staff.
- Sensitive data pipelines should be kept local, using a mid-sized dense model with quantization and fine-tuning. On limited hardware, prioritize stability over scale.
Conclusion
Deciding between local and paid inference is an arithmetic problem plus a compliance question. Define which model size you need, how many real calls you make, and whether your data can leave your environment. Then decide whether to buy GPUs or add API credits. This avoids the two most common mistakes: spending on multi-GPU hardware for MoE models that the hardware cannot handle, and buying hardware for small models that cloud providers already offer for free. Once the numbers are laid out, the answer is usually not hard to find.
