Self-Hosting LLMs vs. APIs: A Break-Even Cost Analysis
Should you self-host an open-source large language model or use a pay-per-token API? This guide explains how to calculate break-even utilization, compare hardware costs with API pricing, and account for engineering effort, peak capacity, reliability, and compliance when choosing a deployment strategy.
Self-Hosting LLMs vs. APIs: A Break-Even Cost Analysis
As large language models become more widely available, more teams are asking whether they should deploy an open-source model themselves rather than continue paying for inference through an API.
Although this looks like a technical architecture decision, it is fundamentally an economic one. A reusable cost model can help developers avoid misleading comparisons and choose an approach that fits their workload.
1. Establish a Fair Comparison
Before asking which option is cheaper, define the conditions of the comparison. A meaningful analysis needs to hold four variables constant:
- The model. Differences in parameter count and quantization precision can change inference costs by an order of magnitude. Comparing different models does not establish which deployment approach is more economical.
- The request mix. Input length, output length, and cache-hit rate determine both token throughput and API charges.
- The throughput assumptions. Actual self-hosted throughput depends on hardware, inference framework optimizations, concurrency, and context length. Benchmark results from another workload cannot simply be applied to yours.
- The pricing date. GPU rental rates and API prices change continuously. A conclusion reached today could reverse in six months if either side reduces its prices.
Claims that self-hosting is “several times cheaper” without these conditions are marketing statements, not a reliable basis for engineering decisions.
2. The Core Break-Even Formula
The direct hardware-cost comparison comes down to a simple ratio:
Break-even utilization =GPU rental cost per hour /API-equivalent cost of one hour of full-capacity inference
For example, assume a consumer GPU costs approximately $0.50 per hour to rent. Running an open-source model in the roughly 30B-parameter range at full capacity produces a workload that would cost about $5.90 through the lowest-priced comparable API endpoint.
The break-even utilization is:
0.50 / 5.90 ≈ 8.5%
Under these assumptions, self-hosting becomes cheaper on direct GPU costs once useful inference exceeds approximately 8.5% of the GPU’s full-capacity output across all billed hours.
If utilization stays below that threshold, the GPU spends too much of its billed time idle, and a pay-per-token API is more economical.
This interpretation depends on the throughput assumptions remaining valid. Utilization here means useful throughput relative to the measured full-capacity baseline, not simply the GPU utilization percentage shown by a monitoring tool.
A particularly important case occurs when break-even utilization exceeds 100%. Under those pricing and throughput conditions, self-hosting cannot match the API’s cost even when running at full capacity around the clock. This can happen when expensive high-end GPU rentals are compared with very low-priced API endpoints.
3. Why Different Configurations Produce Very Different Results
The same formula can produce thresholds ranging from single-digit percentages to more than 100%. Four factors explain the variation.
Hardware Rental Cost
High-end inference GPUs can cost more than ten times as much per hour as consumer GPUs. A larger numerator directly raises the utilization needed to break even.
API Endpoint Pricing
API pricing determines the value of the denominator. A cheaper or subsidized API endpoint reduces the API-equivalent cost of the workload, making self-hosting harder to justify. Conversely, comparing against an expensive endpoint can make self-hosting look especially attractive.
The reference endpoint therefore matters as much as the hardware configuration.
Actual Throughput
With short prompts, GPU decoding throughput may approach its peak. Long contexts and low concurrency can reduce throughput substantially.
For example, a throughput decline from approximately 940 tokens per second to 560 tokens per second on the same machine can move an estimated break-even threshold from roughly 8% to around 12%. These are illustrative figures, not benchmarks that should be assumed to apply to another workload.
Token Billing Categories
APIs may charge different rates for input tokens, cached input tokens, and output tokens.
The correct approach is to calculate what the same workload would cost through the API, preserving its input, cache, and output mix, and then compare that amount with GPU rental costs.
Multiplying all locally processed tokens by the API’s output-token price can substantially overstate the savings from self-hosting.
4. What the Formula Leaves Out
The simple ratio covers direct hardware costs only. A practical decision must also account for several less visible expenses.
- Engineering effort. Deploying an inference framework, quantizing and tuning models, configuring load balancing, and troubleshooting failures all require experienced engineers. For a small team, this work can cost far more than the GPUs.
- Peak-capacity headroom. Self-hosted capacity must accommodate peak demand, while utilization is calculated from average demand. A higher peak-to-average traffic ratio raises the effective break-even threshold.
- Operations and reliability. Redundant replicas, upgrades, monitoring, and alerting create ongoing costs. Cloud container platforms, logging services, and monitoring tools can reduce the burden, but they do not eliminate it.
- Opportunity cost. APIs make it easier to switch models as new versions become available. Self-hosting can tie a team more closely to particular hardware and model choices.
Treat the hardware-only break-even threshold as a lower bound, not a final decision rule. The practical threshold should be higher to leave room for these additional costs.
5. Deployment Recommendations by Workload
Individual Developers and Experimental Projects
When demand is low and unpredictable, an API is usually the most practical choice.
If the goal is to learn inference deployment, hourly GPU rentals can provide hands-on experience without paying for an always-on instance. Stop the instance when it is not needed.
Small and Midsize Teams with Stable Services
For steady, predictable traffic, collect at least a week of real request logs before estimating utilization and applying the formula.
Sustained utilization above 20% is a reason to evaluate self-hosting seriously, not a guarantee that it will be cheaper. Engineering and operational costs still need to be included.
Data-Sensitive Workloads
If compliance requires data to remain within a controlled environment, cost becomes a secondary consideration.
Options include private deployment or comparing cloud services with zero-data-retention commitments, subject to the applicable compliance requirements. The focus then shifts toward throughput optimization and cost control within those constraints.
Large Enterprises
A common approach is hybrid deployment: use an internal cluster for baseline demand and send traffic spikes to an API.
Gradual model-version rollouts can also help avoid dependence on a single provider while keeping deployment changes manageable.
6. Conclusion
There is no universal answer to whether an LLM should be self-hosted, but there is a reusable method for evaluating the decision.
First, fix the model, workload profile, throughput assumptions, and pricing date. Calculate break-even utilization as an initial screen. Then adjust the analysis for engineering effort, peak-capacity headroom, reliability, and compliance.
Once those variables are explicit, much of the debate becomes a straightforward cost calculation. Recalculate whenever GPU rental rates or API prices change materially so that the decision reflects current conditions rather than an outdated pricing snapshot.
