New

Announcing AISIX: The AI-Native AI Gateway for LLMs and AI AgentsLearn More

Learn More

Self-Hosted LLM Gateway: Why and How to Choose (2026)

By API7.ai Team

Last updated: August 2026

Every team that ships LLM features ends up building the same middle layer: something that holds the provider API keys, hands out per-team credentials, enforces limits, retries failed calls, and logs token usage. You can get that layer as a SaaS, or you can run it yourself. This guide is for the second option: what an LLM gateway actually does, why platform teams self-host one, what to evaluate, and an honest survey of six self-hostable open-source options — AISIX, LiteLLM, Bifrost, Portkey Gateway, TensorZero (now archived), and Higress.

TL;DR

Self-host an LLM gateway when provider keys, prompts, and completions must stay inside your network, when you can’t accept a per-request third-party dependency, or for compliance and latency. Six open-source projects cover the space — AISIX, LiteLLM, Bifrost, Portkey Gateway, TensorZero (archived June 2026), and Higress — and they genuinely optimize for different constraints. The honest trade-off: you now operate it.

  • Broadest provider coverage, Python-native, OSS virtual keys and budgets: LiteLLM
  • Go shop wanting a fast start with a built-in UI: Bifrost
  • Edge/serverless runtimes or a minimal Node footprint: Portkey Gateway
  • One Envoy data plane for APIs and AI on Kubernetes: Higress
  • Semantic routing, ensemble models, and full governance in one Apache-2.0 binary: AISIX
  • What a gateway does
  • Why self-host
  • What to evaluate
  • The six options
  • Single-container example
  • How to choose
  • FAQ

What an LLM gateway does

An LLM gateway (also called an AI gateway or LLM proxy) sits between your applications and model providers. In practice, the layer covers six jobs: credential separation, rate and token limits, routing and failover, caching, observability, and guardrails.

  • Credential separation. Provider API keys live at the gateway. Applications and teams get gateway-issued caller keys instead, so a leaked app key never exposes your OpenAI or Anthropic account, and revoking one consumer doesn’t rotate keys for everyone.
  • Rate and token limits. Requests per minute/day and tokens per minute/day, per caller key, model, or team — plus concurrency caps so one runaway agent can’t starve everyone else.
  • Routing and failover. One model alias that maps to real deployments behind it, with retries, fallback targets, and load balancing across providers or API keys.
  • Caching. Serving repeated requests from the gateway instead of paying the provider again.
  • Observability. Per-request logs with token counts and cost attribution, metrics for dashboards, and traces you can send to whatever backend you already run.
  • Guardrails. Input and output content policies — keyword blocks, PII detection and redaction, or calls out to moderation services — enforced in one place instead of in every app.

Increasingly there is a seventh job: agent traffic. Agents call tools over MCP (Model Context Protocol) and other agents over A2A, and that traffic needs the same keys, limits, and logs as chat completions. Some gateways now govern all three through one control point.

Why self-host an LLM gateway?

Four reasons come up consistently with platform teams: credentials stay in your infrastructure, no per-request third-party dependency, compliance, and latency.

  • Credentials stay in your infrastructure. With a hosted gateway, your provider keys — and every prompt and completion — transit a third party. Self-hosting keeps both inside your network boundary.
  • No per-request third-party dependency. A hosted gateway is on the critical path of every LLM call. Its outages are your outages, and its rate limits are your rate limits. A gateway you run has exactly the availability you engineer for it.
  • Compliance. Prompts routinely carry customer data. If you have data-residency or regulatory constraints, routing that data through a gateway vendor is a contract negotiation; routing it through your own VPC usually isn’t.
  • Latency. A self-hosted gateway adds one hop inside your network before the call goes to the provider. A hosted gateway adds a round-trip to someone else’s cloud first.

The honest trade-off: you now operate it. Upgrades, TLS, and high availability are your problem — the FAQ below covers the standard patterns, and they are well-trodden.

What to evaluate in a self-hosted LLM gateway

Six dimensions separate the options in practice: deployment weight, wire compatibility, governance depth in the open-source tier, agent-protocol support, observability exports, and license stability.

DimensionWhat to checkWhy it matters
Deployment weightWhat must run around the gateway: a single container with a config file, a database for key management, a cache for shared state, or a full Kubernetes control planeNone of these shapes is wrong — a database-backed gateway buys you a management UI and API-driven config — but the weight should match your team. Patching a five-service stack is a different commitment than redeploying one container.
Wire compatibilityThe OpenAI chat-completions API is table stakes. Does it also accept the Anthropic Messages API (/v1/messages) natively, and can it translate either wire format to any backend?Claude-based agent tooling speaks Anthropic’s format, and a gateway that translates both directions lets you point any SDK at any provider without code changes.
Governance depth in the OSS tierRead the feature list twice: once for what the product does, once for which tier does it. Common lines: caller/virtual keys and rate limits in open source, with guardrails or clustering in an enterprise editionThere is nothing wrong with a commercial line — most projects here have one somewhere — but you want to know where it is before you standardize.
Agent-protocol supportAn MCP gateway (registering upstream MCP servers behind one governed endpoint, with per-caller tool access) and A2A support — and whether they sit behind the same keys, limits, and logs as LLM traffic or form a separate systemIf agents are on your roadmap, agent traffic needs the same governance as chat completions.
Observability exportsWhat the open-source tier exports, and whether cost/usage data is includedPrometheus metrics and OTLP trace export are the portability baseline — they feed Grafana, Langfuse, Honeycomb, Datadog, or anything else without lock-in.
License stabilityThe actual LICENSE file, not the marketing pageAll six projects below carry OSI-approved licenses today (Apache-2.0 or MIT), but the structures differ: some repos are uniformly licensed, one carves an enterprise/ directory under a separate commercial license inside the same repo, and one is currently merging its enterprise gateway into open source.

Six self-hostable LLM gateways

Disclosure: this guide is published by API7.ai, the company behind AISIX; facts about the other five projects are drawn from their official READMEs, docs, and LICENSE files. Star counts were fetched from the GitHub API on 2026-08-21 — treat them as order-of-magnitude.

DimensionLanguageLicenseMinimal self-hosted shape
AISIXRustApache-2.0One container; one declarative resources.yaml for all dynamic resources; no database or control plane
LiteLLMPythonMIT (separate license for enterprise/)pip or Docker; Postgres required for virtual keys
BifrostGoApache-2.0npx or Docker, built-in web UI
Portkey GatewayTypeScriptMITnpx / Node.js / Docker / Cloudflare Workers
TensorZeroRustApache-2.0One container; ClickHouse optional, for observability
HigressGo (Envoy/Istio)Apache-2.0Docker all-in-one locally; Helm on Kubernetes

AISIX

github.com/api7/aisix

AISIX is a Rust gateway from API7.ai, built by the original creators of Apache APISIX and shipped as a single static binary under Apache-2.0. It accepts both the OpenAI wire format and the Anthropic Messages API (POST /v1/messages) as first-class routes and translates either — streaming included — to five native adapter families: OpenAI (which covers any OpenAI-compatible endpoint such as vLLM, Ollama, or DeepSeek), Anthropic, AWS Bedrock, Google Vertex (Gemini), and Azure OpenAI.

Language

Rust

License

Apache-2.0

Minimal shape

One container; one declarative resources.yaml for all dynamic resources; no database or control plane

Pros

  • Governance ships in the open-source tier: hashed caller API keys with model allowlists and expiry, OIDC/JWT inbound auth, and rate limits (RPS/RPM/RPH/RPD plus TPM/TPD and concurrency caps, shareable across replicas via Redis)
  • Guardrails spanning keyword rules, built-in PII detection and redaction, Presidio, Lakera, OpenAI Moderation, Bedrock Guardrails, Azure AI Content Safety, and two Alibaba Cloud services
  • Exact-match response caching with cost-saved telemetry, plus semantic caching that serves cached answers to differently-worded requests (shipped in v0.9.0, in-process or on Redis vector search)
  • Observability via Prometheus, OTLP GenAI spans (Langfuse, Honeycomb, Grafana, any OTLP receiver), and Datadog/Aliyun SLS exporters
  • Also an MCP gateway (upstream MCP servers behind one governed /mcp endpoint with per-caller tool access) and an A2A agent gateway — behind the same keys, limits, and logs as LLM traffic
  • Semantic routing (dispatch by request meaning) and ensemble models (panel fan-out with judge synthesis) ship in the same Apache-2.0 core; the gateway is covered by 496 end-to-end cases run against real gateway processes

Cons

  • Provider coverage is five adapter families plus anything OpenAI-compatible, rather than dozens of per-vendor integrations
  • Prompt templates managed as gateway resources are still on its public roadmap
  • Multi-tenant teams, dashboards, audit, and spend caps live in the commercial AISIX Cloud control plane, not the OSS gateway — though rate and token limits are fully open source

LiteLLM

github.com/BerriAI/litellm

LiteLLM is the project with the largest GitHub-star count among those surveyed and its ecosystem breadth is a genuine strength. It provides one OpenAI-format interface to 100+ LLM providers, usable as a Python SDK or as a proxy server, and per its README the proxy ships virtual keys, spend tracking, guardrails, load balancing, and an admin dashboard out of the box — a notably generous open-source tier.

Language

Python

License

MIT (separate license for enterprise/)

Minimal shape

pip or Docker; Postgres required for virtual keys

GitHub stars

Roughly 56.9k as of August 2026

Pros

  • Broadest provider coverage here: 100+ LLM providers behind one OpenAI-format interface
  • Usable as a Python SDK or as a proxy server
  • Virtual keys, spend tracking, guardrails, load balancing, and an admin dashboard in open source, per its README
  • MCP and A2A gateway functionality
  • A strong option for broad provider coverage on a Python-native stack

Cons

  • Deployment weight is the main thing to plan for: virtual keys require a Postgres database
  • Its own production reference architecture (published Terraform modules) runs the gateway, backend, and UI as separate services with managed Postgres, Redis, and an object store
  • The enterprise/ directory inside the same repository is under a separate commercial license — worth knowing when you vendor or fork

Bifrost

github.com/maximhq/bifrost

Bifrost, from Maxim AI, is a Go gateway under Apache-2.0 that unifies 23+ providers behind an OpenAI-compatible API. Its developer experience is a strength: it starts with a single npx command or Docker container, includes a built-in web UI for configuration and monitoring, and offers drop-in base_url replacement for the OpenAI, Anthropic, and Google GenAI SDKs.

Language

Go

License

Apache-2.0

Minimal shape

npx or Docker, built-in web UI

GitHub stars

Roughly 7.5k as of August 2026

Pros

  • Fast start: a single npx command or Docker container, with a built-in web UI
  • Drop-in base_url replacement for the OpenAI, Anthropic, and Google GenAI SDKs
  • README lists governance (virtual keys, usage tracking, rate limiting, fine-grained access control), hierarchical budget management, semantic caching, and MCP tool support among its features
  • A good fit for Go shops that want a fast start with a UI

Cons

  • Its enterprise section states that enterprise deployments unlock adaptive load balancing, clustering, guardrails, and the MCP gateway

Portkey Gateway

github.com/Portkey-AI/gateway

Portkey’s open-source gateway is a TypeScript project under MIT, positioned as a lightweight router to 250+ LLMs. It runs via npx, Node.js, Docker, or Cloudflare Workers, giving it a documented edge-runtime deployment path.

Language

TypeScript

License

MIT

Minimal shape

npx / Node.js / Docker / Cloudflare Workers

GitHub stars

Roughly 12.8k as of August 2026

Pros

  • Deploys naturally to edge runtimes (Cloudflare Workers) as well as npx, Node.js, and Docker
  • OSS tier covers fallbacks, automatic retries, load balancing, conditional routing, request timeouts, and a guardrails framework
  • Documents an MCP gateway as part of the product
  • Has announced that its core enterprise gateway is merging into open source with the Gateway 2.0 release (in pre-release at the time of writing) — a move toward more OSS, worth re-checking when 2.0 lands

Cons

  • The README marks several features — semantic caching, prompt template management, and provider optimization — as available in the hosted and enterprise versions

TensorZero

github.com/tensorzero/tensorzero

TensorZero is a Rust, Apache-2.0 project with a deliberately different scope: it is an LLMOps platform that unifies a gateway with observability, evaluation, optimization, and experimentation. The gateway itself deploys as a single Docker container and works with any OpenAI SDK. Note: the tensorzero/tensorzero repository was archived on GitHub in June 2026 and is read-only — the project is no longer maintained.

Language

Rust

License

Apache-2.0

Minimal shape

One container; ClickHouse optional, for observability

GitHub stars

Roughly 11.7k as of August 2026

Pros

  • Single-container gateway; per its docs, ClickHouse is optional and only needed if you enable observability (Postgres is also supported as a backend)
  • Supports 19 named providers plus any OpenAI-compatible API
  • Per its FAQ, the platform is 100% self-hosted and open source, with a paid product (Autopilot) layered on top
  • Choose it when you want the feedback loop — inference data feeding evals and fine-tuning — and not just a proxy

Cons

  • The GitHub repository was archived in June 2026 and is read-only — no further development or security patches
  • Its focus is that loop rather than gateway-side governance such as guardrails or agent-protocol mediation

Higress

github.com/higress-group/higress

Higress is a different animal: a cloud-native API gateway built on Istio and Envoy, originated at Alibaba and now a CNCF sandbox project under Apache-2.0. Its AI gateway capabilities arrive as Wasm plugins on top of a full Kubernetes ingress controller with a console UI.

Language

Go (Envoy/Istio)

License

Apache-2.0

Minimal shape

Docker all-in-one locally; Helm on Kubernetes

GitHub stars

Roughly 9.2k as of August 2026

Pros

  • AI gateway capabilities — unified protocol to mainstream model providers, token rate limiting, caching, AI observability — as Wasm plugins writable in Go, Rust, or JS
  • Can host MCP servers through the same plugin mechanism, including converting OpenAPI specs into MCP servers
  • One Envoy-based data plane governing both classic API traffic and AI traffic
  • Starts locally with one Docker all-in-one container, with Helm for production Kubernetes

Cons

  • More machinery than you need if an LLM gateway is all you are after

What a single-container deployment looks like

Deployment weight is easiest to judge with a concrete example. This is AISIX’s quickstart, verbatim from its README: “One container. No control plane, no database, no configuration store — the gateway reads every dynamic resource from one declarative resources.yaml.”

config.yaml — static gateway settings

# config.yaml
resources_file: /etc/aisix/resources.yaml
proxy:
  addr: "0.0.0.0:3000"
admin:
  enabled: false          # a declarative gateway needs no admin listener
observability:
  metrics:
    prometheus:
      enabled: true
      addr: "0.0.0.0:9090"

resources.yaml — every dynamic resource, declaratively

# resources.yaml
_format_version: "1"

provider_keys:
  - display_name: openai-main
    provider: openai
    api_key: ${OPENAI_API_KEY}        # interpolated from the environment

models:
  - display_name: my-model
    provider: openai
    model_name: gpt-4o-mini
    provider_key: openai-main

api_keys:
  - display_name: local-dev
    key_env: CALLER_API_KEY           # hashed at load; the plaintext is never stored
    allowed_models: ["my-model"]

Run it — one container

export OPENAI_API_KEY="YOUR_PROVIDER_KEY"
export CALLER_API_KEY="YOUR_CALLER_KEY"

docker run -d --name aisix \
  --platform linux/amd64 \
  -v "$(pwd)/config.yaml:/etc/aisix/config.yaml:ro" \
  -v "$(pwd)/resources.yaml:/etc/aisix/resources.yaml:ro" \
  -e OPENAI_API_KEY -e CALLER_API_KEY \
  -p 3000:3000 -p 127.0.0.1:9090:9090 \
  ghcr.io/api7/aisix:latest        # proxy → :3000, metrics + status → :9090
#                                  ^ the metrics/status listener is unauthenticated;
#                                    keep it on loopback or a private network

Then call the gateway exactly like OpenAI

curl http://localhost:3000/v1/chat/completions \
  -H "Authorization: Bearer $CALLER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"my-model","messages":[{"role":"user","content":"hello"}]}'

Edit resources.yaml and send SIGHUP (docker kill -s HUP aisix) to apply changes with no restart — an invalid file is rejected whole and the last good configuration keeps serving. For a multi-replica cluster, the same binary points at etcd instead of a file. Full walkthrough in the gateway quickstart.

How to choose

There is no single winner here — the projects genuinely optimize for different constraints. A reasonable evaluation is an afternoon each with your two shortlisted options: deploy the minimal shape, point one real service at it, kill a provider key mid-stream, and read the logs it produced.

Choose LiteLLM if you…

  • Want the broadest provider coverage on a Python-native stack
  • Want OSS virtual keys, budgets, and spend tracking
  • Are comfortable operating Postgres (and, at scale, its componentized stack)

Choose Bifrost if you…

  • Are a Go shop wanting a fast start with a built-in UI
  • Accept that guardrails and clustering sit in its enterprise tier

Choose Portkey Gateway if you…

  • Target edge/serverless runtimes or want a minimal Node footprint
  • Watch its 2.0 release, which moves enterprise gateway code into open source

Choose Higress if you…

  • Want one Envoy data plane for APIs and AI on Kubernetes

Choose AISIX if you…

  • Need semantic routing by prompt meaning or ensemble judge synthesis in the OSS core
  • Need first-class OpenAI and Anthropic client protocols translated both ways
  • Want keys, limits, guardrails, caching, observability, and MCP/A2A governance all in the Apache-2.0 tier
  • Want one static binary with every dynamic resource in one resources.yaml — no database or control plane

The bottom line

Self-hosting the LLM middle layer keeps credentials, prompts, and availability under your control; the cost is operating one more service, and the patterns for TLS, HA, and upgrades are well-trodden.

AISIX brings dual OpenAI/Anthropic protocols, semantic and ensemble routing, the full OSS guardrail set, and LLM, MCP, and A2A gateway endpoints into one Apache-2.0 static binary — github.com/api7/aisix — and the documentation walks from the quickstart above through guardrails, MCP, and observability setup. For the product overview, see AISIX AI Gateway.

Frequently asked questions

Related comparisons

AISIX vs LiteLLM · LiteLLM alternatives · All AI gateway comparisons

Ready to get started?

For more information about full API lifecycle management, please contact us to Meet with our API Experts.

Contact Us