An AI gateway is a control layer that sits between AI consumers and the models, tools, and services those consumers call. Applications, coding agents, copilots, and pipelines send their requests to the gateway. The gateway decides whether each request is allowed, which upstream should handle it, how the call is counted, and what gets recorded, before anything reaches a model or a tool.
That role is easy to understate because the first generation of AI products looked like ordinary HTTP clients. An app posted a prompt to a vendor API and it simply responded with the completion. Production usage is no longer that simple. A single user action can fan out into retries, tool calls, retrieval steps, and several model providers. Cost is measured in tokens rather than requests. The payload is language, images, and tool arguments, which means the security problem is in the actual request content and not in the request metadata.
If you only want the short version, the request path looks like this:
- A client sends a request to the gateway instead of to a model provider.
- The gateway authenticates the caller and inspects the input.
- Policy and routing pick a model, a provider, or a tool path.
- The request is translated into the upstream's format and executed.
- The response is checked against output policy before it is returned.
- Tokens, cost, latency, and the decision trail are logged.
The rest of this article unpacks why teams add a gateway, how the pieces fit together, what the category actually of AI gateways does, and where it differs from API gateways, LLM gateways, and MCP gateways.
Why Do You Need an AI Gateway?
Calling a provider API directly, such as OpenAI or Anthropic, works when one team uses one vendor from one application. However, this starts to fail as soon as the organization has several of those teams, several of those providers, and callers.
Use Multiple AI Providers From One Endpoint
A typical engineering org now has coding agents in IDEs, an internal support bot that answers tickets, a retrieval pipeline that embeds documents, and a handful of product features that call a language model at runtime. Some of those callers talk to a hosted API. Others talk to a model running on a GPU box in a lab or a rack. Each integration tends to grow its own keys, retry logic, logging, and cost spreadsheet.
The gateway exists so that work happens once. All of these different callers can use a single, common endpoint for their requests. The gateway then decides which model, provider, or tool to use for each request, and how to handle the request and response.
Track and Control AI Token Spend
A request to a traditional API-based microservice has a fairly stable cost. A request to a model does not. Input length, output length, model choice, and how many times an agent retries all change the final cost passed down to the caller. Multi-step agents and harnesses make this problem even worse because one user prompt can become dozens of model calls and a chain of tool invocations, each of which can have a different cost.
Without a place that sees every call, finance teams ask where the spend went and engineering cannot easily answer in by looking in one place for a cohesive report. Token rate limits and budgets should be enforced at the same level of infrastructure that handles the model routing, knows who the caller is, and has the token counts.
Secure Prompts and Prevent Data Leakage
Every AI request to a model that leaves the perimeter can carry source code, customer records, or internal documents inside a prompt. Every response can also carry unsafe content, leaked secrets, or an instruction the caller should not follow. Agents not only generate text, they invoke tools that read data and take actions.
Ordinary API security checks standards like schema, headers, network, etc. It doesn't read a prompt for a policy violation, redaction, or injection attempt. That inspection has to happen on the path between the caller and the model provider at a central control point like an AI gateway.
Fail Over Across Model Providers
If an application hard-codes a single provider, that provider's outage will take down the application. Model APIs also throttle, change versions, and return differently shaped errors. Ideally, the application should be able to failover to another model, another region, or a self-hosted replica. Those decisions happen in the AI gateway so it's centralized and not re-implemented in every client.
Detect Shadow AI and Keep an Audit Trail
There are a lot of AI products people want to use: coding agents, chat apps, copilots inside SaaS, and new tools landing every week. Teams often adopt them on their own because waiting on a sanctioned option is slow. That traffic still carries company data, source code, tickets, customer records, and central IT and security have no way to see which tools are in play, what left the building, or how to put a policy in front of it. An AI gateway is how you let people use those tools on a path you can actually control, with an inventory and an audit trail instead of a spreadsheet of mystery vendors.
How Does an AI Gateway Work?
The gateway sits in the middle of the caller and the model provider on the request path. Clients never need to know which vendor or which GPU served a particular call, and upstreams never need to know which product feature originated it.
AI Gateway Request Flow
1. Request initiation. An AI application, coding agent, harness, or any other AI-based product sends a request to a single gateway endpoint URL that you own. The client usually speaks a familiar API shape, most often an OpenAI-compatible chat completion, an Anthropic messages call, or a provider-native format the gateway has advertised.
2. Authentication and input inspection. Before the payload is forwarded, the gateway establishes who is calling and whether the call is allowed. It can also inspect the content: policy labels, prompt-injection patterns, schema checks, and redaction of fields that should not leave the environment.
3. Governance and routing. The gateway chooses an upstream from the set the caller is permitted to use. Routing can consider identity-based access control, model capability, price, latency, remaining budget, provider health, and data-residency rules.
4. Provider execution. The gateway rewrites the request into the upstream's wire format, attaches the appropriate upstream credential that's stored in the gateway (such as your OpenAI API key or Anthropic API key), and issues the call. Streaming responses are passed through. Errors are normalized so clients see one failure model rather than a different one per vendor.
5. Output validation. The response is checked before it returns to the caller. That can mean content filters, schema enforcement for structured outputs, or blocking a tool result that would violate policy. Failed checks are dropped, rewritten, or sent down a fallback path.
6. Logging and attribution. The gateway records tokens, cost, latency, which caller triggered the work, which model served it, and which guardrails fired. Those records feed live dashboards and the audit trail that compliance teams actually need.
What an AI Gateway Does
The category is defined by a set of jobs that keep showing up together. Individual products emphasize different ones, but a gateway that only routes and a gateway that only logs are both incomplete for production use.
A unified API surface
Callers want one base URL and one request shape, even when the organization uses several model vendors and a self-hosted engine. This way they don't have to know which vendor is serving the request. The gateway maps that canonical API onto each upstream, including auth, streaming, tool-call encoding, and error translation. Swapping a model, or adding a second provider, becomes simply adding a new upstream to the gateway configuration.
Model management and orchestration
Beyond a static mapping of name to endpoint, gateways select among models at request time. They version deployments, shift traffic during rollouts, and pin some workloads to a specific snapshot. They also handle the unglamorous work: timeouts, retries with backoff, and fallback to a secondary model when the primary is unhealthy or over budget.
Cost, rate, and quota controls
Because pricing is token-based, the gateway has to count tokens and estimated cost per caller, team, application, and model. Budgets can stop a runaway agent before the invoice does. Rate limits can be applied per key, per identity, or per model so you don't have an unexpected bill for a rogue application or user.
Caching belongs here too. Exact-match caches skip duplicate completions. Semantic caches, where they are used, reuse a previous answer for a question that means the same thing in different words. Both exist to cut spend and latency, and both have to respect freshness and tenancy.
Authentication and policy
The gateway is the enforcement point for who may call which model, with which tools, under which conditions. That can mean API credentials, identity from an existing SSO identity provider, network constraints, or a mix. Policy can go further than simply allow-or-deny. It can redact fields, force a model that stays in-region, or refuse tool invocations that would write to production systems.
Prompt and output inspection
Content-aware checks are what separate this layer from a generic reverse proxy. On the way in, the gateway can look for secrets, personal data, and prompt-injection attempts. On the way out, it can apply safety filters and require structured responses to match a schema. These checks will never be perfect, but they are the first place a shared rule can run for every client.
Observability
Because every call passes through one hop, the gateway can emit a single stream of traces, metrics, and logs. Useful dimensions include model, provider, caller, tool name, token counts, cost, cache hit, and guardrail verdict. You can see full sessions including the prompt and output for each request. Many implementations also export to OpenTelemetry so the AI traffic shows up next to the rest of the application's traces.
AI Gateway vs API Gateway
An AI gateway is a more specialized version of an API gateway. It's designed for the specific needs of AI traffic, such as streaming, token-based pricing, and content-level policy.
| API Gateway | AI Gateway | |
|---|---|---|
| Designed for | Deterministic, stateless services | Non-deterministic model, agent, and tool traffic |
| Connection model | Short request and response cycles | Long-lived streams, often SSE or chunked tokens |
| Pricing model | Per request or per compute unit | Per token, varying with input, output, and model |
| Routing logic | Path, header, and service discovery | Capability, cost, latency, health, and residency |
| Security model | Transport and schema: auth, TLS, payload shape, IP rules | Content as well as transport: prompts, outputs, tool arguments |
| Observability | Request count, latency, error rate | Tokens, cost, model quality, cache hits, guardrail verdicts |
| Failure handling | Retries and circuit breakers to the same service | Cross-provider failover and model-aware fallback chains |
Many environments still run both. The API gateway remains the front door for ordinary microservices. The AI gateway is the front door for model and agent traffic.
AI Gateway vs LLM Gateway
An LLM gateway sits in front of language-model APIs. It normalizes formats, routes across vendors, retries, caches, and tracks tokens. That is enough if the product sends a prompt and shows a completion.
An AI gateway still does that, and it also covers the rest of the run: tools, retrieval, agent steps, and policy for the whole sequence, not one completion.
AI Gateway vs MCP Gateway
An MCP gateway handles tool access for MCP servers. It decides which agent can call which MCP server and logs what ran. It centralizes the tools in the same way an LLM gateway centralizes model calls.
It does not pick model providers, cap spend on the completions that triggered the tool, or inspect the model output. An AI gateway covers model routing, tool access, and policy across a multi-step agent run all in one place.
Deployment Models
Where the gateway runs changes latency, residency, and who operates it. The common shapes:
Managed. A vendor hosts the data plane, or at least the control plane, and you point clients at their endpoint. This is the fastest way to get routing, keys, and dashboards, at the cost of sending prompts through that operator unless you add extra encryption or a private path.
Self-hosted. You run the gateway in your own cluster, VPC, or on-prem environment. Prompts can stay on networks you already trust. You take on uptime, upgrades, and scaling.
Common AI Gateway Use Cases
Team-wide model access. Platform teams publish one endpoint for coding agents, notebooks, and internal chat. Developers pick a model by name. Keys for upstream vendors stay in the gateway.
Code agents. A coding agent that needs to call a model, a tool, or a self-hosted engine. The gateway is where you can enforce policies on how much your engineering team can spend on AI and what data they can and cannot pass to a model.
Production agents. A customer-facing or internal agent that plans, retrieves, and calls tools needs failover, output checks, tool permissions, and a session-level budget. Doing that inside the agent framework does not scale past the first agent.
Mixed cloud and self-hosted models. A lab cluster runs an open-weight model for private code or documents. Product features still call a hosted frontier model. Callers should not have to know which network the GPU lives on.
Support and retrieval assistants. A ticket bot might call a language model for the reply, a retrieval service for runbooks, and a classifier for urgency. The gateway is where those hops are authenticated, timed, and logged as one operation.
Compliance-bound inference. Healthcare, finance, and similar environments need redaction before a prompt leaves a zone, and a record of every call afterwards. The gateway is the enforcement point for both.
Limitations and Tradeoffs
A gateway is infrastructure on the request path. It is not a model, and it is not a substitute for application-level authorization inside the tools an agent calls.
It only governs traffic that actually goes through it. If developers can still point a client at a vendor API, or if a model server is reachable on the open network, the gateway becomes optional.
Inspection adds latency and will never catch every bad prompt or bad output. The useful comparison is against uninspected direct calls, not against a perfect oracle. Most of the added time is still small next to model inference, but streaming, tool loops, and poorly placed extra hops can make a careless deployment feel slow.
Semantic caches can serve a stale or cross-tenant answer if they are designed carelessly. Fallbacks can silently send a workload to a weaker or cheaper model. Both are powerful, and both need explicit policy.
Finally, the category is still settling. "AI gateway," "LLM gateway," and "MCP gateway" are used interchangeably. When you evaluate a product, ask which jobs on this page it actually performs, rather than trusting the label.
Final Thoughts
An AI gateway is the control point for traffic that talks to models, tools, and agents. It exists because that traffic is streamed, token-priced, content-sensitive, and increasingly autonomous, which is a poor match for the basic API gateway-style proxies organizations already run in front of their microservices.
The useful mental model is a front door with opinions: one API for callers, policy and routing in the middle, and a record of what happened. LLM gateways cover the model calls and MCP gateways cover the tool calls. An AI gateway is typically a combination of both.
FAQ
What is an AI gateway?
An AI gateway is a control layer between applications, agents, and AI workloads on one side and models and tools on the other. It authenticates callers, inspects prompts and outputs, routes work, tracks cost, and records an audit trail
How is an AI gateway different from an API gateway?
An API gateway is built for deterministic HTTP services. An AI gateway is built for streaming, token-priced, non-deterministic traffic, with content-level policy, model-aware routing, and cost attribution that ordinary API gateways do not provide.
Do you need an AI gateway if you only use one model provider?
Often yes. A single provider still leaves you without a shared place for input inspection, output checks, spend caps, caller attribution, and failover onto a backup model or a self-hosted replica. If you ever want to swap out a model provider, you'll need to rewrite every client that calls it. If you use an AI gateway, you can add a new upstream and change the routing rules.
Does an AI gateway add latency?
It adds a hop and whatever inspection you enable. On a well-placed data plane those checks are usually small compared with model inference completion time. Poor placement, extra network distance, or heavy guardrail checks can make the hop noticeable, which is why the data plane belongs near the traffic.
How does an AI gateway relate to agents and MCP?
Agents call models and they call tools. MCP is a protocol for the tool side. An MCP gateway governs tool access. An AI gateway can cover model calls for prompt and responses, tool calls, and the policy that applies to the whole agent run, rather than only one of those slices.
Pangolin is an open-source Secure Access Service Edge (SASE) platform built on WireGuard® that unifies modern networking and security for teams connecting to apps, infrastructure, and AI workloads. Designed as an open, self-hostable alternative to complex legacy suites, Pangolin brings together a zero-trust VPN, zero-trust reverse proxy, privileged access management, and an identity-aware AI gateway under a single identity and policy model. Whether deployed on-premises using a lightweight user-space connector or managed via Pangolin Cloud, it gives organizations transparent, auditable, and frictionless control over their entire digital footprint.
Keep reading
- How We Built A Highly Available Reverse Proxy
How We Built A Highly Available Reverse ProxyHow we turned Pangolin from a single-box reverse proxy into a stateless, horizontally-scalable cluster.
Engineering - Why Virtual API Keys Are a Bad Fit for LiteLLM and Bifrost Deployments
Why Virtual API Keys Are a Bad Fit for LiteLLM and Bifrost DeploymentsVirtual API keys solve model routing and budgeting well, but they were never built to be an identity system. Here's where that gap shows up in self-hosted LiteLLM and Bifrost deployments, and what to do instead.
Engineering - What Are MCP Tunnels? Secure Private MCP Servers Explained
What Are MCP Tunnels? Secure Private MCP Servers ExplainedLearn what MCP tunnels are, how they connect AI agents to private Model Context Protocol servers over outbound-only connections, and why they matter for enterprise security.
Engineering