---
title: "Self-hosted AI: running LLM infrastructure in your own VPC"
type: "deep dive"
url: "https://aifordevs.org/articles/self-hosted-ai"
markdown: "https://aifordevs.org/articles/self-hosted-ai.md"
publisher: "AI for Devs"
license: "https://aifordevs.org/reuse"
attribution: "Credit AI for Devs and link to https://aifordevs.org/articles/self-hosted-ai"
description: "Self-hosted AI in a VPC: inference engine, gateway, logs, and secrets, the GPU utilization that decides cost against an API, and when a hybrid split wins."
author: "AI for Devs"
published: "2026-11-25"
level: "Intermediate"
topics: ["inference", "models"]
---

# Self-hosted AI: running LLM infrastructure in your own VPC

Self-hosted AI in a VPC: inference engine, gateway, logs, and secrets, the GPU utilization that decides cost against an API, and when a hybrid split wins.

> **TL;DR**
>
> - Self-hosted AI for a company is four layers inside your own network: an inference engine on GPUs, a gateway in front of it, a log store, and a secret store.
> - Cost against a managed API is decided by GPU utilization. OpenRouter's November 2026 analysis found break-even loads from 8% for a cheap RTX 3090 to never for H200s rented at $4.59 an hour.
> - vLLM and SGLang suit shared GPU serving, and Ollama suits development machines and small tools; vLLM and SGLang both serve one model per server or router.
> - A hybrid split, with sensitive and bulk work on local GPUs and frontier tasks sent out through one egress, is often the right answer, and the gateway is what enforces it.
> - Bifrost, an open-source AI gateway, supports Ollama, vLLM, and SGLang as providers, logs every request to a database you own, and runs fully air-gapped once its datasheets are local files.

Self-hosted AI means you run the models, and the layer that controls access to them, on infrastructure you operate, so prompts, responses, and logs stay inside your network unless you choose to send them out. Most guides that rank for the term stop at one machine running Ollama with a chat window on top. That works for one developer. It stops working when several teams, services, and agents share the same GPUs and an auditor asks what data went into which model.

This article covers the production version: the four layers of a self-hosted AI stack in a VPC, how GPU utilization decides cost against a managed API, when a hybrid split beats going all in, and how [Bifrost](https://www.getmaxim.ai), an [open-source AI gateway](https://github.com/maximhq/bifrost), fills the gateway layer. For regulated, on-premises rollouts with a compliance checklist, see the companion piece on [on-prem LLM deployment](https://aifordevs.org/articles/on-prem-llm-deployment).

## What self-hosted AI means for a company

For a company, self-hosted AI is a production service inside its own network boundary, with the same access control, logging, and change management as any internal API. It has four layers, and each answers a different question.

| Layer | What it does | Typical choices | Question it answers |
| --- | --- | --- | --- |
| Inference engine | Loads open-weight models onto GPUs and serves an HTTP API | vLLM, SGLang, Ollama | Which model runs, and how fast? |
| Gateway | One endpoint for every caller: keys, routing, retries, fallbacks, budgets | Bifrost | Who may call which model? |
| Log store | A record of every request and response, under your control | PostgreSQL, an OpenTelemetry collector | What went into which model? |
| Secret store | Provider and internal credentials outside config files | HashiCorp Vault, a cloud secret manager | Where do the keys live? |

Skip one and the gap shows quickly. Without a gateway, every app hardcodes an inference URL and its own retry logic, so adding a second model means editing every caller. Without logs, nobody can answer a data-handling question after the fact. Without a secret store, the one external API key you allow ends up in a dozen `.env` files.

## A reference architecture for self-hosted AI in a VPC

A self-hosted AI stack puts inference servers on GPU nodes in private subnets, puts the gateway in front of them as the only address applications call, and keeps the log store and secret store inside the same boundary. The gateway is also the only component with an outbound route.

**Figure 1.** Apps never call an inference server directly. The gateway is the one address they know, the one writer to the log store, the one reader of provider keys, and the only component with a route through the egress.

The request path:

1. An internal app or agent sends an OpenAI-format request to the gateway.
2. The gateway checks the caller's key, picks a backend, and forwards the request.
3. The backend is a self-hosted engine in the VPC or, for approved routes, an external provider reached through the egress.
4. The gateway writes the request, response, latency, and token counts to a database you control.

This turns egress into a decision made per route rather than per app. A strict setup blocks outbound traffic from the inference subnet entirely and lets only the gateway reach a short list of provider hostnames. A fully air-gapped setup blocks outbound traffic everywhere, which changes how the software itself is installed (covered at the end).

## Choosing a self-hosted inference engine

The [inference](https://aifordevs.org/glossary#inference) engine turns model weights into an API, and the right one depends on how many users share it. Two of this site's articles compare engines in depth: [vLLM vs SGLang, plus Ollama and llama.cpp](https://aifordevs.org/articles/vllm-sglang-llama-cpp) for servers, and [LM Studio vs Ollama](https://aifordevs.org/articles/lm-studio-vs-ollama) for local machines. For the stack, three facts matter most.

- **vLLM** fits shared GPU serving. It runs an [OpenAI-compatible server](https://docs.vllm.ai/en/latest/serving/online_serving/openai_compatible_server/) started with `vllm serve <model>`, and each server names one model, so plan one deployment per model you offer.
- **SGLang** suits multi-GPU production. Its [data parallelism guide](https://docs.sglang.io/docs/advanced_features/dp_dpa_smg_guide) strongly recommends separate SGLang servers behind `sgl-router` over one server with a data-parallel flag. The router serves one model and spreads requests across that model's workers, with a cache-aware routing policy.
- **Ollama** is the easiest to start. It keeps several models loaded at once if they fit in memory (`OLLAMA_MAX_LOADED_MODELS` defaults to three per GPU), but on most backends processes one request per model at a time by default (`OLLAMA_NUM_PARALLEL` is 1), and it binds to `127.0.0.1:11434`, so a gateway on another host cannot reach it until you change `OLLAMA_HOST` ([Ollama FAQ](https://docs.ollama.com/faq)).

Hardware is where the budget goes. Each replica needs GPU memory for the weights plus a [KV cache](https://aifordevs.org/glossary#kv-cache) for every request in flight; [how the KV cache works](https://aifordevs.org/articles/kv-cache-explained) explains why long prompts eat concurrency. vLLM's [parallelism guide](https://docs.vllm.ai/en/latest/serving/parallelism_scaling/) sets the order: one GPU if the model fits, tensor parallelism across the GPUs of one node if it does not, and pipeline parallelism across nodes beyond that. At startup vLLM logs the KV cache size in tokens and a maximum concurrency estimate for a given request length, and the guide says to add GPUs when those numbers fall short of the target.

Size from the smallest model that passes your evaluations, at your real prompt lengths. [Quantization](https://aifordevs.org/glossary#quantization) can move a model down a GPU tier, and the [open-source LLM roundup](https://aifordevs.org/articles/best-open-source-llms) lists which open-weight models are worth testing.

## Self-hosted vs managed API: utilization decides the cost

Self-hosting trades per-token bills for a fixed GPU cost and an operations job you now own. A rented or owned GPU costs the same whether it is busy or idle, so the deciding number is utilization: the share of each hour the GPU spends serving at full load.

OpenRouter published a [break-even analysis](https://openrouter.ai/blog/insights/self-hosted-llm-vs-api/) on November 12, 2026, with prices as of October 8, 2026. Its formula divides the GPU's hourly rent by what one fully loaded GPU-hour of tokens would cost from an API. The result is the load you must sustain before self-hosting is cheaper.

**Figure 2.** The same model can be a clear win or a permanent loss depending on rent. Against the median zero-data-retention API price, a cheap consumer GPU pays off at 8% load, while H200s rented at $4.59 an hour never beat the API even when fully busy.

Three readings from that data hold beyond the specific prices:

- **Cheap hardware on a small model breaks even early.** An RTX 3090 at $0.50 an hour serving a 27B model needed about 8% load.
- **Rent moves the answer more than the GPU does.** The same B200 setup needed 37% load at $3.70 an hour and 68% at $6.79.
- **Cheap APIs can be unbeatable.** Against the cheapest zero-retention endpoint, the H200 setup never broke even at either rent.

Cost is one axis of four:

| Factor | Self-hosted | Managed API |
| --- | --- | --- |
| Data control | Prompts and outputs stay inside your boundary; your network diagram answers residency questions | You rely on the provider's retention and processing terms |
| Cost shape | Fixed per GPU-hour; wins at steady, high utilization | Per token; wins for spiky or low volume |
| Model access | Open-weight models only | Closed frontier models, which cannot be downloaded |
| Operations | You own capacity, driver and engine upgrades, model updates, on-call | The provider owns all of it |

Before pricing hardware, measure two things from current traffic: tokens per hour at peak and off-peak, and how much of that traffic an open-weight model handles at acceptable quality. The ratio of off-peak to peak load is what turns a promising break-even into an idle GPU bill.

## When a hybrid self-hosted AI setup makes sense

A hybrid setup makes sense when some traffic is sensitive or high-volume and some needs a frontier model. The first kind runs on local GPUs, the second goes to an external provider, and the gateway hides the difference from applications while enforcing which work may go where.

**Figure 3.** Each class of work has its own fallback chain. Sensitive data falls back to a second local replica and never crosses the egress; bulk work may fall back outward only when its data is allowed to leave.

Typical splits:

- **Sensitive data** (customer records, patient notes, source code under contract) goes to a self-hosted model and never leaves the VPC.
- **Bulk jobs** (tagging, embeddings, summarization) run on owned GPUs, which is where steady load keeps utilization high.
- **Frontier tasks** (hard reasoning, long-context analysis, agent planning) go to an external provider through the egress.

The failure case needs as much design as the happy path. A fallback for sensitive traffic must be another local replica, never a cloud model, or a GPU outage quietly turns into a data leak. The rule belongs at the gateway, tied to the caller's key, rather than in each app's retry code.

## Bifrost as the self-hosted gateway layer

[Bifrost](https://www.getmaxim.ai) is an open-source AI gateway and control plane with an Apache 2.0 core that sits between applications and every model they call, local or external, behind one OpenAI-compatible API. It is a gateway, not a model host: the models stay on your engines, and Bifrost routes, governs, and logs the traffic to them.

### Deployment options

For evaluation, `npx -y @maximhq/bifrost` or `docker run -p 8080:8080 maximhq/bifrost` starts the gateway with its web UI and `/v1/chat/completions` on port 8080 ([gateway setup](https://docs.getbifrost.ai/quickstart/gateway/setting-up)); the docs say to pin an image version and enable authentication and TLS before production. The [deployment guides](https://docs.getbifrost.ai/deployment-guides/overview) cover a Helm chart for any Kubernetes cluster, including EKS, GKE, and AKS, plus Amazon ECS, Terraform, and Docker on a VM. Several open-source instances each load the same file-only `config.json` and secrets, with PostgreSQL 16 or later holding shared logs. Bifrost Enterprise requires PostgreSQL for both the config and log stores, and its [in-VPC deployment](https://docs.getbifrost.ai/enterprise/invpc-deployments) runs the gateway and log ingestion inside your own Kubernetes cluster.

### Self-hosted providers: Ollama, vLLM, and SGLang

Self-hosted engines plug in as providers that point at a URL you operate. The [provider configuration](https://docs.getbifrost.ai/deployment-guides/config-json/providers) shows all three:

```json
{
  "providers": {
    "ollama": {
      "keys": [{ "name": "ollama-local", "value": "", "models": ["*"], "weight": 1.0,
                 "ollama_key_config": { "url": "env.OLLAMA_URL" } }]
    },
    "vllm": {
      "keys": [{ "name": "vllm-llama3-70b", "value": "", "models": ["llama-3-70b"], "weight": 1.0,
                 "vllm_key_config": { "url": "http://vllm-server:8000",
                                      "model_name": "meta-llama/Meta-Llama-3-70B-Instruct" } }]
    },
    "sgl": {
      "keys": [{ "name": "sgl-main", "value": "", "models": ["*"], "weight": 1.0,
                 "sgl_key_config": { "url": "http://sgl-router:30000" } }]
    }
  }
}
```

The `value` stays empty because self-hosted engines usually need no key. vLLM gets one key per served model, matching its one-model-per-server design, and SGLang points at the router rather than individual workers. For engines behind certificates from a private CA, the per-provider `ca_cert_pem` setting trusts that CA without turning off TLS checks. The same file holds external providers, so one [LLM gateway](https://www.getmaxim.ai/llm-gateway) fronts the GPUs you run and the APIs you rent, out of [10,000+ models across 25+ providers](https://docs.getbifrost.ai/providers/supported-providers/overview). The JSON above follows the documented examples and was not run for this article.

### Logging and secrets inside the boundary

[Built-in observability](https://docs.getbifrost.ai/features/observability/default) records input messages, model parameters, the provider and model that served each call, output messages, tool calls, latency, token usage, cost, and status. The logging plugin writes asynchronously, off the request path. SQLite is the default store and suits development; PostgreSQL is the documented choice for high-volume production. When prompts carry data you must not retain, `disable_content_logging` drops request and response content but still records usage metadata. Traces can also go to your own collector over [OpenTelemetry](https://docs.getbifrost.ai/features/observability/otel), so observability stays inside the network.

For credentials, config values can reference environment variables with the `env.` prefix. On Bifrost Enterprise, [secret management](https://docs.getbifrost.ai/deployment-guides/config-json/secret-management) resolves `vault.<path>` references from HashiCorp Vault, AWS Secrets Manager, GCP Secret Manager, or Azure Key Vault, which requires the enterprise image and a PostgreSQL config store.

### Fallbacks and the hybrid rule

A request can carry a `fallbacks` list of `provider/model` entries. Bifrost tries the primary with its full retry budget, then each fallback in order, each with its own retry budget, and reports in `extra_fields.routing_info` which provider served the request and whether it was a fallback ([fallbacks](https://docs.getbifrost.ai/features/fallbacks)). If every attempt fails, the caller gets the primary's original error.

To make the hybrid rule hold even when an app sends the wrong fallback list, restrict providers on the caller's [virtual key](https://docs.getbifrost.ai/features/governance/virtual-keys). Providers are deny-by-default on a key, and a request for one the key does not list gets HTTP 403 with `provider_blocked`. Governance runs again on each fallback attempt, so a key that lists only `vllm` and `sgl` cannot spill sensitive traffic to a cloud model during a GPU outage.

The same control plane carries [governance](https://www.getmaxim.ai/resources/governance) and security controls (virtual keys, budgets, [guardrails](https://aifordevs.org/glossary#guardrails), audit logs), and [Bifrost Edge](https://www.getmaxim.ai/edge) extends them to AI apps and coding agents on employee machines. Edge routes that traffic through the same gateway, so existing [guardrail profiles apply on each device](https://docs.getbifrost.ai/edge/security) with nothing extra to set up on the endpoint, which matters when the point of self-hosting is keeping data inside the company.

## Running self-hosted AI fully air-gapped

A fully air-gapped deployment has no outbound internet, so every external dependency must be replaced by a local file or turned off before the software starts. That applies to the gateway, the engines, and the weights.

The [air-gapped deployment guide](https://docs.getbifrost.ai/deployment-guides/how-to/airgapped) lists what Bifrost fetches from getbifrost.ai:

- **Pricing and model-parameter datasheets.** Bifrost fails to start without them. Download both on a connected machine, carry them across, and point `pricing_url` and `model_parameters_url` at `file://` paths in `config.json`.
- **The MCP server catalog.** Point `mcp_library_url` at a local file, or set `mcp_library_sync_interval` to `0` so no request goes out.

The `file://` values are honored only from `config.json`, not from the UI or the config API. Bifrost re-reads local files on each sync tick, so replacing a file on disk takes effect without a restart.

Beyond the gateway, mirror container images and model weights into an internal registry, pin every version, and decide in advance how updated weights and engine releases cross the gap, because each crossing is a change-management event.

## How to start a self-hosted AI rollout

Start with measurement and one model, then add layers in the order failures would hurt most.

1. **Measure.** Record tokens per hour at peak and off-peak for each workload, and tag which workloads carry data that cannot leave.
2. **Pick one open-weight model and one engine.** Run your own evaluation set at real prompt lengths, and read vLLM's KV cache and concurrency log lines against your peak.
3. **Put the gateway in first.** Point apps at the gateway's OpenAI-compatible endpoint before moving any traffic, so switching backends later is a config change.
4. **Turn on logging and move keys out of files.** Use PostgreSQL for logs at production volume and `disable_content_logging` where content must not be kept.
5. **Write the hybrid rule into virtual keys.** Sensitive callers get keys that list only self-hosted providers; frontier callers get keys that list approved external ones.
6. **Rerun the break-even monthly.** API prices fall and traffic shifts, so recompute utilization against current rent and current per-token prices before buying more GPUs.

The Bifrost, vLLM, SGLang, and Ollama details here describe each project as of November 23, 2026.

## Questions

### Can you self-host an AI model?

Yes. Open-weight models run on your own GPUs through an inference engine such as vLLM, SGLang, or Ollama, each of which exposes an OpenAI-compatible HTTP API. Closed frontier models cannot be self-hosted, because their weights are not published. Once more than one team uses the models, put a gateway in front so keys, routing, and logs live in one place instead of in every app.

### Is self-hosted AI free?

The software can be. Open-weight models and engines such as vLLM, SGLang, and Ollama are free to download, and the Bifrost gateway core is Apache 2.0. The cost moves to GPUs, power or cloud rent, storage, and the engineers who upgrade drivers, patch engines, and carry the pager. Whether that beats per-token pricing depends on how busy the GPUs stay.

### Is self-hosting an LLM cheaper than using an API?

Only above a utilization threshold. OpenRouter's November 2026 analysis put break-even against the median zero-retention API at 8% load for a $0.50-an-hour RTX 3090, 37% for B200s rented at $3.70 an hour, and never for H200s at $4.59 an hour. Steady, high-volume traffic favors owned GPUs; spiky or low traffic favors paying per token.

### What hardware do you need to self-host AI?

You need GPU memory for the model weights plus the KV cache that holds tokens for every request in flight. vLLM's guidance is to stay on one GPU if the model fits, use tensor parallelism across GPUs in one node if it does not, and add pipeline parallelism across nodes beyond that. vLLM logs a maximum concurrency estimate at startup to size against.

### Should you self-host AI or use a hosted service?

Self-host when data cannot leave your network or when steady volume keeps GPUs busy enough to beat per-token prices. Use a hosted service for frontier models you cannot download and for low or unpredictable volume. Many teams run both behind one gateway: sensitive and bulk work on local GPUs, hard reasoning tasks on an external provider through a single approved egress.

### What is an air-gapped LLM deployment?

An air-gapped LLM deployment runs the models, the gateway, and every dependency in a network with no outbound internet access. Container images and model weights come from an internal registry, and anything the software would normally download must be supplied as a local file. Bifrost, for example, needs its pricing and model-parameter datasheets loaded through file:// paths before it will start.

## Sources

1. [OpenRouter, Self-hosted LLM vs API: when does self-hosting pay off (published November 12, 2026; prices as of October 8, 2026)](https://openrouter.ai/blog/insights/self-hosted-llm-vs-api/)
2. [vLLM docs, Parallelism and scaling (read November 23, 2026)](https://docs.vllm.ai/en/latest/serving/parallelism_scaling/)
3. [vLLM docs, OpenAI-compatible server (read November 23, 2026)](https://docs.vllm.ai/en/latest/serving/online_serving/openai_compatible_server/)
4. [SGLang docs, Data parallelism and sgl-router guide (read November 23, 2026)](https://docs.sglang.io/docs/advanced_features/dp_dpa_smg_guide)
5. [Ollama docs, FAQ (read November 23, 2026)](https://docs.ollama.com/faq)
6. [Bifrost, reference for AI systems (llm-info, last updated September 2026)](https://www.getmaxim.ai/llm-info)
7. [Bifrost docs, Gateway setup (read November 23, 2026)](https://docs.getbifrost.ai/quickstart/gateway/setting-up)
8. [Bifrost docs, Deployment guides overview (read November 23, 2026)](https://docs.getbifrost.ai/deployment-guides/overview)
9. [Bifrost docs, Provider configuration in config.json (read November 23, 2026)](https://docs.getbifrost.ai/deployment-guides/config-json/providers)
10. [Bifrost docs, Built-in observability (read November 23, 2026)](https://docs.getbifrost.ai/features/observability/default)
11. [Bifrost docs, Secret management (read November 23, 2026)](https://docs.getbifrost.ai/deployment-guides/config-json/secret-management)
12. [Bifrost docs, Fallbacks (read November 23, 2026)](https://docs.getbifrost.ai/features/fallbacks)
13. [Bifrost docs, Virtual keys (read November 23, 2026)](https://docs.getbifrost.ai/features/governance/virtual-keys)
14. [Bifrost docs, Air-gapped deployment (read November 23, 2026)](https://docs.getbifrost.ai/deployment-guides/how-to/airgapped)
15. [Bifrost docs, In-VPC deployments (read November 23, 2026)](https://docs.getbifrost.ai/enterprise/invpc-deployments)
16. [Bifrost docs, Edge security and guardrails (read November 23, 2026)](https://docs.getbifrost.ai/edge/security)

## Cite this deep dive

AI for Devs. "Self-hosted AI: running LLM infrastructure in your own VPC." Published November 25, 2026. https://aifordevs.org/articles/self-hosted-ai

- Page: https://aifordevs.org/articles/self-hosted-ai
- Markdown: https://aifordevs.org/articles/self-hosted-ai.md
- Reuse: Quote or summarize with a link to this page. Terms: https://aifordevs.org/reuse
- Publisher: AI for Devs
- Published: 2026-11-25
