---
title: "Self-hosted AI: how to run a private LLM stack on your own infrastructure"
description: "Self-hosted AI for production teams: model serving, a gateway, logging, secrets, network isolation, hybrid routing with managed APIs, and air-gapped setups."
summary: "A production self-hosted AI deployment needs more than an inference server: it needs a gateway, a log store, secret handling, and network rules that decide what may leave. This guide covers each layer, compares self-hosting with managed APIs, and explains hybrid routing and air-gapped setups."
type: "guide"
canonical_url: "https://theaiengineering.com/articles/self-hosted-ai"
markdown_url: "https://theaiengineering.com/articles/self-hosted-ai.md"
topic: "LLM inference and serving"
author: "The AI Engineering Editors"
publisher: "The AI Engineering"
published: "2026-11-23"
updated: "2026-11-23"
keywords: ["self hosted ai","self hosted ai models","self hosted ai gateway","self hosted llm vs api","air gapped llm"]
citation: "The AI Engineering Editors. \"Self-hosted AI: how to run a private LLM stack on your own infrastructure.\" The AI Engineering, updated Nov 23, 2026. https://theaiengineering.com/articles/self-hosted-ai"
---

# Self-hosted AI: how to run a private LLM stack on your own infrastructure

## TL;DR

- Self-hosted AI runs open-weight models on servers an organization operates, so prompts, responses, and logs stay inside its network unless a route is explicitly allowed to send them out.
- A production self-hosted AI stack has five layers inside one network boundary: calling applications, a gateway, inference servers, stores for logs and secrets, and network rules that limit egress to the gateway.
- Self-hosting replaces per-token pricing with fixed GPU cost, so steady high-volume workloads favor it, while spiky or low-volume workloads usually cost less on a managed API.
- In a hybrid setup, a gateway sends restricted data to self-hosted models and frontier tasks to managed APIs, and the fallback for restricted data should be another self-hosted model, never an external provider.
- A fully air-gapped LLM deployment works once model weights, container images, and every file a component downloads at startup are mirrored inside the network and engine telemetry is switched off.

Self-hosted AI is the practice of running AI models, and the services that control access to them, on infrastructure your organization operates, so prompts, responses, and logs stay inside your network unless you choose to send them out. Installing an inference server is only the first step: a production deployment also needs a gateway, a log store, secret handling, and network rules that decide what may leave. This guide covers each layer, the trade-offs against managed APIs, hybrid routing, and fully air-gapped setups, with [Bifrost](https://www.getmaxim.ai), an [open-source AI gateway](https://github.com/maximhq/bifrost) by Maxim AI, as the worked example for the gateway layer. It is part of the [LLM inference hub](https://theaiengineering.com/topics/llm-inference).

## What is self-hosted AI?

Self-hosted AI is an AI system whose models run on servers your organization operates, served by inference software you control rather than by a vendor's API. The hardware can be a data center GPU server, GPU instances in your own cloud account, or an isolated cluster; what matters is who runs the model server and where data flows.

A self-hosted LLM deployment runs [open-weight models](https://theaiengineering.com/glossary/open-weights-model), whose weights are published for download, on an [inference engine](https://theaiengineering.com/glossary/inference-engine) such as vLLM, SGLang, or Ollama. Closed-weight models are not candidates, because their weights are not published. For a company, the result is a shared internal service with the same access control, logging, and change management as any other internal API, not one engineer's laptop.

The data boundary is only as tight as its weakest component. A self-hosted model behind a gateway that exports full prompts to a hosted logging service still sends prompt content out of the network, so every layer below has to stay inside the boundary or be configured not to carry content.

## Self-hosted LLM vs API: the trade-offs

Self-hosting trades per-token pricing and a provider's data terms for fixed GPU cost and an operations job your team now owns. Neither option is cheaper by default. Utilization determines cost, data rules determine whether self-hosting is required, and model quality determines whether an open-weight model can do the work at all.

| Dimension | Self-hosted models | Managed API |
|---|---|---|
| Where prompts go | Stay inside your network | Sent to the provider under its retention and processing terms |
| Cost shape | Fixed GPU cost, paid whether GPUs are busy or idle | Per-token price that scales with usage |
| Models available | Open-weight models only | Includes closed-weight frontier models |
| Capacity | Limited by the GPUs you run; excess requests queue | Limited by the provider's rate limits and quotas |
| Model changes | Nothing changes until you deploy new weights | The provider updates and retires models on its own schedule |
| Operations | You own drivers, engine upgrades, scaling, and on-call | The provider runs serving |
| Internet dependency | Can run with no outbound access | Requires a network path to the provider |

A third option sits between the two: an [inference provider](https://theaiengineering.com/platforms/inference-providers) that serves open-weight models over an API. Prompts still leave the network, but the application already uses the model it would self-host, so moving in-house later changes the endpoint rather than the model.

Self-hosting pays off when data must stay in the network, traffic keeps GPUs busy, and an open-weight model passes your own evaluation set. When only the first condition holds, use the hybrid pattern described below.

## The self-hosted AI stack, layer by layer

A production self-hosted AI stack has five layers inside one network boundary: the applications and agents that call models, a gateway that is their only entry point, inference servers on GPU nodes, stores for logs, traces, and secrets, and network controls that decide what may leave. Each layer can leak data on its own, so each one needs its own configuration.

**Figure 1: A self-hosted AI stack. Applications call only the gateway, and the gateway is the only layer allowed to reach anything outside the network.**

Five layers of a self-hosted AI stack inside one network boundary: applications, a gateway, inference servers, stores for logs and secrets, and network controls that limit egress.

Layers, top to bottom:

1. **Applications and agents**: Call one OpenAI-compatible endpoint (internal apps, agents, chat UI)
2. **Gateway**: Gateway-issued keys and routing Fallbacks, budgets, and guardrails (auth, routing, request logs)
3. **Model serving**: Open-weight models on GPU nodes (vLLM, SGLang, Ollama)
4. **Logs, traces, and secrets**: Stores the security team can audit (PostgreSQL, OTel collector, secret manager)
5. **Network boundary**: Private subnets and an egress allowlist (no inbound, no GPU egress, internal registry)

Operated by the platform team spans Gateway through Network boundary.

A request moves through the stack in four steps:

1. An internal app or agent sends an OpenAI-format request to the gateway with a gateway-issued key.
2. The gateway authenticates the key, applies budgets and rate limits, and picks a backend from its routing rules.
3. The gateway forwards the request to an inference server on a private subnet or, if the route allows egress, to an approved external provider.
4. The gateway writes metadata, and content where policy allows, to a log store inside the network, and exports traces to an internal collector.

## Model serving: choosing self-hosted AI models and hardware

The model-serving layer loads open-weight models onto GPUs and exposes them over HTTP. Engine choice follows concurrency: vLLM or SGLang for shared GPU serving with many simultaneous requests, and Ollama for development machines and small internal tools. Hardware follows the model, because GPU memory must hold the weights plus the cache for every in-flight request. The [self-hosted LLM guide](https://theaiengineering.com/articles/self-hosted-llm) covers that memory arithmetic and each serving tier step by step; this section covers only what the rest of the stack needs from the serving layer.

- **vLLM:** provides an [OpenAI-compatible HTTP server](https://docs.vllm.ai/en/latest/serving/online_serving/openai_compatible_server/) started with `vllm serve <model>`. Each server is started for one model, so plan one deployment per model you offer.
- **SGLang:** targets the same multi-user GPU serving as vLLM. The [vLLM vs Ollama comparison](https://theaiengineering.com/articles/vllm-vs-ollama) covers how the two differ and when each fits.
- **Ollama:** the easiest engine to start with. Ollama [binds to 127.0.0.1 on port 11434 by default](https://docs.ollama.com/faq), so a gateway on another host cannot reach it until `OLLAMA_HOST` changes the bind address. Its default `OLLAMA_MAX_LOADED_MODELS` allows three loaded models per GPU, memory permitting.

Each replica needs GPU memory for the weights plus a [KV cache](https://theaiengineering.com/glossary/kv-cache), the per-request memory that grows with context length and concurrency. A model that does not fit on one GPU needs [tensor parallelism](https://theaiengineering.com/glossary/tensor-parallelism) across the GPUs of a node.

[Quantization](https://theaiengineering.com/glossary/quantization) shrinks the weights at some cost in quality, so test it on your own tasks. The [LLM inference optimization guide](https://theaiengineering.com/articles/llm-inference-optimization) covers sizing, batching, and parallelism in depth, and the [serving engines directory](https://theaiengineering.com/platforms/serving-engines) lists more engines.

For model choice, pick the smallest self-hosted LLM that passes your own evaluation set, check the license on its model card, and pin an exact revision so the model does not change when the copy on the hub is updated.

## The gateway layer: one entry point for every model

A self-hosted AI gateway gives every application one OpenAI-compatible endpoint in front of all the models the organization runs or rents, and moves authentication, routing, retries, budgets, guardrails, and logging into one place. Without a gateway, each application hardcodes inference URLs and failure handling, and adding a second model, team, or provider means changing every caller.

An [AI gateway](https://theaiengineering.com/glossary/ai-gateway) here does the same job as anywhere else, which the explainer on [what an AI gateway is](https://theaiengineering.com/articles/what-is-an-ai-gateway) covers, with one extra requirement: the gateway itself runs entirely inside the boundary. Callers receive gateway-issued [virtual keys](https://theaiengineering.com/glossary/virtual-key) instead of backend credentials, so revoking a team's access takes one change.

### What to look for in a self-hosted AI gateway

- **Runs inside the network:** every outbound call is documented and can be replaced by a local file or turned off.
- **Native support for self-hosted engines:** vLLM, SGLang, and Ollama endpoints next to managed providers, behind one [OpenAI-compatible API](https://theaiengineering.com/glossary/openai-compatible-api).
- **Private TLS:** trust for an internal certificate authority without disabling certificate checks.
- **A log store you operate:** a database inside the network, with control over whether prompt content is stored.
- **Fallbacks you control:** per-route rules for when a self-hosted model fails, including whether the request may leave the network.

### Bifrost as the self-hosted gateway

Bifrost is a control plane for model, MCP tool, and agent traffic with an Apache 2.0 open-source core, shipped as a single binary with a built-in web UI. It starts with `npx -y @maximhq/bifrost` or `docker run -p 8080:8080 maximhq/bifrost` and serves the UI and an OpenAI-compatible `/v1/chat/completions` endpoint on port 8080 ([gateway setup](https://docs.getbifrost.ai/quickstart/gateway/setting-up)). Bifrost does not serve models; it routes to the inference servers you run.

The Bifrost [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. One open-source instance can keep configuration and logs in SQLite under a persistent `/app/data` directory. Several open-source instances share one file-only `config.json` and the same secrets, with PostgreSQL 16 or later for shared logs, and Bifrost Enterprise requires PostgreSQL for both stores.

Self-hosted engines plug in as [providers that point to a URL you operate](https://docs.getbifrost.ai/deployment-guides/config-json/providers). The key `value` stays empty because self-hosted servers usually need no API key, each vLLM key maps one served model, and `ca_cert_pem` lets the gateway trust inference servers whose certificates come from a private CA:

```json
{
  "encryption_key": "env.BIFROST_ENCRYPTION_KEY",
  "providers": {
    "vllm": {
      "keys": [
        {
          "name": "vllm-llama-70b",
          "value": "",
          "models": ["llama-3-70b"],
          "weight": 1.0,
          "vllm_key_config": {
            "url": "https://vllm-llama.inference.internal:8000",
            "model_name": "meta-llama/Meta-Llama-3-70B-Instruct"
          }
        }
      ],
      "network_config": {
        "ca_cert_pem": "<PEM-encoded internal CA certificate>"
      }
    },
    "ollama": {
      "keys": [
        {
          "name": "ollama-dev",
          "value": "",
          "models": ["*"],
          "weight": 1.0,
          "ollama_key_config": { "url": "env.OLLAMA_URL" }
        }
      ]
    }
  }
}
```

Callers then name a provider and model, such as `vllm/llama-3-70b`. The same file can hold managed providers with their keys referenced from environment variables, so one gateway fronts both the GPUs you run and the APIs you rent.

## Logging and tracing without data leaving the network

Logging in a self-hosted stack should record metadata for every request (model, tokens, latency, status, and caller) in a store inside the network, and record prompt and response content only where a policy allows it. The common leak is a content setting applied to one destination while another destination, such as a trace exporter, still carries full prompts.

Decide three things before choosing tools: which routes may store content, how long logs are kept, and who may read stored prompts, which should be a smaller group than the people who read dashboards.

Bifrost separates the two kinds of data. Metadata covers model, provider, token counts, cost, latency, status, and governance attribution, content covers prompts, completions, and tool traffic, and Bifrost [strips content independently at each destination](https://docs.getbifrost.ai/features/observability/content-logging). For the log store, which can be SQLite, PostgreSQL, or ClickHouse, `disable_content_logging` applies at the client level and can be overridden per virtual key or per project.

Each Bifrost connector, such as OpenTelemetry or Kafka, has its own content setting, and metrics never carry content. Attribution identifiers such as user, team, and virtual key count as metadata, so a content setting never removes them; treat them separately if they are sensitive.

For tracing, Bifrost exports spans in the [OpenTelemetry](https://theaiengineering.com/glossary/opentelemetry) GenAI semantic conventions to any OTLP collector, including a [self-hosted collector](https://docs.getbifrost.ai/features/observability/otel). Gateway logs show per-request facts, and the guide to [LLM observability](https://theaiengineering.com/articles/llm-observability) covers the application-level tracing that complements them.

## Secrets management for self-hosted AI

A self-hosted stack holds more secrets than teams expect: provider API keys for any managed routes, gateway-issued keys for callers, model-hub tokens for gated weights, database passwords, TLS keys, and the gateway's own encryption key. Keep all of them out of config files and container images, inject them at runtime, and store them in a secret manager.

- **Reference, never embed:** config files point at environment variables or secret-manager paths, and values arrive at runtime from Kubernetes Secrets or a vault.
- **Keep provider keys at the gateway:** callers hold gateway-issued keys, so rotating a provider key never touches application code.
- **Download gated weights elsewhere:** fetch weights with a hub token on a staging machine and copy them in, so the inference subnet never holds the token.

Bifrost config values accept an `env.` prefix, as in `env.OPENAI_API_KEY`, so keys never appear in `config.json`. Persisted credentials are protected by `BIFROST_ENCRYPTION_KEY`, which must stay the same across restarts, replicas, upgrades, and restores, because changing it can make stored values unreadable. By default, Bifrost keeps provider keys and virtual key values in its config database.

[Secret management in Bifrost Enterprise](https://docs.getbifrost.ai/enterprise/secret-management) connects HashiCorp Vault, AWS Secrets Manager, GCP Secret Manager, or Azure Key Vault, after which any secret field accepts a `vault.<path>` reference that Bifrost resolves at runtime. The default `read_only` mode resolves references without writing to the vault. The feature requires the Enterprise image and a PostgreSQL config store.

## Network isolation and egress control

Network isolation puts inference servers on private subnets that accept connections only from the gateway and allow no outbound traffic, and makes the gateway the single component with egress, limited to the providers each route is approved to use. Authentication built into an inference engine is a second line of defense, not the boundary itself.

- **Don't rely on engine keys:** vLLM's `--api-key` option [authenticates only the `/v1`, `/v2`, `/inference`, and `/cohere` path prefixes](https://docs.vllm.ai/en/latest/serving/online_serving/openai_compatible_server/), so other routes on the same server stay open.
- **Expose Ollama narrowly:** after changing `OLLAMA_HOST`, firewall port 11434 so only the gateway can reach it.
- **Encrypt internal hops:** run TLS between the gateway and inference servers with an internal CA, which Bifrost trusts through `ca_cert_pem`; its `insecure_skip_verify` setting is a last resort.
- **Build the egress allowlist from config:** Bifrost [needs outbound access](https://docs.getbifrost.ai/deployment-guides/runtime-contract) to each provider, PostgreSQL server, MCP server, vector store, identity system, and observability endpoint in its configuration, so the firewall list can be generated from that file.

A network boundary governs only the traffic that reaches it. Employees who paste the same documents into a desktop chat app or a browser AI tool bypass the self-hosted stack entirely. Bifrost applies governance and security controls (virtual keys, budgets, guardrails, and audit logs) at the gateway, and [Bifrost Edge](https://www.getmaxim.ai/edge), which requires Bifrost Enterprise, extends the same governance and security to AI apps on employee machines, routing their traffic through the gateway so [existing guardrails apply on each device](https://docs.getbifrost.ai/edge/security).

## Hybrid routing: self-hosted models with managed APIs

A hybrid setup routes sensitive or high-volume work to self-hosted models and sends tasks that need a frontier model to a managed API, with the gateway hiding the difference from applications. One rule keeps it safe: the fallback for restricted data must point at another self-hosted model, never at an external provider, or an outage of the self-hosted model sends that data out of the network.

| Workload | Primary route | Fallback |
|---|---|---|
| Documents with customer, patient, or employee data | Self-hosted model | A second self-hosted model |
| Bulk tagging, extraction, and summarization | Self-hosted model on owned GPUs | A second self-hosted model, or queue and retry |
| Hard reasoning, long-context analysis, or agent planning with no restricted data | Managed API | A second provider or a self-hosted model |

**Figure 2: Hybrid routing. Restricted data stays on self-hosted models, including on fallback; only approved routes leave the network.**

Internal apps call one gateway, which sends restricted data to a self-hosted primary model, falls back to a second self-hosted model, and sends only approved traffic to an external provider.

Components:

- **Internal apps and agents**: One endpoint, one key each
- **Gateway**: Routing rules, fallbacks, guardrails
- **Self-hosted model A**: vLLM Primary for restricted data
- **Self-hosted model B**: SGLang Fallback for model A
- **External provider**: Managed API Frontier tasks only

Groups:

- Inside the network: Self-hosted model A, Self-hosted model B
- Outside: External provider

Connections:

- Internal apps and agents → Gateway
- Gateway → Self-hosted model A: restricted data
- Gateway → Self-hosted model B: fallback
- Gateway → External provider: approved egress

In Bifrost, a request can carry a `fallbacks` list of `provider/model` entries. The primary model gets its full retry budget, each fallback is then tried in order with its own retry budget, and the response's `routing_info` reports which provider served the request ([retries and fallbacks](https://docs.getbifrost.ai/features/retries-and-fallbacks)):

```bash
curl -X POST https://bifrost.internal:8080/v1/chat/completions \
  -H "Authorization: Bearer $BIFROST_VIRTUAL_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "vllm/llama-3-70b",
    "messages": [{"role": "user", "content": "Summarize this claim file."}],
    "fallbacks": ["sgl/fallback-model"]
  }'
```

Routes that may leave the network are where [guardrails](https://theaiengineering.com/glossary/guardrails) matter most. [Bifrost Enterprise guardrails](https://docs.getbifrost.ai/enterprise/guardrails) check requests and responses at the gateway, so personal data and credentials can be blocked or redacted before a prompt reaches an external provider.

## Running self-hosted AI fully air-gapped

A fully air-gapped LLM deployment has no outbound internet at all, so every dependency that normally downloads something at startup has to be mirrored inside the network or switched off before go-live. In practice that means model weights, container images, engine telemetry, guardrail services, and any data files the gateway fetches from its vendor.

| Dependency | Connected default | Air-gapped setup |
|---|---|---|
| Model weights | Downloaded from the Hugging Face Hub when an engine is given a repository ID | Copied into a local cache from a staging machine, with `HF_HUB_OFFLINE=1` set |
| Container images | Pulled from public or vendor registries | Mirrored into an internal registry with pinned versions |
| vLLM usage statistics | Anonymous usage data collected by default | `VLLM_NO_USAGE_STATS=1` or `DO_NOT_TRACK=1` |
| Ollama cloud features | Cloud models and web search available | `OLLAMA_NO_CLOUD=1` or `disable_ollama_cloud` |
| Bifrost pricing and model-parameter datasheets | Fetched from getbifrost.ai; Bifrost cannot start without them | Downloaded once, then loaded from `file://` paths |
| Bifrost MCP server catalog | Synced from getbifrost.ai | A local catalog file, or the sync turned off |
| Guardrails | Cloud services such as AWS Bedrock Guardrails or Azure Content Safety | Guardrails that run in-process, or a PII analyzer you host |

With `HF_HUB_OFFLINE` set, [huggingface_hub makes no HTTP calls](https://huggingface.co/docs/huggingface_hub/package_reference/environment_variables) and reads only cached files, and vLLM documents its [usage statistics and the variables that turn them off](https://docs.vllm.ai/en/latest/usage/usage_stats/). In a VPC with partial egress these defaults are real outbound calls, so switch them off there too.

The [Bifrost air-gapped deployment guide](https://docs.getbifrost.ai/deployment-guides/how-to/airgapped) covers the two things Bifrost fetches from getbifrost.ai. Download the datasheets on a connected machine, copy them in or bake them into the image, and point `config.json` at them; the MCP catalog can come from a local file or be switched off:

```json
{
  "framework": {
    "pricing": {
      "pricing_url": "file:///opt/bifrost/pricing.json",
      "model_parameters_url": "file:///opt/bifrost/model-parameters.json",
      "mcp_library_sync_interval": 0
    }
  }
}
```

Bifrost honors `file://` values only from `config.json`, not from the web UI or the config API, and re-reads local files on every sync tick, so a replaced datasheet takes effect without a restart. Bifrost Enterprise images come from a vendor registry, and the [on-premise guide](https://docs.getbifrost.ai/deployment-guides/enterprise/on-premise) shows the mirror: `docker save` on a connected machine, then `docker load`, tag, and push to the internal registry.

Guardrails need the same check. Bifrost's Secrets Detection runs inside the gateway on embedded Gitleaks rules, Custom Regex runs in-process with a PII template, and the Presidio integration calls an Analyzer endpoint you deploy, so all three work without egress. Beyond the gateway, plan how updated weights, images, and datasheets cross the gap, and keep a checksum for each file that does.

## Next steps

Start a self-hosted AI rollout with one route whose data cannot leave the network, one open-weight model that passes your evaluation set, and a gateway in front of it, then add hybrid routes only where the data allows. Teams evaluating a self-hosted AI gateway can [request a Bifrost demo](https://www.getmaxim.ai/book-a-demo) or run the open-source gateway from its repository.

To go deeper on a single layer, the [vLLM vs Ollama comparison](https://theaiengineering.com/articles/vllm-vs-ollama) covers engine choice, the [LLM inference optimization guide](https://theaiengineering.com/articles/llm-inference-optimization) covers GPU sizing, and the [LLM routing guide](https://theaiengineering.com/articles/llm-routing) covers routing strategies.

## Frequently asked questions

### Is self-hosted AI worth it?

Self-hosted AI is worth it when data must stay inside your network, traffic is steady enough to keep GPUs busy, and an open-weight model passes your own evaluation set for the task. If only the data requirement holds, self-host the sensitive routes and send everything else to a managed API through one gateway. For low or spiky volume with no data constraint, a managed API usually costs less.

### Is self-hosting an AI model cheaper than using an API?

Self-hosting is cheaper only at sustained utilization. GPUs cost the same whether they are busy or idle, while API pricing scales with the tokens you use. Compare total cost of ownership, including GPUs or cloud instances, power, storage, engine upgrades, and on-call engineering time, against the per-token bill at your real traffic volume. Spiky or low-volume workloads usually favor paying per token.

### Can you self-host AI models without a GPU?

Yes, for small models. llama.cpp and Ollama run quantized models on CPUs, which works for development, offline assistants, and low-traffic internal tools, but generation is much slower than on a GPU. Shared production serving for many concurrent users needs GPUs, because throughput depends on GPU memory for the weights and KV cache and on memory bandwidth during decoding.

### Is self-hosted AI the same as local AI?

Not quite. Local AI usually means one person running a model on a laptop or workstation, often with Ollama or LM Studio. Self-hosted AI is broader: any deployment where your organization operates the model server, including GPU servers in a data center, GPU instances in your own cloud account, and air-gapped clusters that many teams share behind a gateway.

### Can self-hosted AI work without an internet connection?

Yes. Once model weights, container images, and configuration files are inside the network, inference needs no internet access. Plan for the defaults that reach out: set HF_HUB_OFFLINE=1 for Hugging Face downloads, turn off vLLM usage statistics, disable Ollama's cloud features, and load any data files the gateway fetches from its vendor, such as Bifrost's pricing datasheets, from local paths.

### Should a company use self-hosted AI or ChatGPT?

Use self-hosted AI for work whose data cannot leave your network, or whose steady volume makes owned GPUs cheaper than per-seat or per-token pricing. Use ChatGPT or another managed service when people need the strongest closed-weight models and the provider's data terms are acceptable. Many companies run both and route each request through one gateway according to the data it contains.

## Terms in this guide

- [Open-weights model](https://theaiengineering.com/glossary/open-weights-model): An open-weights model is an AI model whose trained parameters are published for download, so anyone can run, fine-tune, or quantize it on their own hardware under the terms of its license.
- [Inference engine](https://theaiengineering.com/glossary/inference-engine): An inference engine is the software that serves a trained language model: it loads the weights, batches incoming requests, manages KV cache memory, runs the forward passes, and streams generated tokens over an API.
- [KV cache](https://theaiengineering.com/glossary/kv-cache): The KV cache is GPU memory that stores the attention key and value vectors already computed for previous tokens, so a transformer generating text computes them once instead of at every step.
- [Tensor parallelism](https://theaiengineering.com/glossary/tensor-parallelism): Tensor parallelism is a model parallelism technique that splits the weight matrices inside each transformer layer across several GPUs, which compute every token together and combine partial results through all-reduce operations.
- [Quantization](https://theaiengineering.com/glossary/quantization): Quantization is a model compression technique that represents a neural network's weights, and sometimes its activations or KV cache, with fewer bits, such as 8-bit or 4-bit integers instead of 16-bit floats.
- [AI gateway](https://theaiengineering.com/glossary/ai-gateway): An AI gateway is a proxy layer between applications and model providers that exposes one API for many models and centralizes routing, failover, access control, cost tracking, caching, and logging.
- [Virtual key](https://theaiengineering.com/glossary/virtual-key): A virtual key is an API key issued by an AI gateway that maps a caller to its allowed models, budget, and rate limits, while the gateway keeps the real provider credentials.
- [OpenAI-compatible API](https://theaiengineering.com/glossary/openai-compatible-api): An OpenAI-compatible API is an HTTP API that accepts OpenAI's request and response formats, so code written for OpenAI's SDKs can call another server by changing the base URL, API key, and model name.
- [OpenTelemetry](https://theaiengineering.com/glossary/opentelemetry): OpenTelemetry is an open source, vendor-neutral observability framework of APIs, SDKs, a wire protocol, and naming conventions for traces, metrics, and logs, including conventions for LLM calls and agent runs.
- [Guardrails](https://theaiengineering.com/glossary/guardrails): Guardrails are programmatic checks placed around a large language model that validate, filter, or block inputs, outputs, and tool calls so an AI application stays within its safety, security, and policy limits.

## Related guides

- [How to self-host an LLM: hardware, serving engines, and a production setup](https://theaiengineering.com/articles/self-hosted-llm): Self-hosted LLM guide: size GPU memory for weights and KV cache, run models locally with Ollama or llama.cpp, and serve them with vLLM, SGLang, or Kubernetes.
- [vLLM vs Ollama vs llama.cpp vs SGLang: which engine to use](https://theaiengineering.com/articles/vllm-vs-ollama): vLLM vs Ollama compared with llama.cpp, SGLang, LM Studio, and TensorRT-LLM: scope, hardware, APIs, concurrency, and which engine fits local or production use.
- [LLM inference optimization: a practical guide for engineers](https://theaiengineering.com/articles/llm-inference-optimization): LLM inference optimization guide: prefill vs decode, TTFT, KV cache and PagedAttention, continuous batching, quantization, speculative decoding, and GPUs.
- [What is an AI gateway? How it works and when you need one](https://theaiengineering.com/articles/what-is-an-ai-gateway): An AI gateway is a proxy between your apps and model providers. Learn how it works, its core features, AI gateway vs API gateway, and open source options.

Part of the [LLM inference and serving](https://theaiengineering.com/topics/llm-inference) topic hub.

## Cite this guide

The AI Engineering Editors. "Self-hosted AI: how to run a private LLM stack on your own infrastructure." The AI Engineering, updated Nov 23, 2026. https://theaiengineering.com/articles/self-hosted-ai

- Title: Self-hosted AI: how to run a private LLM stack on your own infrastructure
- Author: The AI Engineering Editors
- Publisher: The AI Engineering
- Published: 2026-11-23
- Updated: 2026-11-23
- URL: https://theaiengineering.com/articles/self-hosted-ai
- Markdown: https://theaiengineering.com/articles/self-hosted-ai.md

To cite one section, link to its anchor:

- [What is self-hosted AI?](https://theaiengineering.com/articles/self-hosted-ai#what-is-self-hosted-ai)
- [Self-hosted LLM vs API: the trade-offs](https://theaiengineering.com/articles/self-hosted-ai#self-hosted-llm-vs-api-the-trade-offs)
- [The self-hosted AI stack, layer by layer](https://theaiengineering.com/articles/self-hosted-ai#the-self-hosted-ai-stack-layer-by-layer)
- [Model serving: choosing self-hosted AI models and hardware](https://theaiengineering.com/articles/self-hosted-ai#model-serving-choosing-self-hosted-ai-models-and-hardware)
- [The gateway layer: one entry point for every model](https://theaiengineering.com/articles/self-hosted-ai#the-gateway-layer-one-entry-point-for-every-model)
- [Logging and tracing without data leaving the network](https://theaiengineering.com/articles/self-hosted-ai#logging-and-tracing-without-data-leaving-the-network)
- [Secrets management for self-hosted AI](https://theaiengineering.com/articles/self-hosted-ai#secrets-management-for-self-hosted-ai)
- [Network isolation and egress control](https://theaiengineering.com/articles/self-hosted-ai#network-isolation-and-egress-control)
- [Hybrid routing: self-hosted models with managed APIs](https://theaiengineering.com/articles/self-hosted-ai#hybrid-routing-self-hosted-models-with-managed-apis)
- [Running self-hosted AI fully air-gapped](https://theaiengineering.com/articles/self-hosted-ai#running-self-hosted-ai-fully-air-gapped)
- [Next steps](https://theaiengineering.com/articles/self-hosted-ai#next-steps)
- [Frequently asked questions](https://theaiengineering.com/articles/self-hosted-ai#faq)
