Skip to content
Ashish.
All posts
Diagram comparing API latency and local GPU inference costs.
6 min readDevelopmentEngineering Managers, ArchitectsFeatured#llm#self-hosting#gpu-economics#data-residency#infrastructure#build-vs-buy

When Self-Hosting Beats an API (and When It Doesn't)

An examination of self-hosting versus API usage for LLMs, focusing on break-even points, data residency, and GPU economics for engineering teams.

By Ashish KumarPart 5 of GPU Economics for AI Teams

The debate over whether to host Large Language Models (LLMs) locally or consume them via API is often framed as a philosophical stance on open-source software versus proprietary convenience. For engineering managers and architects, however, it is a strictly mechanical problem involving three variables: token economics, data flow topology, and operational latency.

This article is Part 5 of the "GPU Economics for AI Teams" series.

The decision is rarely black and white. It exists along a spectrum defined by break-even points where the marginal cost of API calls exceeds the amortized cost of hardware, and by regulatory boundaries where data cannot leave your perimeter. This analysis dissects those mechanisms to provide a deterministic framework for decision-making.

The Economics of Inference: Breaking Even on Tokens

To understand the break even point, we must first define the cost structure of both models. The comparison between self hosting vs api usage hinges on volume and consistency of demand.

API Model: The cost is purely variable. You pay per input and output token. Vendors include a significant markup for compute, infrastructure maintenance, and profit. As of mid-2024, running a model like Llama 3 8B via an API might cost roughly $0.05–$0.10 per million input tokens, while output tokens can be more expensive.

Self-Hosted Model: The cost is fixed plus variable. Fixed costs include GPU acquisition (or rental) and power/cooling. Variable costs are electricity and the marginal compute time. The key metric here is tokens per second (TPS) relative to GPU price.

Consider a team using a single NVIDIA T4 GPU (often used for inference). A T4 can serve approximately 10–15 tokens per second for an 8B parameter model with INT8 quantization. If you rent a T4 on a cloud provider like Lambda Labs or RunPod for ~$0.40/hour, and you are generating 50,000 tokens per hour (roughly 14 TPS), your cost is $0.40/hour.

If the same 50,000 tokens were processed via an API at $0.05/1M tokens, the cost would be $0.0025. In this low-volume scenario, the API is significantly cheaper.

However, as volume scales, the API cost grows linearly while the self-hosted cost plateaus once the GPU is saturated. The break-even point typically occurs when monthly token volume exceeds 50–100 million tokens for mid-sized models (7B–13B parameters).

Opinion: Do not calculate break-even based on peak load. Calculate it based on average sustained load. A GPU sitting idle during off-hours still incurs cost if you own the hardware, whereas API costs drop to zero.

Data Residency: The Non-Negotiable Constraint

Economics are secondary when legal compliance is at stake. The mechanism of data transfer differs fundamentally between the two approaches.

API Data Flow: When you send a prompt to an API, the data travels over the public internet (or a dedicated private link) to the vendor’s data center. Even with "zero-retention" policies, the data resides on the vendor’s servers during processing. For industries governed by HIPAA (healthcare), GDPR (EU personal data), or strict corporate IP policies, this introduces a trust boundary. You must rely on the vendor’s security posture and contractual SLAs.

Self-Hosted Data Flow: The data never leaves your network. It moves from your application server to your local GPU memory. This allows for air-gapped deployments, which are required in high-security government or financial environments.

For most B2C applications handling PII (Personally Identifiable Information), self-hosting is not just an economic choice but a risk mitigation strategy. If you cannot guarantee that the API provider will not use your data for training (a common clause in older terms of service), self-hosting is the only compliant path. Data residency requirements often force this decision regardless of cost.

Latency, Tail Performance, and Customization

Beyond cost and compliance, the user experience dictates the architecture.

Latency and Jitter: API responses are subject to network jitter, queueing delays at the vendor’s end, and regional routing issues. For real-time applications (e.g., interactive chatbots, code completion tools), a 500ms delay is acceptable, but a 2-second delay with high variance is not. Self-hosting eliminates network latency, leaving only the time required for matrix multiplication on the GPU. However, local GPUs have limited memory bandwidth. An A100 GPU has significantly higher memory bandwidth than a T4, leading to faster token generation.

Customization via Fine-Tuning: APIs generally offer "zero-shot" or "few-shot" prompting. You cannot fine-tune a model through a standard API. If your domain requires specific knowledge (e.g., legal contract review, proprietary codebases), you must fine-tune the model.

Fine-tuning a model like Llama 3 8B using QLoRA (Quantized Low-Rank Adaptation) can be done on a single GPU, and inference after fine-tuning can also be done on a single GPU. If your use case relies on fine-tuned accuracy, you must self-host the inference endpoint, as the fine-tuned weights are unique to your organization and cannot be hosted on a shared public API. The llm build vs buy decision often pivots here: if customization is required, "buying" via API is no longer a viable option for that specific workload.

The Hidden Cost: Operational Overhead

The "build" side of "build-vs-buy" includes operational complexity that is often underestimated.

Self-hosting an LLM is not just installing a model file. It involves:

  1. Scaling: Handling traffic spikes requires auto-scaling groups of GPU instances, which is complex to orchestrate.
  2. Monitoring: Tracking token usage, latency percentiles (p95, p99), and error rates requires specialized observability tools.
  3. Maintenance: Updating drivers, managing container versions, and applying security patches to the underlying OS.

Managed services like AWS Bedrock, Google Vertex AI, or Azure AI Studio reduce this overhead by providing a managed API. However, they still route through their infrastructure. For teams with strong DevOps/MLOps capabilities, the control offered by self-hosting (e.g., using vLLM or TGI for high-throughput serving) is worth the operational cost. For teams without dedicated ML engineers, the overhead can derail product timelines. The gpu-economics of self-hosting must include the salary of the engineers required to maintain the infrastructure.

Decision Matrix

Based on the mechanisms above, here is a practical decision framework:

ScenarioRecommendationReason
Low Volume (<1M tokens/mo)APIHardware cost amortization is too high.
Strict Data ResidencySelf-HostCompliance requires data never leave perimeter.
Real-Time Latency CriticalSelf-HostEliminates network jitter; allows local optimization.
Requires Fine-TuningSelf-HostAPIs do not support custom model weights.
High Volume (>50M tokens/mo)Evaluate Self-HostAPI costs may exceed GPU rental costs.
No ML Ops TeamAPI / ManagedOperational overhead will consume engineering resources.

Conclusion

Self-hosting an LLM is a capital expenditure play; using an API is an operational expenditure model. The choice should not be driven by ideology but by the mechanics of your specific workload. If your primary constraint is budget and you have low volume, the API is the rational choice. If your constraints are data sovereignty, latency, or customization, self-hosting becomes necessary despite the higher initial complexity.

For most engineering teams, the optimal path is hybrid: use APIs for general-purpose tasks where data is non-sensitive, and self-host smaller, fine-tuned models for sensitive, high-frequency, or domain-specific tasks. This approach balances cost, control, and capability.

Related posts