AI Infrastructure
What Is an AI Gateway?
- Routing
- Policy
- Masking
Short answer
An AI gateway is a service between your applications and AI model providers. Apps send requests to the gateway instead of the provider, and the gateway applies shared controls, such as authentication, routing, rate limits, cost tracking and data masking, before forwarding each call and handling the response on the way back.
What problem does an AI gateway solve?
A company with a dozen services calling AI models usually ends up with a dozen ways of doing it. One team calls OpenAI with a key in an environment variable. Another calls Claude through LangChain. A third added Gemini last month. Each has its own retry logic, its own logging and its own idea of what's safe to send. Nobody can answer "which customer data went to which provider last week?"
An AI gateway puts one service in the middle. Every model call goes through it, so policy, keys and records live in one place instead of twelve.
What does an AI gateway do?
| Function | What it means in practice |
|---|---|
| Routing | Send each request to the right provider and model, sometimes with fallback |
| Key management | Provider API keys live in the gateway, not in every service |
| Rate limits and cost tracking | Cap spend per team or key, see usage by model |
| Caching | Reuse answers to identical requests (some gateways) |
| Observability | Latency, errors and token counts per request |
| Data protection | Mask personal data and secrets before the provider sees them, restore them after |
| Guardrails | Block or flag requests that break policy. See LLM guardrails |
Different gateways weight these differently. Many general-purpose gateways focus on routing, caching and cost. Maskflare's gateway is built around the data-protection row: it's a masking layer first.
How does an AI gateway work in practice?
Most gateways speak the provider's own API, so the only change in your code is the base URL. With Maskflare, it's https://<your-gateway>/v1/<provider>, for example /v1/openai or /v1/anthropic:
import Anthropic from "@anthropic-ai/sdk";
// Point the official SDK at the gateway. Nothing else changes.
const client = new Anthropic({ baseURL: "https://<your-gateway>/v1/anthropic" });
const message = await client.messages.create({
model: "claude-sonnet-4-5",
max_tokens: 512,
messages: [{ role: "user", content: "Summarize the complaint from ada@example.com" }],
});The gateway receives the request, runs detection on the messages, replaces ada@example.com with a token, forwards the call to Anthropic, and, if restoring is switched on for that key, puts the email back into the answer. Provider-specific guides: OpenAI, Anthropic, Gemini.
How is an AI gateway different from an API gateway or an LLM proxy?
| API gateway | AI gateway | LLM proxy | |
|---|---|---|---|
| Main job | Expose and protect your own APIs | Control your calls to AI providers | Relay and inspect LLM traffic |
| Understands prompts and tokens | No | Yes | Usually |
| Handles streaming answers | Passes them through | Inspects them event by event | Depends |
| Who points at it | Your API consumers | Your applications | Apps (reverse) or devices (forward) |
The terms overlap. An AI gateway is a kind of reverse proxy for LLM traffic with policy on top. See what is an LLM proxy for the forward-proxy side.
What about streaming, embeddings and batch jobs?
These are where gateways differ most, so ask specifically. Maskflare handles them like this:
- Streaming: server-sent events are masked event by event, and restored values appear as the answer streams.
- Embeddings: deterministic tokens, so the same value gets the same token and search still works. These requests fail closed.
- OpenAI Batch: uploaded files are masked line by line.
- Realtime and voice: text events are masked. Audio is not.
What should you look for in an AI gateway?
- Provider coverage. Maskflare supports nine: OpenAI, Anthropic, Google Gemini, Mistral, xAI, DeepSeek, Groq, Together AI and self-hosted Ollama.
- Added latency. Maskflare adds about 2 ms median to a 10 KB chat request with default rules (4.3 ms p99), about 10 ms with all 574 detectors.
- What it logs. A gateway sees every prompt. Maskflare never logs or stores prompts or responses; records hold metadata and counts.
- Where it runs. Maskflare is EU-hosted by default, with on-premises deployment for enterprise.
- Restoring. Masking without restoring leaves users reading tokens.
Comparisons: Cloudflare AI Gateway DLP, Portkey PII redaction, and LiteLLM, Portkey and Kong alternatives.
Do you actually need an AI gateway?
Not always. If one service calls one provider and never handles personal data, the provider's SDK and a few lines of logging are fine. A gateway starts paying off when any of these is true: more than one team or service calls AI models, you use more than one provider, prompts can contain customer data or secrets, or someone will eventually ask you to prove what was sent where. For regulated teams in finance, healthcare or the public sector, that last point usually arrives first. A gateway is also the cheapest place to add masking later, because every call already passes through it.
How do you put Maskflare's gateway in front of an app?
- Create a gateway key in the console for the right environment (development, staging or production).
- Pick a compliance profile and run it in shadow mode first.
- Change the base URL in your SDK to
https://<your-gateway>/v1/<provider>. - Switch on restoring for the key if users should see real values.
- Check the audit records, then enforce.
What are the limits of an AI gateway?
A gateway only sees traffic that's sent to it. Employees using ChatGPT in a browser never touch it; for them you need the desktop agent or browser protection. It's another hop in the request path, so its availability matters. It doesn't make answers more accurate; it controls what data goes in and out, and Maskflare's prompt-injection detection screens what comes back from tools and fetched content.
Frequently asked questions
Do I need to change my code to use an AI gateway?
Usually just the base URL. Maskflare works with the official provider SDKs: change the base URL to the gateway route for that provider.
Does an AI gateway add latency?
Some. Maskflare adds about 2 ms median to a 10 KB chat request with default rules, and about 10 ms with all 574 detectors on.
Can an AI gateway work with LangChain or LiteLLM?
Yes. Both let you set a base URL, and Maskflare also ships a LiteLLM guardrail class in the Python package.
Does the gateway store my prompts?
Maskflare doesn't. Prompts and responses are never logged or stored; records hold metadata and counts only.
Is an AI gateway enough to protect employees?
No. It covers applications. Employees in browsers and desktop apps need the desktop agent, browser protection or the forward proxy.