An API gateway is the single entry point that routes, authenticates, rate limits, and logs traffic to the backend services behind it. An LLM gateway does those same jobs in front of AI model providers, then adds a layer the API gateway does not have: it understands the model traffic itself. It reads tokens and context, routes each request to the right model, falls back to another provider when one fails, caches repeated prompts, and keeps a budget guard on inference cost.

You need an API gateway when you operate a service architecture and you want one place to protect and control access to those services. You need an LLM gateway when your application calls language models through several providers and you care about which model answers each request, what it costs, and what happens when a provider degrades. Most teams that build AI features into a real product end up running both, layered.

The pattern extends beyond these two names. An AI gateway is the broader label for the same model aware layer, and an MCP gateway handles a separate job about what the model may do next. Keep the two you asked about in view and read the table before anything else.

The comparison table

Capability API gateway LLM / AI gateway
Primary job Route and protect service traffic Route and govern model calls
Authentication Yes (JWT, OAuth, API keys) Yes, plus per key and per team scopes
Rate limiting By request, IP, user, or key By token, by request, and by spend budget
Routing Between backend services Between models and providers
Model awareness None Core (tokens, context, capabilities)
Provider failover Not its job Core feature
Prompt and response caching Exact match at best Exact and semantic
Cost tracking Coarse or absent Per call, per team, per model
Streaming responses Buffers poorly Streaming native (SSE, WebSocket)
Content security Not content aware Prompt injection and PII controls

That table is the whole argument. The rest of the guide explains both columns, walks a request through the two gateways, and helps you decide what your stack needs.

What an API gateway does

An API gateway is a software layer that presents one entry point for clients to reach many backend services. IBM states the definition plainly and calls the gateway a standard component of microservice architectures. Instead of each client talking to each service directly, every request passes through the gateway, which applies policy, hands the call to the right service, and sends the answer back. If you already run a microservice platform, you almost certainly have one of these in place, whether you think of it by that name or not.

Five jobs dominate what an API gateway does in practice.

Routing and load balancing

The gateway directs each request to the correct backend service based on headers, paths, or request content. It balances load across the instances of a service so a single instance does not become the bottleneck. It also makes versioning work without breaking clients: you can run two versions of an API side by side and move traffic between them, and the client keeps calling the same door.

Authentication and authorization

The gateway is the natural place to enforce security at the edge. It validates JSON web tokens, OAuth flows, and API keys, and it can centralize role based access control so the policy lives in one place instead of inside every service. A client presents one credential at the entrance, and the gateway decides which services that credential may reach.

Rate limiting and throttling

Gateways protect services from abuse and from overload. They apply configurable limits per user, per IP, or per API key, which both stops denial of service traffic and keeps quality of service predictable for everyone else. The throttle counts requests over a window. That is the whole model, and it is a good model for ordinary API traffic.

Protocol translation

Different services speak different protocols. The gateway translates between them, so a client that speaks one style can reach a backend that speaks another. It turns a representational state transfer (REST) call into gRPC, or lets a legacy SOAP service answer a modern request. This is the layer that lets old and new systems talk without rewriting the old ones.

Observability and logging

Because every request passes through the gateway, the gateway becomes the natural source of metrics, logs, and traces. It feeds that data to your monitoring stack. When something breaks, the logs point at which service, at what time, and with which request. Kong, Amazon API Gateway, and NGINX define this category, and their shape sets the expectation for what a gateway looks like.

None of these five jobs requires the gateway to understand what a request means. That is by design, and it is exactly the property that fails when the traffic becomes a model call.

Where an API gateway stops

Conventional API gateways were built for a specific traffic shape, and that shape is the bottleneck for AI workloads. They treat HTTP traffic as opaque data to route. That design works well for request and response services, and poorly for anything that needs the gateway to understand the payload.

An API gateway counts requests. It does not count tokens. It cannot tell you how many tokens a call consumed or what that call will bill you. It buffers streaming responses badly, because a model streams an answer token by token over the course of a minute or more, and the gateway was built to shuttle a complete response from one service to another. It caches exact matches at best, and it has no view of model capabilities, inference cost, or the meaning of the prompt moving through it.

Kong is blunt about the same thing: traditional gateways cannot track tokens, cannot manage streaming responses, cannot enforce content level security, and cannot use semantic caching. Those limits are not a bug in any single product. They are the consequence of a design that treats every request as identical to every other. When the traffic is a language model call, those gaps stop being edge cases and become the central problem.

What an LLM or AI gateway adds

An LLM gateway is a middleware layer that sits between your application and the model providers. It performs the gateway jobs of authentication, rate limiting, and logging, then adds an understanding of model traffic that a conventional gateway does not have.

OpenRouter states the difference the cleanest way: an API gateway handles authentication, rate limiting, load balancing, and SSL termination, and it has no understanding of tokens, model capabilities, or inference cost. Put one in front of a model provider and you get HTTP level controls, which are useful but not model aware. An LLM gateway understands that a request carries a token count tied to a price, that providers differ in what they support, and that the right provider for a request depends on a mix of performance, cost, and health signals.

Here is what that understanding buys you.

Model awareness and routing

Where an API gateway routes between services, an LLM gateway routes between models and providers. It picks the model that should answer each request against that model's capabilities, its price, and its current state. It can send a coding request to one provider and a summarization request to another, or shift a workload to a smaller model that still clears the quality bar. Because the gateway normalizes the provider APIs behind one interface, changing the model becomes a configuration change instead of a rewrite of the integration. Switching providers no longer means reworking your application code, which is the practical definition of escaping vendor lock in.

Provider fallback and resilience

When the primary provider fails, rate limits you, or degrades, the LLM gateway reroutes the request to another provider automatically. Your application stops surfacing a 503 to the user just because one vendor is having a rough stretch. Fallback chains can list several models across several providers in a defined order, and a straight swap keeps the request flowing. A good gateway is also honest about one boundary: if a stream has already started sending tokens and then fails mid response, the application still has to handle the partial output. Transparent failover works cleanly when the failure precedes the stream, and that boundary is worth knowing.

Token and context handling

A model call has a cost and a context that scale with the number of tokens. The gateway sees that count, tracks it in real time against a budget, and applies limits at that level. It understands context growth, which matters for the long conversations and chained calls where token counts climb quickly. This is the layer that can stop a runaway agent from draining a budget in a single session, because the guard lives in the request path rather than in a review done after the fact.

Prompt and response caching

Repeated prompts cost money and latency every time they reach a provider. An LLM gateway caches them. Exact match caching returns the stored answer for a repeat request without calling the provider at all. Semantic caching understands that two differently worded questions mean roughly the same thing and serves the same result. Both cut cost and latency on the traffic that repeats, which is common with routine and template driven prompts. The distinction matters for how you evaluate a gateway, because exact match and semantic caching are not the same feature.

Cost controls and attribution

Inference spend tends to stay opaque until the invoice arrives. The gateway makes it legible in real time, with a per request breakdown of what each call cost. It can set per key or per team caps, fire alerts before a cost escalates, and attribute spend to the team or project that generated it. Moving from finding out after the fact to having a guard inside the request path is the difference between reporting a surprise and preventing one.

Content aware security

Model traffic carries sensitive payloads, and those payloads leave your boundary for an external API. The gateway can inspect the prompt going in and the response coming out, mask personally identifiable information before it is sent, and apply policy from a single control plane. It is a natural enforcement point for prompt injection and unsafe output, threats that are specific to model based systems. A perimeter based API gateway is not built to see them.

Streaming as the normal case

Models stream their answers. The gateway has to hold an open connection and pass tokens through in real time, using server sent events (SSE) or WebSockets, without buffering the whole response before sending anything. That is how a chat interface stays responsive while a long answer builds over a minute. A conventional gateway treats that as an awkward, long request. An LLM gateway treats it as the everyday case, because every serious consumer of a language model streams its responses.

Walking a single request through both gateways

Layering is easier to picture with one concrete request. A user opens your application and asks a question that reaches the AI feature.

The request lands at the API gateway first. The API gateway checks the caller's credential, confirms they may reach this route, applies the request level rate limit for that user or key, and forwards the call into your backend. If this were an ordinary service call, the gateway would route it to a service, wait for the response, and hand it back.

This request is a model call, so the backend forwards it to the LLM gateway. The LLM gateway reads the message, counts the tokens, and checks the budget for the team that owns this feature. It chooses the model that should answer, from across the providers you have wired in, and decides whether the answer can come from cache. If the first provider is down or rate limited, it sends the call to the fallback instead of failing. It masks any personal data it is configured to hide, then opens a stream back to the user as tokens arrive. When the call finishes, it records the token count and cost to the team's ledger.

Both gateways did their job and neither could have done the other's. The API gateway could not have chosen the model or counted the tokens, and the LLM gateway did not enforce access to the rest of your system. This is the shape of a production AI architecture.

Do the names matter: LLM gateway vs AI gateway

The terms overlap, so it helps to set them straight once. An LLM gateway is the specialized case that focuses on language models. An AI gateway is the broader label that covers other kinds of models too, including multimodal traffic and the systems built around them. IBM describes the AI gateway as a specialized API gateway for AI models: it extends the standard gateway with multi model access, intelligent workload routing, dynamic load balancing, token consumption tracking and rate limiting, security policy, and cost management. For this guide the two share one set of concepts, which is why the headings use both.

There is a third layer worth naming so you do not confuse it with either of these. A Model Context Protocol (MCP) gateway sits closest to the agent and controls which tools a model can reach while it runs, where the LLM gateway routes requests to providers. Teams building with MCP servers often run all three, with the API gateway on the outside protecting the wider service traffic.

When you need only an API gateway

You need an API gateway when the traffic you are protecting is service traffic, and AI is a small part of the building.

You run a microservice backend, you want one entry point for clients, and you want authentication, rate limiting, and logging handled in one place instead of repeated in every service. None of that changes because AI exists in the stack. If your application makes a handful of calls to a single model through a single provider, with no routing, no fallback, and no team level budget, you can pass those calls through the same gateway and call it done.

The signal that an API gateway is all you need is precise. One provider, one or two models, no failover, and nobody asking which team consumed what inference budget. The moment any of those conditions breaks, the API gateway stops being enough.

When you need an LLM gateway

You need an LLM gateway the moment your model usage stops being a footnote. OpenRouter gives the threshold: use the direct API if you call one model from one provider and have no plans to change that. You are already building gateway infrastructure the day you add a second provider, failover logic, or team level cost controls, whether you call it that or not.

Concretely, an LLM gateway earns its place when the price or the health of your models has to be managed rather than assumed. When you route across providers to get the right tradeoff of cost and quality, when an outage at one provider has to be invisible to your users, when you need to swap a model without rewriting the integration, when you must know what every team spends on inference, or when the prompt payloads contain data you have to mask before they leave your boundary, an LLM gateway is the layer built for that job.

Adding one does not mean removing the API gateway. The LLM gateway typically sits in front of the providers and behind the API gateway, and it handles only the model calls.

When you need both

For a production AI system, the normal answer is both, in layers, because the two own different traffic.

The API gateway protects your service traffic. It is the perimeter that decides who can reach your backend at all and handles the bulk of ordinary application calls. The LLM gateway owns the model calls, which are a distinct and expensive traffic type with their own failure and cost characteristics. Composio lays this out as separate layers in one request path: the API gateway controls service traffic, the LLM gateway controls which model gets called, and the MCP gateway controls which tools the model may use next.

Layering works because each gateway has a job the other does not. Your API gateway has no way to count the tokens in a model response or to route a request to a model that costs less yet still fits the job. Your LLM gateway has no business terminating general service traffic or managing the full API surface of your application. Give each gateway the job its layer was built for, and the boundary between them stays clean.

There is a practical reason the layered answer is orderly. As AI features grow from an endpoint to a family of routes, you want the model aware logic concentrated in one place so the application code stays stable while the routing policy evolves. That concentration makes a provider switch a configuration task instead of a sprint through the codebase.

Self-hosted and managed, and what the vendor choice changes

Gateways come in two delivery shapes, and the shape changes your tradeoff table even though the concepts stay the same.

A self-hosted gateway runs inside your infrastructure, in your language and against your network. You control the data retention, the deployment, and the policy, and you carry the operational burden of keeping it up to date and available. This is the route teams take when a compliance requirement about where prompts may live rules out a hosted service, or when the infrastructure team prefers to own the whole path.

A managed gateway runs on a provider's platform. You get the model catalog, the failover, and the dashboards without running the layer yourself, and you trade that for a third party holding the traffic path.

Neither shape changes which gateway you need. Both offer model routing, fallback, caching, and cost controls; the decision is about custody of the traffic, not whether the layer exists. State that before you evaluate vendors, because the two questions get conflated constantly.

A quick decision framework

Answer three questions in order and the right call follows.

First, what does the traffic look like? Ordinary service traffic needs the API gateway. Model calls need the LLM gateway. Both kinds flowing through the building means you run both.

Second, how many models and providers do you depend on? One provider with one model and no failover needs no LLM gateway. Add a second provider, any failover, or a budget someone must defend, and the LLM gateway does work you would otherwise hand code into the application, where it becomes harder to change.

Third, who has to answer for the spend? If nobody asks which team consumed what inference budget this month, the cost controls are a reasonable extra. The day finance asks, the LLM gateway stops being optional, because no amount of post hoc invoicing tells you which team burned the budget before the invoice arrived.

When in doubt, put the API gateway in front of your service architecture, because it is nearly always warranted, and add the LLM gateway when the model traffic gets heavy enough to need routing, fallback, caching, and budgets. Then bolt the two together in layers and keep the boundaries explicit.

Common mistakes worth avoiding

Three errors come up more than any others, and they map to the three questions above.

The first is buying an AI gateway because it sounds modern, when the real problem is that your service architecture never had a proper API gateway to begin with. Fix the perimeter first. Model level controls do not substitute for service level access control, and adding an LLM gateway on top of an unmanaged service layer just moves the chaos one hop further out.

The second is skipping the API gateway because an AI gateway can also terminate traffic. The reverse direction is the common one. Teams consolidate everything on the AI gateway and then wonder why they no longer have a clean answer to who accessed which service and how often. Keep the service traffic on the layer built for it.

The third is leaving caching and cost controls to last. Routing gets the attention because it is visible and interesting, but the budget guard is what the finance team notices first and the cache is what shaves latency off your most repeated calls. Sequence the rollout so the decision layer, the failover, the budget guard, and the cache all ship, not just the routing headline.

The verdict

The two gateways are not rivals and they do not replace each other. An API gateway answers a question about your services: who can reach them, how fast, and through what single door. An LLM gateway answers a question about your model calls: which model handles this request, what does it cost, and what happens when the first choice is down.

Small AI footprints survive with an API gateway alone. Real AI products, the ones with multiple models, provider failover, and spend that has to be defended, add an LLM gateway in front of the providers, layered behind the API gateway. Start with the question of what the traffic is, size the layer to the traffic you actually have, and add the second gateway when the first stops answering the cost and reliability questions your model traffic raises.

For the foundation, start with what an LLM gateway is, then look at the two levers that make the model aware layer earn its place: LLM routing and how prompt caching and routing work together. If you are comparing gateway providers for the layer you decided on, the OpenRouter alternatives breakdown is the next step.

Route every model call through one gateway

Route, cache, and govern AI traffic from one OpenAI-compatible platform.

Start Free → See Features