B3IQ Blog · Knowledge · 9 min read
Self-Hosted LLM vs API: How to Compare Total Cost
Build a workload-specific comparison of model APIs and self-hosted LLMs, with complete costs, a worked crossover example and capacity constraints.
B3IQ Team
Compare a self-hosted LLM with an API only after both meet the application's quality, latency and data requirements. Count the complete costs over the same period and divide by eligible completions. Any cost crossover must remain feasible within the capacity and recovery plan you will pay for.
TL;DR
- Compare a self-hosted LLM with a model API by the cost of an acceptable application response. First establish that each option meets your quality, latency and data-handling requirements.
- Build complete cost ledgers. API invoices can include more than uncached input and output tokens. Self-hosting includes the machine or rental, hosting, software operations and the capacity you keep available for peaks or recovery.
- A monthly cost crossover applies only while the assumed fleet can serve the workload. A second machine or a different model can change the result.
- This guide compares application serving with API billing. B3IQ's buying-versus-renting guide covers the separate choice of how to acquire GPU capacity.
Establish an Equivalent Service Before Comparing Prices
A self-hosted LLM and an API model can produce different answers, use different tokenizers and support different features. Before comparing prices, test whether both can do the application’s job. An inexpensive deployment that fails the task is not an equivalent service.
Use representative prompts and expected outputs, including long contexts, tool calls and difficult cases. Define the acceptable error or review rate. If a candidate model needs more retries, human correction or another model to finish the task, include that work in its cost. An API-only model may have no acceptable self-hosted replacement for your application.
Set latency and availability requirements separately from output quality. Record where requests may travel, who may administer the service and which records can persist. Exclude options that cannot meet the required boundaries. Hardware ownership alone does not establish privacy; B3IQ's private-AI overview describes the data-path questions around a customer-owned deployment.
For capacity planning, count eligible completions: successful responses that pass both the task-quality check and the application's latency limits. Serving tools such as vLLM's benchmark can report latency-constrained goodput. Apply your task-quality evaluation separately; the tool's latency counter does not grade the answer for you.
Test the actual prompt/output distributions, arrival pattern and cache conditions. Report errors and timeouts as well as successful throughput, and include waiting before a request reaches the server. A monthly average below the machine's theoretical capacity can still hide an unmanageable lunchtime peak.
Build the Complete API Cost Ledger
Start with the bill or the applicable price schedule for the exact model and service. Count the tokens the provider actually bills rather than assuming a fixed character-to-token conversion across models.
OpenAI's API pricing and Claude's pricing documentation distinguish input, output and feature-specific charges. Depending on the service, cached input, cache writes, asynchronous processing, tools, storage or other features can have separate prices. Use only the categories your workload and contract actually incur.
- API cost input · What to collect
- Model requests · Actual billed input and output tokens, including repeated context
- Caching · Cache writes, reads and the hit rate the application achieves
- Additional features · Any billable tools, storage, execution or service tiers you use
- Unsuccessful work · Billable attempts that fail the task or latency requirement, plus retries
- Commercial terms · Commitments, credits, minimum spend and applicable discounts
- Application operations · Integration, evaluation, monitoring and other internal work needed for this option
A response can be technically successful at the API level and still fail your application. If you pay for that response and retry it, its cost belongs in the numerator even though it does not count as an eligible completion.
Check the provider's treatment of failures rather than assuming every failed call is billed. Also check how a commitment works. A minimum spend that already includes usage cannot simply be added to the full usage bill a second time.
Divide total applicable cost by eligible completions over the same period. That gives you a useful comparison when two models need different token counts or retries to perform the same task.
Build the Dedicated GPU Server Cost Ledger
For a self-hosted LLM, separate the upfront cash requirement from the economic cost allocated to the comparison period. An owned machine has a purchase payment and an uncertain residual value. Rented dedicated capacity has a compute bill or commitment instead.
For an owned machine, an illustrative monthly hardware allocation is purchase price minus an assumed residual value, divided by the months of use. Record the upfront purchase cash separately. Do not include both that full purchase payment and the allocation in the same monthly economic-cost total.
Add hosting, separately billed power, storage and networking, and the people and services needed to operate the application. Check what a hosting quote includes before adding each line. Count engineering work on both sides of the comparison; using an API also requires integration and monitoring.
Reliability changes the capacity budget. Model and runtime updates, hardware recovery and peak traffic can require additional machines or a separate fallback arrangement. Assign those costs to the availability target you actually need. Do not assume that one machine and a provider's managed API offer the same recovery behavior.
B3IQ's private-fleet documentation describes no per-request inference charge for requests served on your owned machines. That rule does not remove hardware, hosting or operating costs. Use the current ownership offering and a dated quote to identify the commercial inputs.
Leave possible Earn income outside the baseline. In B3IQ's documented modes, a machine in Earn leaves the owner's inference pool. It cannot simultaneously provide that application's owner-scoped serving capacity. A separate income scenario would need its own demand, cost and capacity assumptions.
Worked Monthly Cost Comparison and Sensitivity
The following example is entirely hypothetical. It describes no named model, provider price or measured GPU result. Assume both options can meet the same task-quality and latency requirements. The purpose is to show which inputs a buyer must replace with a real bill, quote and pilot.
Suppose an API attempt averages 2,000 billed input tokens and 500 billed output tokens. At assumed prices of $0.50 per million input tokens and $1.50 per million output tokens:
cost per billed attempt
= (2,000 * $0.50 + 500 * $1.50) / 1,000,000
= $0.00175Assume 95% of those billed attempts become eligible completions. The effective API cost is therefore $0.00175 / 0.95, or approximately $0.001842 per eligible completion. This example assumes no additional API fixed cost or uncounted feature charges.
For the self-hosted option, assume these fixed monthly costs:
- Illustrative fixed cost · Monthly allocation
- Hardware · $300
- Hosting · $250
- Engineering and operations · $300
- Storage and other fixed services · $50
- Total fixed cost · $900
The hardware allocation assumes a $12,600 purchase, a $1,800 residual value and 36 months of use: ($12,600 - $1,800) / 36 = $300. These are example inputs, not a B3IQ machine quote. The upfront cash payment remains $12,600.
Assume a further $0.0002 of separately billed variable cost per eligible completion. It already allows for the example workload's unsuccessful work. In a real quote, leave this line out or change it when those costs are bundled or behave differently.
- Eligible completions per month · Illustrative API cost · Illustrative self-hosted cost
- 500,000 · $921.05 · $900 + $100 = $1,000
- 1,000,000 · $1,842.11 · $900 + $200 = $1,100
Now add a capacity assumption. Suppose, purely for arithmetic, that the selected serving group could sustain 0.5 eligible responses per second at the required quality and latency. Across a 730-hour month, that would be 1,314,000 completions if it sustained that rate continuously. This is an assumed capacity ceiling, not a benchmark. Downtime, reserve headroom and the arrival pattern can reduce usable capacity.
If peaks or recovery requirements instead require two serving groups, suppose fixed cost rises to $1,800 per month. At one million eligible completions, self-hosting now costs $2,000. That exceeds the assumed API cost of $1,842.11. The same monthly demand produces a different answer once the required capacity changes.
Break-Even Equation and Capacity Constraints
For a fixed, feasible deployment, express the comparison as:
API monthly cost = A + a * N
Self-hosted monthly cost = F + v * N
Crossover volume N* = (F - A) / (a - v)Here N is eligible monthly completions; A and F are the respective fixed monthly costs; and a and v are variable costs per eligible completion. The example has A = $0, F = $900, a = $0.00175 / 0.95, and v = $0.0002.
The crossover is approximately 548,077 eligible completions per month. At that volume the two modeled costs are equal. Above it, the self-hosted option has lower modeled cost only while the same fixed deployment can meet the workload's requirements.
This usual fixed-cost crossover assumes a > v and F > A. If the denominator is zero, that formula cannot produce a finite crossover. If the cost relationships differ, compare the actual cost curves rather than applying the same threshold rule. Minimum-spend contracts, usage credits and changing service tiers may need a different billing function.
Capacity is a separate constraint. A positive crossover below an optimistic monthly ceiling does not establish that the deployment can serve the peak arrival rate or remain available through maintenance. When the machine count changes, update F and the usable capacity, then calculate again.
Run sensitivities for lower demand, more expensive operations, different billed token mixes and extra serving capacity. Changes in cache reuse or model quality can alter the API cost per eligible completion. A cheaper self-hosted model can also change retries and throughput. This is a workload-specific monthly comparison, not a universal token threshold or a cash payback period.
Choose Your Deployment Path and Run a Pilot
Consider the deployment options against the requirements you established:
- A model API can fit when an API-only model is needed, traffic is uncertain, or avoiding a hardware commitment has value. Use actual pricing, operating work and data-handling terms in the comparison.
- Rented dedicated GPU capacity can provide a way to test an acceptable self-hosted model while hardware needs remain uncertain. Verify capacity availability, billing and the work your team must operate.
- Customer-owned hosted machines can fit a predictable workload when the model, capacity and complete costs support the commitment. Use B3IQ's buy-versus-rent analysis to examine hardware acquisition separately from API economics.
- A hybrid application can assign different tasks to different models or services where quality and data policies permit it. Build and test that application routing explicitly. B3IQ's owner-scoped gateway does not automatically fall back to a third-party model API.
Validate Your Numbers With a Focused Pilot
Test task quality first, using data approved for each environment. Include the cases that drive retries or manual review. Record what qualifies as an eligible completion before comparing cost.
Measure the self-hosted candidate on the exact GPU configuration, model and runtime you are considering. Test realistic arrivals, prompt/output lengths, cache reuse and a recovery procedure. Record failures and waiting time as well as successful throughput. B3IQ's model methodology explains why planning estimates cannot replace that run.
Finally, replace the example inputs with a representative API billing period, a dated machine and hosting quote, and the operating effort each option requires. Keep upfront cash, recurring spend and assumed residual value visible. Commit against the service you can actually deliver and the complete cost of delivering it.