Skip to main content
Blog · Guide

AI Gateway vs API Gateway: What Each One Controls

Vishal Vishwakarma11 min read

The API gateway is one of the quieter successes of the last decade of infrastructure. Almost every company that exposes an API runs one at its edge, authenticating callers, routing paths to services and stopping abusive clients before they reach anything that matters. So when model calls began to multiply inside those same companies, the natural first instinct was to send them through the gateway that was already there.

That instinct is reasonable, and it explains why the question of AI gateway vs API gateway comes up so often. The two look alike from a distance: both sit in the request path, both authenticate, both rate-limit. Up close they control different things, because a model call differs from an ordinary API call in what it costs, how it fails, how long it runs and what it carries. This guide sets out what each gateway controls, why API gateways are being extended with AI plugins, and how to decide whether you need one, the other or both.

AI gateway vs API gateway: the short answer

An API gateway governs access to your own services. An AI gateway governs what your applications do with AI models. The table shows where the difference lands.

API gatewayAI gateway
Sits in front ofYour own services and APIsAI model providers, your own keys and cloud model accounts
Unit of limitRequests per periodTokens, cost and requests, per key, project or session
RoutingBy path, host or header to a backend serviceTo a model and provider, chosen by the request or by a policy
On failureRetry the same backend, or return the errorMove to another provider or another model that qualifies
Reads the payloadRarely; the body is usually opaqueYes: prompts, responses and tool results, for checks and records
Security focusAuthentication, authorization, abuse, injection into your APIsUnsafe content, prompt injection, data retention, which model saw what
Cost trackingNot applicablePer request, from token counts and prices
Typical responseMilliseconds, one payloadSeconds to minutes, streamed token by token
RecordsStatus, latency, callerModel, tokens, cost, latency, and the reason a model was chosen

Neither column is better; they describe different jobs. The interesting cases are where one gateway is asked to do the other's job.

What an API gateway controls

An API gateway is the front door to the services you build. A request arrives, the gateway checks who is calling and whether they may, finds the backend that serves the path, applies limits and transformations, and forwards it. Amazon API Gateway describes the same jobs: creating, publishing, monitoring and securing APIs at scale.

Its limits are counted in requests, because for an ordinary API one request is roughly one unit of load and cost. Its retries assume that the same backend may succeed a moment later. Its view of the payload is usually shallow, because the body belongs to the service behind it. Those assumptions are exactly right for the traffic it was designed for.

What an AI gateway controls

An AI gateway sits in front of the models your applications call, which are someone else's services, billed by the token. Its job is to decide what each call may do and to record what it did. In practice that means holding provider keys and cloud accounts in one place, choosing or enforcing the model and provider for each request, moving a failed request to another provider or model, enforcing limits in tokens and money, inspecting prompts and responses, and keeping a record of every call with its cost. The what is an AI gateway guide walks through each of these in order.

Why model traffic breaks API gateway assumptions

Four properties of model calls account for most of the gap.

Cost lives in tokens, and arrives late. Two requests to the same endpoint can differ in cost by a factor of a thousand, depending on the prompt and the length of the answer, and the final count is only known when the answer ends. A limit in requests says little about spend. Even a token limit, counted after the fact, lets concurrent requests overshoot it; Microsoft's token limit policy documentation states that concurrent requests "can temporarily exceed the configured token limit". Enforcing a budget as a true maximum means reserving each request's worst-case cost before it is served.

Failure has more than one remedy. When a provider returns a 429 Too Many Requests or a server error, retrying the same backend is often the slowest choice. The same model may be served by another provider, or a different model may answer the request equally well. Choosing among them requires knowing which models and providers can serve the request at all.

Responses stream for a long time. A model answer arrives token by token over seconds, and an agent turn can run for minutes. Checks on the response either wait for the whole answer or run after it has been sent, and that choice has to be made deliberately per policy.

The payload is the risk. What matters for safety and compliance is inside the body: the prompt, the retrieved documents, the tool results, the answer. Prompt injection arrives in that content, and data retention rules apply to it. A gateway that treats the body as opaque cannot see either.

Can an API gateway become an AI gateway?

Several have tried, with real progress. Azure API Management has a set of AI gateway capabilities, including token limits, semantic caching and content safety; Google's Apigee offers an LLM token quota policy; Kong ships an AI gateway on its API platform. For a team that already runs one of these platforms and has engineers who configure it, extending it can be the shortest path.

The trade-offs follow from the origin. The AI features are policies and plugins on a general-purpose gateway, configured in its own language (policy XML, proxy definitions, plugin entities), so model choice, provider fallback and cost rules are expressed by hand. Token limits are counted after responses, which Azure's documentation notes lets concurrent requests pass them for a moment. And the gateway generally trusts that a provider honors the fields a request sends, which is not always true: we found the same model behaving differently across providers on structured output, logprobs and output caps in our provider parameter report.

One request through both gateways

A concrete case makes the division of labour easier to see. A customer asks a support assistant a question through your public API, and the assistant answers from your documentation with a model call.

  1. The API gateway admits the customer. It checks the customer's token, applies the per-customer request limit on your public API, and routes the path to the support service.
  2. The support service builds the model request. It retrieves the relevant documentation and assembles the prompt, as it would without any gateway.
  3. The AI gateway admits the model call. It authenticates the support service's own gateway key, checks the prompt and the retrieved text for prompt injection, reserves the call's maximum cost against the support team's budget, and picks the model and provider the policy allows.
  4. The model answers through the AI gateway. The answer streams back token by token; if the chosen provider fails, the AI gateway moves the call to the next candidate before the first token reaches the service.
  5. Both gateways record what they saw. The API gateway logs a request from a customer to a path; the AI gateway logs the model, the tokens, the cost, the check verdicts and the reason the model was chosen.

Neither gateway could do the other's job without being taught it: the API gateway has no reason to know what a token costs, and the AI gateway has no business deciding which customers may call your public API.

Adding an AI gateway behind an API gateway you already run

Nothing in front of your services has to change. The AI gateway is called by your services, not by your customers, so it slots in behind the API gateway without touching its routes or its policies.

  • Start from the calls, not the edge. Find where services call model providers directly, and point those clients at the AI gateway's base URL with a gateway key per service.
  • Keep identity separate. Customer identity stays with the API gateway; the AI gateway identifies the calling service, team or agent through its own keys, which is the level at which budgets and model policies make sense.
  • Pass a session or customer reference if you need per-customer limits on model use. Give each customer, or each agent run, its own key or session identifier so its model spend can be capped and attributed.
  • Leave network rules alone. Outbound traffic to model providers now goes to one place, which usually simplifies egress rules rather than adding to them.

Questions to ask before extending your API gateway

If extending the gateway you already run is on the table, a few questions separate a good fit from a slow accumulation of hand-written policy.

  • How is a budget enforced? Ask whether a limit is counted after responses or reserved before them, and what happens when fifty requests arrive in the same second.
  • Who keeps the model list current? Models, prices and provider quirks change weekly. Find out whether the gateway tracks them, or whether a person edits a policy file each time.
  • What happens on a provider failure? Check whether a failed call can move to another provider of the same model, or to a different model, and whether the response says that it did.
  • Can it read a streamed answer? Response checks on streamed output either hold the answer until the check passes or run afterwards; confirm which, per policy.
  • Where do the records go? Per-request cost and the model that actually served belong somewhere finance and engineering can both read, not only in the API gateway's access logs.

If the answers depend on custom code your platform team would write and own, a dedicated AI gateway is usually the cheaper choice over a year, even for a team that already runs a capable API gateway.

Do you need both?

Often, and the two fit together without overlap. The API gateway stays at the edge, in front of the services your customers call. The AI gateway sits behind those services, in front of the models they call. A request from a customer passes the API gateway once; each of the model calls the service makes to answer it passes the AI gateway.

A simple way to decide:

  • Only an API gateway when model calls are few, come from one service, use one provider, and cost is not yet a concern.
  • An AI gateway alongside it when more than one team or provider is involved, when spend needs a hard ceiling, when an outage at one provider must not become an incident, or when you need a record of what was sent to which model.
  • An API gateway extended with AI policies when your organization already standardizes on Kong, Azure API Management or Apigee, and your platform team prefers one system it already operates over a dedicated layer.

Where Inferbase fits

Inferbase is a hosted AI gateway: it sits behind your API gateway, in front of every model your services call. One OpenAI-compatible API reaches managed models, your own provider keys and your own Azure, Bedrock or Vertex accounts; budgets and spend caps are reserved before each request is served; guardrails inspect prompts, responses and tool results; and each route is checked for what it actually supports before a request that needs it is sent there. The AI gateway overview covers each part, and LLM rate limiting and budgets and spend caps go into the limits in detail.

Frequently asked questions

AI gatewayAPI gatewayLLM gatewayrate limitingAI governance

Have thoughts on this article?

We would love to hear your feedback, questions, or experience with these topics. Reach out on social media or drop us a message.

Related Articles

Stay up to date

Get notified when we publish new articles on AI model selection, cost optimization, and infrastructure planning.

Put intelligence in the middle.

Start on the free plan with 5,000 requests a month, no card required.