On this page
  1. What does an AI gateway do?
  2. When do you need one?
  3. What are the risks?
  4. How do you choose one?
  5. Where AI coding assistants get this wrong
  6. Checklist
  7. FAQ
    1. Is an AI gateway the same as an API gateway?
    2. Does a gateway improve security?
    3. Will a gateway add latency?
    4. Can I self-host one?
  8. Related topics
  9. Sources
concept

What Is an AI Gateway?

An AI gateway centralises provider keys, routing, limits, caching, logging, and fallback. It also concentrates secrets and prompts in one place.

Quick answer

  • An AI gateway sits between application code and model providers, exposing one API while handling keys, routing, retries, rate limits, caching, and logging.
  • Its main benefit is consistency: every service gets the same spend caps, fallback behaviour, and audit trail instead of each team implementing its own.
  • It is not required for a single app calling one provider; an SDK wrapper with the same policies is simpler.
  • A gateway concentrates risk: provider keys, prompt logs, and traffic all pass through it, so it becomes a high-value target and a single point of failure.
  • Most gateways can redact content before logging, but only if you configure it; the default is often to store the full request.

What does an AI gateway do?

It accepts requests in a provider-neutral format and forwards them to a model provider. Along the way it can authenticate the calling service, apply per-tenant rate limits, route to a cheaper model, serve a cached response, retry a transient failure on another provider, and record tokens, latency, and cost.

The value is that these policies live in one place. Without a gateway, each service holds its own provider key and implements its own retry logic, so a spend cap or a model change requires editing every codebase. With one, the policy is a configuration change at the edge of the model traffic.

| Capability          | Gateway                          | SDK wrapper in each app            |
|---------------------|----------------------------------|------------------------------------|
| Key management      | Central, one per provider        | Duplicated per service             |
| Routing / fallback  | Config change                    | Code change in every app           |
| Spend caps          | Enforced centrally               | Per service, easy to miss          |
| Logging             | Uniform, but sensitive           | Inconsistent                       |
| Failure blast radius| Whole platform                   | One service                        |

When do you need one?

When more than one service calls models and you need one place to control spend and provider access. When you route between providers or models for cost, latency, or availability. When compliance requires a uniform audit trail or a redaction step before content is logged. When provider rate limits must be shared fairly across tenants.

A single small application does not need one. An SDK wrapper with a timeout, a retry policy, a token budget, and structured logging provides the same controls with less infrastructure. Adopt a gateway when the coordination cost of doing that in every service exceeds the cost of running one more component.

What are the risks?

Concentration. The gateway holds provider credentials that can spend real money, it sees every prompt, and it sits on the critical path of every AI feature. A compromise or outage affects all of them at once. Protect it like a production database: private networking, strong service authentication, least-privilege keys, and a tested failure mode.

Logging is the second risk. Many gateways can store full prompts and responses for debugging, which creates a store of customer data that did not exist before. Configure redaction and retention before the first request, not after an incident. A gateway that logs everything by default is a data-protection problem disguised as an observability feature.

How do you choose one?

Check the deployment model first: a hosted gateway is quick but sees your prompts, while a self-hosted one keeps content inside your network and adds operational work. Then check provider coverage, fallback semantics, per-tenant limits, redaction, and whether the logs can be exported to your existing observability stack.

Avoid one that requires rewriting every call in a proprietary format. A gateway should be replaceable: if removing it requires changing every service, it has become a dependency rather than an abstraction. Prefer one that speaks an OpenAI-compatible or provider-native protocol so the exit is cheap.

Where this bites vibecoders

Each generated service tends to get its own provider key and its own retry loop, because the assistant only sees one repository. The result is five keys with different scopes and no shared spend cap. A gateway fixes the coordination problem, but the first step is simply to name which services call which providers and who owns the key.

Where AI coding assistants get this wrong

  • Deploying a gateway that logs full prompts by default.
  • Giving the gateway a provider key with more scope than the applications need.
  • Making the gateway a single point of failure with no fallback path.
  • Adopting a proprietary request format that makes removal expensive.
  • Routing to a cheaper model without per-route quality evaluation.
  • Letting every service bypass the gateway with its own key.

Checklist

  • List the services that call model providers and who owns each key.
  • Decide whether an SDK wrapper is sufficient before adding a gateway.
  • Configure redaction and retention before the first request.
  • Scope provider keys to the minimum required.
  • Set per-tenant rate and spend limits.
  • Test the gateway outage path and the fallback provider.

FAQ

Is an AI gateway the same as an API gateway?

They overlap but differ in focus. An API gateway handles general HTTP concerns: authentication, routing, rate limiting, and TLS. An AI gateway adds model-specific concerns: provider abstraction, token accounting, prompt caching, streaming, and fallback between models. Some API gateways now include AI features.

Does a gateway improve security?

It can centralise key management, enforce quotas, and apply redaction, which improves control. It also concentrates sensitive traffic and credentials in one place. The net effect depends on how well the gateway itself is secured; it is a chokepoint, and chokepoints need hardening.

Will a gateway add latency?

Yes, usually a small amount per request, plus the network hop. For streaming responses the added time to first token matters more than total duration. Measure it against the provider’s own variance; a few milliseconds is noise, but a poorly placed gateway across regions is not.

Can I self-host one?

Yes, several open-source gateways exist. Self-hosting keeps prompts inside your network and gives you control over logging, at the cost of running, patching, and scaling another service. For a regulated workload that is often the deciding factor.

Sources

Share: