Sub topic 13
Hosted or self-hosted: weighing the trade-offs
This chapter assumes you have read the earlier chapters on hosted APIs, open-weight models, token pricing, memory, latency, and privacy. It combines them into one comparison. You should be able to read short Python and know what a token is.
The five factors
The choice between a hosted API and a self-hosted open-weight model comes down to five factors. Each one traces back to an earlier chapter.
| Factor | Hosted API | Self-hosted open-weight |
|---|---|---|
| Cost shape | Pay per token, no fixed cost | Fixed hardware or rental cost, near-zero per token |
| Privacy | Data leaves your network | Data stays on your machines |
| Latency and throughput | Set by the provider and shared load | You tune it, but you must size it |
| Licenses | Provider terms of service | Model license, which may restrict use |
| Operational effort | Almost none | Serving, updates, monitoring, scaling |
Cost: variable versus fixed
A hosted API charges for the tokens you send and receive. Cost grows in a straight line with traffic. A self-hosted model costs the same whether it handles one request or a million, until you run out of capacity and need more GPUs.
This means there is a break-even volume. Below it, the API is cheaper. Above it, owning the hardware wins. Compute it with your own numbers:
def breakeven_requests(monthly_hosting_cost: float, api_cost_per_request: float) -> float:
"""Requests per month at which self-hosting equals API spend."""
return monthly_hosting_cost / api_cost_per_request
# Made-up numbers: a rented GPU server at $1,500 per month,
# and an API cost of $0.0032 per request.
print(round(breakeven_requests(1500, 0.0032))) # 468750At these numbers, you need about 470,000 requests per month before the server pays off. That figure ignores the engineer time to run it, which often tips small teams toward the API.
Privacy and licenses
If your rules forbid sending data to a third party, self-hosting settles the question. Many providers also offer contracts that limit data retention and training use. Read those terms before assuming a hosted API is ruled out.
Self-hosting brings its own check. The model license may limit commercial use, set user-count thresholds, or restrict certain fields. Confirm it before you build on the model.
Latency and control
A hosted API gives you good speed with no tuning, but you share capacity and depend on the provider's rate limits. Self-hosting lets you pick the model size, quantization, and batching to fit your latency target. It also means a traffic spike is your problem.
A common decision path
Many teams start hosted because it is fast to set up, then move specific high-volume or sensitive workloads to self-hosting later. Keeping the model swappable, which a later chapter covers, makes that move cheap.
Common mistakes
- Comparing API price to GPU price without including idle time. A GPU you rent runs and bills even when no one calls it.
- Ignoring peak load. Capacity must cover your busiest hour, not your average.
- Skipping the license check because the weights are free to download.
Exercise
A hosted API costs $0.004 per request. A self-hosted server costs $1,200 per month. Your app handles 200,000 requests per month. Which is cheaper on cost alone, and what else should you weigh before deciding?
Show answer
The API costs 200,000 × $0.004 = $800 per month, which is less than $1,200, so the API is cheaper. Break-even is 300,000 requests per month. Before deciding, also weigh privacy requirements, the model license, latency needs, peak capacity, and the engineering time to operate the server.