AI gateway

Also known as: LLM gateway

On this page 7

An AI gateway is a proxy layer between applications and AI model providers that receives every model request, applies shared policies and forwards the request to the right model. In AI infrastructure, it centralizes routing, authentication, rate limiting, cost tracking, caching, logging and failover for language model and other AI traffic, so that individual applications do not have to implement these functions themselves.

The concept is also called an LLM gateway. It extends the familiar API gateway pattern with features specific to AI workloads, such as token-based accounting, streaming responses, prompt-level guardrails and translation between the request formats of different model providers.

How an AI gateway processes requests

An AI gateway works as a single endpoint that applications call instead of calling model providers directly. Each request passes through a pipeline of middleware steps before and after the model call, and the gateway records the result.

  1. Authentication identifies the calling application, team or user with a gateway-issued key.
  2. Policy checks enforce quotas, budgets, allowed models and input guardrails.
  3. Cache lookup returns a stored response when an identical or sufficiently similar request was answered before.
  4. Routing selects the provider and model, translating the request into that provider’s format.
  5. Response handling streams tokens back, applies output checks and records token counts, latency and cost.

Because all traffic passes one point, the gateway holds the provider credentials, while applications receive only scoped internal keys. This removes secret sprawl and lets a platform team rotate or revoke access centrally.

Core capabilities

AI gateways bundle a recognizable set of capabilities. Not every product offers all of them, but the following table covers the functions that define the category.

CapabilityWhat it doesMain benefit
Unified APIOne request format for many providersSwitching models without code changes
Model routingChooses a model by rules, cost or loadLower cost, better fit per task
Failover and retriesFalls back to another provider on errorsHigher availability
Rate limiting and quotasCaps requests or tokens per keyProtects budgets and shared capacity
CachingReuses exact or semantic matchesLower latency and spend
ObservabilityLogs prompts, tokens, latency, costDebugging and chargeback
GuardrailsFilters inputs and outputsConsistent safety and data protection
Core functions of an AI gateway

Token-based limits are the main difference from a classic API gateway. Two requests can differ in cost by several orders of magnitude depending on prompt and output length, so limits counted only in requests per minute do not protect a budget; limits in tokens per minute or in currency per day do.

Key configuration parameters

Gateway behavior is shaped by a few key settings whose right values depend on traffic patterns and risk tolerance. The ranges below are typical starting points.

SettingTypical valuesConsideration
Request timeout30-120 s, longer for reasoning modelsLong generations need generous limits
Retry attempts1-3 with exponential backoffRetries multiply cost on partial failures
Semantic cache thresholdHigh similarity onlyLoose thresholds return wrong answers
Cache time to liveMinutes to daysFreshness versus hit rate
Log retentionDays to monthsPrompts may contain personal data
Added latency budgetA few to tens of millisecondsGateway must not dominate response time
Typical AI gateway settings

Semantic caching deserves particular care: returning a cached answer for a question that is only similar can be wrong when a single word changes the meaning. Many teams therefore enable exact-match caching broadly and semantic caching only for well-understood, low-risk request types.

An AI gateway sits in front of model providers and inference servers, while related components sit behind it or inside it. Confusing them leads to duplicated functions or gaps.

ComponentPositionPrimary job
AI gatewayBetween applications and modelsPolicy, routing, accounting across providers
API gatewayIn front of general web servicesRequest-based auth and rate limiting
Inference serverBehind the gateway, on GPUsRunning a model efficiently
Model routingA function inside or beside the gatewayPicking the best model per request
Prompt cachingInside the provider or inference serverReusing computed prompt prefixes
AI gateway and neighboring components

Note the difference between gateway response caching and prompt caching: the gateway cache skips the model call entirely, while prompt caching still runs the model but reuses the KV cache of a repeated prefix to reduce cost and latency. The two are complementary.

When to adopt a gateway and common pitfalls

An AI gateway pays off once an organization has several applications, several model providers or shared budgets. A single prototype calling one model rarely needs one, while an organization with dozens of teams almost always benefits.

  • Single point of failure: the gateway must be deployed redundantly, or every AI feature fails with it.
  • Lowest-common-denominator API: unified formats may hide provider-specific features such as tool calling options.
  • Logging sensitive prompts: full prompt logs create a new store of confidential data that needs protection.
  • Silent model swaps: automatic fallback to a weaker model can change quality without anyone noticing.
  • Streaming breakage: buffering in the gateway can turn streamed responses into long waits.

A sound rollout starts with observability and key management, adds budgets and routing once usage data exists, and makes every fallback visible in logs and response metadata so that application teams know which model actually answered.

Explained without jargon

An AI gateway is like the reception desk of a large office building. Visitors do not wander straight to any office; they check in at the desk, which confirms who they are and sends them to the right place. It keeps a log and stops anyone who is not allowed in.

In the same way, every request an app makes to an AI model goes through the gateway first. That lets a company see what AI is being used and how much it costs. It can check that the rules are followed and switch to another model if one stops working.

A typical use case

A mid-size insurance company has a claims summarizer, an internal chat assistant and a document classifier, each built by a different team and each calling models from two providers with its own provider keys. Monthly spending is hard to explain, and an outage at one provider recently stopped the claims tool for several hours.

The platform team introduces an AI gateway. Applications switch to gateway-issued keys, each team receives a monthly token budget, and the gateway routes the classifier to a small, cheap model while the summarizer keeps a large one. When the primary provider fails, requests fall back automatically to a second provider and the fallback is logged. Within the first quarter, finance receives per-team cost reports, and the next provider outage passes with no interruption to the claims tool.