Infrastructure · Explainer

What an AI gateway is

For operatorsFor developers 7 min read · Updated Jul 2026

On this page
  1. Where a gateway sits
  2. What the layer does
  3. Whose keys pay for the tokens
  4. Things it gets confused with
  5. Why not just use one provider directly?
  6. Common questions
  7. Where Gate fits

The short answer

An AI gateway is a service that sits between your applications and the model providers they call. Instead of every app talking to Anthropic, OpenAI, or Google directly, they all send their requests to the gateway, and the gateway passes them on. Because every request goes through one place, that place is where model choice, spend tracking, retries, and security checks can live.

The change is smaller than it sounds. A request keeps its format and changes its destination.

Where a gateway sits

Every model request is sent to an address. Provider tools default to the provider’s own address and let you change it, and that is the whole mechanism a gateway runs on. Point the address at the gateway, and requests arrive there first and carry on to the provider from there. Cloudflare puts the cost of switching at one line of code.

one request format each provider's own API Chat app Coding agent Internal tool Gateway one base URL Provider A Provider B Self-hosted
one request format Chat Agent Tool Gateway one base URL Prov A Prov B Local each provider's own API
Fig. 1
A gateway is one place every request passes through, which is what makes adding a model configuration rather than another integration.

The request itself doesn’t change. An app still sends a conversation and the name of a model, and still gets back a reply with a token count. What changes is that the traffic now passes through a place you decide the rules for, instead of going straight to whichever provider it was written against.

That’s also what makes the arrangement worth having. Kong describes the effect as client applications staying decoupled from provider-specific APIs, with credentials handled centrally and policy applied at the gateway layer rather than inside every application.

What the layer does

Gateway products differ in the details, and the same handful of jobs shows up across all of them.

One APIOne request format reaches many models, so adding a model is configuration rather than another integration. Kong calls it a single standardized interface across providers.
RoutingRules pick which model or account serves each request: a cheaper model for simple work, or traffic spread across accounts to stay under rate limits.
FallbackRetry somewhere else when a provider times out or fails, and stop sending traffic to whatever is broken until it recovers. LiteLLM pauses a provider that keeps failing and waits longer between attempts; Cloudflare retries and falls back to another model.
CostMeter spend per app, team, person, or key, and reduce it three ways: serve repeats from cache, send easy work to a cheaper model, and compress the prompt so fewer tokens go out for the same result. Gate bundles compression and caching into the layer itself.
AccessOne gateway-issued key per app, person, or agent, scoped and revocable on its own without touching a provider account.
InspectionRead the traffic in flight rather than only relaying it: screen it, redact what shouldn’t leave, add context that has to be there. Kong says its gateway can understand the prompts passing through; Gate screens every request for injection attempts before it reaches the model.

Whose keys pay for the tokens

Feature lists don’t answer the question that changes the most: whose provider account pays for the tokens. Gateways divide into two arrangements, and some support both.

On your keysOn the gateway’s keys
Who bills youEach provider, directlyThe gateway, on one bill
Whose quotas and ratesYours, including anything you negotiatedWhatever the gateway has arranged
Whose agreement governs the dataYour contract with the providerThe gateway’s terms
What you need to startAn account with every provider you useNothing beyond the gateway
Which models you can reachThe ones you hold accounts forWhatever it offers, sign-up included

On your own keys, the credential gets to the provider one of two ways. It can travel with each request, where your app sends its own provider key alongside a separate key identifying it to the gateway, and the gateway forwards the credential without ever holding it. That is also how an existing subscription keeps working, since a tool with its own paid plan carries its own authentication straight through. Or the gateway stores the key once and callers present only a gateway key after that, which is the variant Cloudflare labels BYOK. Some vendors use the term for that variant alone, so it’s worth checking which one a product means.

Neither arrangement is the advanced option. A team with negotiated rates and a signed data agreement has reason to keep its own keys. A team that wants to compare four models this week has reason not to bother. OpenRouter supports both, and so do others.

Things it gets confused with

Three neighbours get described in similar words. A model provider is the thing at the far end: the gateway forwards to it and never runs a model itself, so nothing about what the model can do changes on the way. A client library does some of the same work, but inside one application and in one language, where a gateway is a separate hop whose rules cover everything pointed at it. And an API gateway is the same family and often the same vendors, with Kong’s AI gateway built directly on its API gateway, adding the model-aware parts: token and cost accounting, caching that recognizes similar prompts, and rules that read what a prompt says.

Why not just use one provider directly?

Going direct to one provider is the simplest thing that works, and for a while it comes with more than the model. The lab hands you an operations department along with it: screening you never see, spend limits, a dashboard, a record of what happened. None of that is wrong, and it’s why the direct call feels like enough.

Then you add a second provider and find out how much of it was theirs. The record of what your agents did now lives in two consoles and nothing joins them. The cap you set covers half your traffic. Ask which team spent the money, or what one agent did on Tuesday, and the answer depends on which dashboard you open. Deploy an open model on your own hardware and there’s no dashboard at all. It’s your name on the deployment.

A gateway is where those things live when no single vendor owns them. Costs and records for every model land in one view. Screening and limits apply at the layer, so they cover the model you added last week and the one running on the machine under your desk. Keys are issued per person, per project, per agent, each with its own ceiling and its own trail.

It also changes what picking a model costs you. When a frontier model, a cheap one, and an open-weight one all arrive through the same interface, choosing one per task is a configuration decision rather than a migration, and changing your mind later doesn’t reach into the applications.

And it outlasts the tools. Coding agents and assistants churn every few months. When the rules and the history sit in front of the tool instead of inside it, replacing one costs you nothing.

None of this needs a large team. One person running a coding agent against a private codebase already has a screening problem and a record problem, and neither gets smaller when they switch agents next quarter.

Common questions

What is the difference between an AI gateway and an API gateway?+
Lineage rather than opposition. AI gateways come from the same place and add the model-specific parts: counting tokens and cost, caching by meaning rather than exact match, routing between models, and rules that read the contents of a prompt. Kong’s AI gateway is built directly on its API gateway.
Do I have to change my code to use one?+
Barely. Provider tools let you set the address requests go to, so pointing an app at a gateway is usually a configuration change rather than a rewrite. Cloudflare describes getting started with its gateway as one line of code.
Does a gateway make requests slower?+
It adds a hop, so it adds some latency. In practice that’s small next to the time a model spends generating a reply, and it can go the other way: a cached answer skips the provider entirely and comes back faster than a fresh generation.
Can I keep using my own provider accounts?+
Often, yes, and it has a name: bring your own key. The provider meters the tokens against your account and bills you directly, so your quotas and your provider agreement stay in force. Some gateways work only this way, some only sell usage on their own accounts, and some do either.
What happens when a provider goes down?+
That’s what fallback is for. A gateway can retry the call, move it to another provider or model, and stop sending traffic to whatever is failing until it recovers. Without a layer doing this, the same behavior has to be written into each application.
Can a gateway reduce what I spend?+
It can, three ways: serving repeated requests from cache, routing work to a cheaper model when the expensive one isn’t needed, and compressing prompts so fewer tokens leave. How much any of it is worth depends on your traffic, and the arithmetic is in what a request costs.

Keep learning