Explainer

What is an AI gateway? A plain explanation with examples

An AI gateway is one API between your apps and the AI models they call, handling routing, keys, limits, failover and cost. How it works.

An AI gateway is a single API that sits between your applications and the AI models they use. Instead of every app holding its own provider keys and retry logic, every request goes through the gateway, which decides where it goes, checks who's allowed to send it, applies limits, switches providers when one fails and records what it cost.

Updated 2 December 2026.

The problem it solves

AI use inside a company often starts like this. One team calls OpenAI. Another tries Groq. Someone runs an open model on a spare GPU. Keys get shared in chat threads. It works, until:

  • A provider goes down, and every app that depends on it goes down too.
  • One script burns through a shared key and blocks everyone else.
  • Nobody can say who spent what, on which model, with which vendor.
  • Paid APIs get the traffic even when your own hardware could have done the job.

An AI gateway fixes all four by becoming the one front door for AI traffic.

How an AI gateway works

Every request follows the same path:

app  →  AI gateway  →  provider or your own model server
           │
           ├─ checks the key and who it belongs to
           ├─ checks limits and budgets
           ├─ picks a destination (and a backup)
           ├─ forwards the request, streams the answer back
           └─ records tokens and cost

Because most gateways speak the OpenAI API format, apps usually only change two settings to start using one: the base URL and the API key.

What an AI gateway typically does

CapabilityWhat it means in practice
One APIApps call one endpoint, whichever model or provider ends up serving the request
RoutingSend each request to the right model or server, by rules, load or cost
FailoverIf a provider is down or rate-limited, retry on the next one automatically (how it works)
Access controlKeys per app or per person, and a list of models each one may use
Limits and budgetsRequests per minute, tokens per day, dollars per month
Cost trackingSpend per user, team, model and provider in one place (how to track it)
Privacy controlsDecide what, if anything, gets logged
Optional extrasCaching, guardrails on prompts and responses, prompt management

Not every gateway does every row. Some focus on security and guardrails; others on routing and cost.

AI gateway vs API gateway vs LLM gateway

API gatewayAI gatewayLLM gateway
Built forAny HTTP APIAI model trafficLanguage model traffic
Understands tokens and modelsNoYesYes
Typical examplesKong, cloud API gatewaysProducts in this category, sometimes covering agents and toolsSame products, narrower name

In practice, "AI gateway" and "LLM gateway" are used almost interchangeably. Some vendors use "AI gateway" to include agent and tool traffic as well as model calls. A traditional API gateway can be extended for AI with plugins, which is the approach Kong takes. We cover the LLM side, and how a gateway differs from a simple proxy, in what is an LLM gateway.

Hosted or self-hosted

AI gateways come in two shapes:

  • Hosted: you send requests to the vendor's endpoint. Nothing to run, but your prompts pass through a third party. Examples: OpenRouter, Vercel AI Gateway, Cloudflare AI Gateway.
  • Self-hosted: you run the gateway in your own infrastructure. Prompts stay in your network until they reach a provider, or never leave if you serve models on your own GPUs. Examples: LiteLLM, Bifrost, Portkey's open-source gateway, AI Gateway by LayerX.

For a side-by-side list, see best LLM gateways.

Do you need an AI gateway?

Probably not yet if one app calls one provider and one person owns the key.

Probably yes if any of these are true:

  • several apps or teams call AI models
  • you use more than one provider, or your own GPUs as well as vendors
  • you need to know cost per person or per team
  • a provider outage would hurt
  • you have rules about what can be logged or where data can go

Example: AI Gateway by LayerX

AI Gateway is our gateway, built for companies that run models on their own GPUs and also buy tokens from vendors. It puts your vLLM or Ollama servers and providers like OpenAI, Groq, Together and OpenRouter behind one OpenAI-compatible endpoint. Requests go to your GPUs first and move to vendors when needed. Each person gets their own keys, daily and monthly token budgets and a list of allowed models, and the dashboard shows cost per user, key, model and provider. Prompts and responses are never stored. It runs on your servers, or LayerX hosts it.

Questions

What does an AI gateway do?

It routes requests from your apps to AI models through one API, and adds access control, limits, failover and cost tracking on the way.

Is an AI gateway the same as an API gateway?

No. An API gateway manages general HTTP traffic. An AI gateway understands models and tokens, so it can route between providers, enforce token budgets and track AI spend.

What is the difference between an AI gateway and an LLM gateway?

Very little in practice. "LLM gateway" refers to language model traffic specifically; "AI gateway" is sometimes used more broadly to include other model types, agents and tools.

Do AI gateways store prompts?

It depends on the gateway and its settings. Some log requests for debugging, some only when you opt in, and some, like AI Gateway by LayerX, never store prompts or responses.

More posts

Keep reading.

See how AI Gateway fits your setup.

Tell us what you run today and how many people need access. We'll get back to you to learn more about your setup.

See how AI Gateway fits your setup.

What do you run today?