What an AI gateway is, and when to run your own.

An AI gateway is a single endpoint that sits between your applications and the AI models they call. Every model request passes through it, so it is the one place to issue keys, set budgets, apply guardrails and record usage. It is also called an LLM gateway or an LLM proxy.

What an AI gateway does.

When every team calls model APIs directly, there is no single place to see what is being sent, stop what should not be, or cap what is being spent. A gateway gives you that place.

One endpoint for every model

Applications call one OpenAI-compatible URL and ask for a model by alias. Which provider and model sit behind the alias is your decision, and you can change it without touching application code.

Keys you issue and revoke

Each application or team gets its own gateway key. The provider credentials stay in the gateway, so a leaked application key can be revoked without rotating anything upstream.

Budgets and rate limits

Set a spending limit and an expiry on every key, and a request rate on the edge. A runaway loop hits its own limit instead of your whole bill.

Guardrails on every request

Prompts and responses are checked for prompt injection, unsafe content, malicious links and sensitive data in one place, so no application can forget to do it.

Routing, retries and fallbacks

The gateway decides where a request goes, retries a failed call, and can fall back to another model or region when one is unavailable.

A record of usage

Every call is logged with the key, the model, the token counts and the result, which gives you usage and spend per application without reading provider invoices.

AI gateway architecture: how a request moves through one.

The application sends the same request it would send to a model provider, to a different address, with a gateway key in place of the provider key.

IdentifyThe gateway checks the key, and that the key is allowed this model and is within its budget.
InspectGuardrails screen the prompt. A request that fails the check stops here.
RouteThe gateway calls the model with its own credential, retrying or falling back if the call fails.
RecordThe response is screened, usage and cost are recorded against the key, and the answer is returned.

AI gateway vs API gateway.

An API gateway manages HTTP traffic. An AI gateway understands model calls. Most production setups use both: a load balancer or API gateway at the edge, and the AI gateway behind it.

API gatewayAI gateway
What it understandsHTTP requests: paths, methods, headersModel calls: the model, the messages, token counts and cost
What it limitsRequests per secondSpend and tokens per key, as well as request rate
What it inspectsRequest shape, known web attack patternsThe content of prompts and responses
How it routesBy host and path to a backend serviceBy model alias to a provider, with retries and fallbacks
CredentialsPasses the caller's credentials through, or checks themSwaps the caller's gateway key for the provider credential it holds

Hosted or self-hosted.

The main decision is who runs the gateway, because whoever runs it sees every prompt and response. A hosted gateway is quicker to start. A self-hosted gateway keeps the traffic inside your own cloud.

Hosted gatewaySelf-hosted gateway
Where prompts and responses goThrough the vendor's service, then to the model providerThey stay in your own cloud project until they reach the model
Who runs itThe vendorYou, on infrastructure you already manage
Time to first requestMinutesAbout 15 minutes with a ready-made module, longer if you build it
UpgradesHappen when the vendor ships themHappen when you choose, on a version you have pinned
What you payA subscription or a fee per request, on top of model costsYour cloud bill for the resources, on top of model costs
Best fitSmall teams that want no infrastructure and can send prompts to a third partyTeams with sensitive data, a cloud platform already in place, or a need to control change

What to look for in a gateway.

Whichever way you host it, these are the properties that decide whether a gateway makes your AI traffic safer or only adds a hop.

  • An OpenAI-compatible API, so existing SDKs and agent frameworks work by changing a base URL.
  • Guardrails that fail closed: if the check cannot run, the request is refused rather than waved through.
  • A key per application or team, each with its own budget and expiry.
  • Provider credentials held by the gateway, never by the applications.
  • Logs that record usage without storing prompt and response text by default.
  • A version you can pin, so the gateway only changes when you change it.
  • No lock-in: if you remove the gateway, applications point back at the provider with one setting.

Run an open-source AI gateway in your own cloud.

Agent Ping publishes free, open-source Terraform modules that deploy a self-hosted AI gateway into a cloud account you own. No Agent Ping account is needed, and nothing is sent to Agent Ping.

Google Cloud

The open-source LiteLLM gateway on Cloud Run, with Model Armor guardrails and Vertex AI Model Garden models. Released as v0.1.0.

AI gateway for Google Cloud

What you get

One guarded, OpenAI-compatible endpoint, a key and budget per application, a private database, and credentials kept out of Terraform state. An evaluation setup takes about 15 minutes to deploy.

A gateway controls traffic. Observability explains it.

A gateway can tell you which key made a call and what it cost. It cannot tell you which agent run or which customer the call belonged to, or whether the answer was any good.

What the gateway knows

The key, the model, the token counts, the latency and the result of each request, and whether a guardrail blocked it.

What Agent Ping adds

Each call tied to the agent run it was part of, with cost per agent, customer and feature, alerts when an agent goes quiet, and quality scoring. Add an SDK from the integrations to the application that calls the gateway.

Further reading.

What is LiteLLM?

The open-source AI gateway, what the free edition includes, and how to self-host it on Cloud Run.

What is Model Armor?

Google Cloud's guardrail service for prompts and responses: what it checks and what it costs.

LiteLLM guardrails

Screening every request with Model Armor, failing closed, and the gaps to close around it.

Questions.

What is an AI gateway?
An AI gateway is a single endpoint that sits between your applications and the AI models they call. Every model request passes through it, so it is the one place to issue keys, set budgets, apply guardrails, route between models and record usage, instead of building each of those into every application.
Is an LLM gateway the same as an AI gateway?
Yes. "LLM gateway", "AI gateway" and "LLM proxy" are used for the same thing: a service that receives model requests from applications and forwards them to the model provider. "Proxy" tends to be used for the simplest form, which only forwards and translates requests, and "gateway" for one that also enforces keys, budgets and guardrails.
What is the difference between an AI gateway and an API gateway?
An API gateway manages HTTP traffic: it routes by path, checks credentials and limits requests per second. An AI gateway understands model calls: it limits spend and tokens per key, inspects the content of prompts and responses, and routes by model. They work together. In production an AI gateway usually sits behind a load balancer or API gateway that handles TLS and web attack filtering.
Do I need an AI gateway?
You probably do once more than one application or team calls model APIs. The usual signs are provider keys copied into several services, no view of which application is spending what, safety checks implemented differently in each codebase, and no quick way to cut off one caller. A single application with one key can wait.
Is there an open-source AI gateway?
Yes. LiteLLM is a widely used open-source AI gateway, MIT licensed, with an OpenAI-compatible API, virtual keys, budgets and an admin UI. Agent Ping publishes a free Terraform module that deploys it into your own Google Cloud project with guardrails switched on.
Is an AI gateway the same as an AI firewall?
They overlap. "AI firewall" and "LLM firewall" usually mean the guardrail part: screening prompts and responses for attacks and sensitive data. An AI gateway includes that screening and also handles keys, budgets, routing and usage records. A gateway with guardrails switched on does the job of an AI firewall for the traffic that passes through it.
Does an AI gateway add latency?
It adds one network hop, which is small next to the time a model takes to answer. Guardrail checks add the time the check takes, once before the model call and once after. Run it in the same region as your applications and models, and measure with your own traffic before relying on a number.
Can an AI gateway stop prompt injection?
It reduces the risk. A gateway can run a prompt-injection detector on every request and refuse the ones it flags, which is far better than relying on each application to do it. No detector catches every attack, so keep the usual defences in the application too: least-privilege tools and treating model output as untrusted.
What does a self-hosted AI gateway cost?
The software can be free. You pay your cloud provider for what runs. For the Google Cloud module, list-price estimates start at about $10 a month idle for the evaluation profile and about $249 a month for the production profile, before model inference.