What is an LLM Gateway? A 2026 Engineer's Guide
An LLM gateway is the routing, governance, and observability layer that sits between your application and every LLM provider. Here's what's inside one, why it matters, and how to evaluate them.
Gateway-LLM team · · 9 min read
TL;DR
An LLM gateway is the routing, governance, and observability layer that sits between your application and every LLM provider you call. It exposes a single, stable API surface (almost always OpenAI-compatible), and adds five things you don't get from raw provider SDKs:
- Routing — pick a provider and model per request, by cost, latency, or quality.
- Failover — re-try the next provider when the first one degrades.
- Virtual API keys — issue revocable, rate-limited keys per team without rotating provider credentials.
- Cost & spend tracking — per-request cost, per-team budgets, per-deployment dashboards.
- Observability — Prometheus metrics, OpenTelemetry traces, audit logs.
Think of it as API gateway, but for LLMs — and like an API gateway, you don't notice you needed one until you've shipped to production without it.
Why this category exists
Two years ago, "use an LLM" meant "call OpenAI". Latency was OpenAI's latency, cost was OpenAI's cost, and reliability was OpenAI's reliability. There was nothing to route between.
That world stopped existing roughly when Anthropic shipped Claude 3, Google shipped Gemini 1.5, and Meta open-sourced Llama 3. By 2026 every serious team has at least three providers in play — usually for one of these reasons:
- Cost. Different providers are cheap at different things. Llama 3 70B on Groq is functionally free for short tasks; Anthropic's Haiku undercuts GPT-4o on classification; Gemini Flash is the cheapest long-context model on the market. Pinning everything to GPT-4o leaves money on the table every request.
- Reliability. OpenAI alone has had four 30+ minute outages in the last year. If your product depends on a single provider being up, your reliability is bounded by theirs.
- Capability mix. Some prompts genuinely need a flagship model. Most don't. A single deployment can't serve both well — flagships are too expensive for trivial work, mini-tier models miss the hard prompts.
- Region and compliance. EU customers need their prompts to stay in the EU. Healthcare needs HIPAA-compliant routing. A federation of provider endpoints, each with its own residency and compliance posture, is the only way through.
When you're juggling three providers, two regions, four model tiers, and five teams, you can't put that logic in your application. It belongs at a layer between the app and the providers — and that layer is the gateway.
What's inside an LLM gateway
A modern gateway has four major subsystems. Conceptually:
┌─────────────────────────────────────────────────────────┐
│ Client │
│ (OpenAI SDK / curl / your app) │
└────────────────────────┬────────────────────────────────┘
│ HTTP / SSE
┌────────────────────────▼────────────────────────────────┐
│ LLM Gateway │
│ ┌──────────┐ ┌────────────┐ ┌──────────────┐ │
│ │ Auth │→ │ Rate limit │→ │ Router │ │
│ └──────────┘ └────────────┘ └───────┬──────┘ │
│ │ │
│ ┌─────────────────────────────────────▼──────────┐ │
│ │ Provider translators │ │
│ │ OpenAI │ Anthropic │ Gemini │ Bedrock │ │
│ └────────────────────────┬───────────────────────┘ │
│ │ │
│ ┌──────────────┐ ┌─────────┐ ┌───────────────────┐ │
│ │ Cost engine │ │ Cache │ │ Spend / audit DB │ │
│ └──────────────┘ └─────────┘ └───────────────────┘ │
└─────────────────────────────────────────────────────────┘
│
┌────────┴────────┐
▼ ▼
OpenAI / Anthropic / Gemini / Bedrock / Ollama
1. Auth + virtual keys
The first thing every request hits. The gateway validates a virtual API key — a token your app holds that's distinct from your provider keys. Virtual keys are scoped (which models can they reach?), rate-limited (RPM, TPM), budgeted (USD per month), and revocable. Provider keys stay in the gateway's environment, where leaks are harder.
If you've ever rotated OPENAI_API_KEY at 11 PM because a developer pushed it to a public repo, virtual keys are why you stop doing that.
2. Rate limiting
Per-key counters live in Redis (or in-process for single-instance deployments). The gateway enforces RPM, TPM, and monthly USD budgets in that order, and emits a structured 429 with Retry-After and X-Gateway-Limit-Kind so your client knows what kind of limit it hit.
3. The router
This is the brain. For every request, the router picks one of the deployments registered under the requested model alias. The pick is driven by a strategy:
- Round-robin — even split, weight-able. Fits identical deployments behind one alias.
- Least-latency — picks the deployment with the lowest p50 over the last 60s. Routes around brief degradations automatically.
- Classifier — scores the prompt for complexity in microseconds and routes simple prompts to mini-tier models, complex prompts to flagships. This is what unlocks the 40–70% cost savings teams talk about.
A retry budget wraps the strategy: if the chosen deployment 5xxs, the next one in the alias's list takes the call transparently.
4. Provider translators
LLM provider APIs only look the same from a distance. OpenAI puts system prompts in the messages array; Anthropic puts them at the request level. OpenAI uses tokens; Gemini uses characters and converts internally. Streaming uses SSE everywhere, but the chunk shapes are subtly different.
The gateway hides all of this. Your app only ever speaks the OpenAI Chat Completions / Responses API; the gateway translates inbound to whichever provider it dispatched to, and translates the streamed response back. Switching providers is a config.yaml line, not a code change.
5. Cost engine + spend log
Every request is metered. The gateway maintains a pricing table (gpt-4o: $2.50 / $10 per million in/out, etc.) and computes the USD cost of every call. That number lands in three places: a response header (X-Gateway-Cost-Usd), a Prometheus counter (gatewayllm_cost_usd_total{model,provider}), and a per-request audit log row.
When finance asks "what spent the $40,000 last month?" you can answer in a SQL query, sliced by team, by service, by route. Without a gateway, you can't.
6. Observability
The fourth wall: making everything above visible. Modern gateways emit Prometheus metrics for live RED dashboards, push per-request events to OpenTelemetry / Datadog / Langfuse, and write structured JSON logs you can ship to Splunk or your warehouse. If you can't see it, you can't tune it.
What an LLM gateway isn't
Two persistent confusions worth flattening:
It's not an agent framework. LangChain, LlamaIndex, AutoGen, your own — those orchestrate tool use, memory, retrieval, and chains of LLM calls. They sit above the gateway. The gateway is the network layer those frameworks point at; it doesn't know what a "chain" is and doesn't want to.
It's not a fine-tuning platform. The gateway routes calls to whichever models you've trained or licensed. It doesn't train them. (Most gateways will happily route to your house model behind an OpenAI-compatible endpoint though — see Providers.)
How to evaluate an LLM gateway in 2026
Five things to look at before you commit:
- Latency overhead. Best-in-class is sub-millisecond on routing decisions. Anything over 10 ms is a Python implementation hiding behind marketing copy.
- OpenAI compatibility. Your existing SDKs need to work without code changes. If "compatible" means "we've reimplemented the OpenAI client", that's a red flag — every provider feature lag becomes their problem to backport.
- Self-host first. If the only path is hosted SaaS, your traffic is going through a third-party server. Look for an open-source binary you can run on your VPC. Hosted should be a convenience layer, not a moat.
- Pricing model. Per-token markups are predatory; you're paying twice for the same tokens. Look for percentage-of-savings or flat-rate pricing.
- Real failover, not retries. Many "gateways" will retry the same provider 3 times and call it failover. Real failover means the request seamlessly lands on a different vendor with a different region in under a second.
When you don't need a gateway
If you're a solo developer hitting one provider with one model from one app, skip it. Add a gateway when one of these is true:
- You've got more than one LLM provider in production.
- You've got more than three engineers calling LLMs daily.
- Your monthly LLM bill has crossed roughly $1,000, and finance has started asking about it.
- You've ever asked "should we route this prompt to a cheaper model?" out loud.
The cost of running a gateway is one Docker container and a Postgres + Redis pair. The cost of not running one — once you cross the threshold above — is paying flagship prices on every request and explaining outages you couldn't see coming.
Try it
Gateway-LLM is the open-source LLM gateway we ship. It's a single Go binary, OpenAI-compatible, ~9 µs routing overhead, with smart routing, virtual keys, multi-provider failover, and full Prometheus + OpenTelemetry instrumentation built in. Apache 2.0, no usage caps.
Five-minute Quickstart → /docs/quickstart Architecture deep-dive → /docs/smart-routing Talk to the founders → mitshawtechnologies@gmail.com
Related reading
- How smart routing cuts LLM costs by 40–70% — the worked-example version of section 3.
- LiteLLM vs Gateway-LLM — honest comparison against the most common Python alternative.
- Multi-provider LLM failover — production patterns for cross-provider resilience.
FAQ
What is an LLM gateway?
A server that sits between your application and one or more LLM providers, exposes a unified (typically OpenAI-compatible) API surface, and adds routing, failover, rate limiting, virtual keys, cost tracking, and observability on top.
How is an LLM gateway different from an LLM proxy?
A proxy just forwards. A gateway makes decisions — which provider, which model, which retry, which budget. Most "proxies" sold in 2026 are gateways under the hood.
Do I need an LLM gateway?
Not at first. The break-even is roughly when you're juggling more than one provider or team, or your monthly LLM bill has crossed $1,000.
Is an LLM gateway the same as LangChain or LlamaIndex?
No. Agent frameworks live one layer up; the gateway is the network plumbing they all share.
Run Gateway-LLM in five minutes.
Open-source, OpenAI-compatible, and Apache 2.0. The Quickstart is a single docker compose up.