AI Guides · 10 min read

What Is an LLM Gateway? Routing, Auth, and Failover Explained

An LLM gateway sits between your app and model APIs to handle auth, routing, rate limits, logging, and failover. What it does, and what it cannot replace.

A dark editorial still life of a single junction box sitting between a row of incoming cables and several outgoing paths, with no text or logos

An LLM gateway is a proxy or middleware layer that sits between your application and one or more model providers. Instead of scattering provider keys, rate checks, and logging across every service you run, the gateway authenticates incoming calls, picks an upstream route, applies governance policies, translates formats if needed, and records usage.

What is an LLM gateway?

An LLM gateway, sometimes called an AI gateway, is a network proxy or middleware layer placed between application code and one or more model APIs. Across official documentation from LangSmith and Cloudflare checked on November 30, 2026, an LLM gateway handles six recurring jobs:

  • Authenticating and authorizing the calling application or service
  • Selecting an upstream route, provider, or model, including fallback candidates when configured
  • Applying pre-request governance policies for spend, rate limits, model access, and sometimes data protection
  • Translating requests and responses between different provider API formats when required
  • Forwarding the request upstream and returning or streaming the model response
  • Recording usage, cost, routing metadata, policy outcomes, and traces or logs

There is no single industry specification defining what an LLM gateway must include. Vendor platforms emphasize different parts of that pipeline, though they share the same basic proxy pattern: your application sends requests to one gateway endpoint instead of calling each upstream provider directly.

On the credential side, gateways decouple what your application holds from what the upstream model provider sees. Your application authenticates to the gateway using a gateway or workspace token. The gateway then attaches an upstream credential at runtime, either from keys stored with the gateway (often called bring your own key, or BYOK), from prepaid gateway credits managed by the platform, or from a provider key passed through in the request headers.

What happens to a request inside an LLM gateway?

A request entering an LLM gateway moves through a staged pipeline of authentication, policy evaluation, routing, optional format translation, and logging before and after it reaches an upstream model.

Standard request lifecycle in LangSmith LLM Gateway

LangSmith documents an eight-step flow for its standard LLM Gateway endpoint, which is officially noted as being in beta as of November 30, 2026:

  1. Caller authentication and authorization: The gateway validates the LangSmith API key and checks for the gateway:invoke permission.
  2. Route resolution: Using the target endpoint and model ID, the gateway resolves the upstream route along with any configured fallback candidates.
  3. Credential loading: The gateway retrieves the upstream credential, such as a workspace provider key or a Gateway Credits credential.
  4. Pre-request policy evaluation: Spend limits, rate limits, and model access rules can block the request before any provider sees it. When data protection policies are configured, they inspect the request body and redact sensitive content.
  5. Request translation: When the chosen upstream provider expects a different API format than the one the client sent, the gateway translates the payload.
  6. Upstream execution: The gateway sends the request to the provider and receives or streams back the response.
  7. Response translation and placeholder restoration: The gateway translates the provider’s response back into the API format the client requested and restores redaction placeholders where applicable.
  8. Response return and tracing: The caller receives the response while the gateway logs usage, cost, routing and policy metadata, and the LangSmith trace.

LangSmith also documents a direct model access mode that skips steps 5 and 7. Direct model access passes requests and responses through in the provider’s native format while keeping caller authentication, credential resolution, policy evaluation, and tracing active.

Deployment topology affects where those steps execute. LangSmith lists three availability options: LangSmith Cloud in every LangSmith region (noting that API keys from one region do not work on another region’s gateway), Bring your own cloud (BYOC), where the gateway runs inside your VPC so model requests and traces stay inside your data plane, and self-hosted LangSmith.

Authentication and rate limits in Cloudflare AI Gateway

Cloudflare AI Gateway illustrates how caller authentication, key storage, and rate limits interact at the proxy layer. According to Cloudflare’s documentation as of November 30, 2026, routing requests through the gateway provides unified logging, analytics, caching, rate limiting, and security controls, with three provider authentication models: Unified Billing (prepaid AI Gateway credits for Workers AI and supported third-party providers), BYOK / Store Keys (storing your provider API keys with Cloudflare for runtime injection), or passing your provider API key in request headers.

Newly created Cloudflare AI Gateways require authentication by default. Existing gateways created with authentication turned off can keep it disabled or turn it on, though once authentication is turned on, it cannot be turned off again. Requiring authentication stops unauthorized access and prevents invalid requests from inflating log storage usage.

Header handling depends on which endpoint style your application calls:

  • REST API (api.cloudflare.com): Cloudflare recommends this path for new integrations and expects a Cloudflare API token in the standard Authorization header.
  • Provider-native endpoints (gateway.ai.cloudflare.com): These endpoints expect the token in the cf-aig-authorization header instead.

Cloudflare also documents an important authorization boundary in its token model: AI Gateway API tokens are account-scoped. Permissions such as AI Gateway Read, AI Gateway Run, and AI Gateway Edit cannot be restricted to a single gateway inside an account. Any token granted AI Gateway Run can send requests through every gateway in that account, including gateways configured with stored provider keys through BYOK, consuming those upstream credentials. For isolation between gateways or tenants, Cloudflare advises using separate Cloudflare accounts or a Worker-side AI Gateway binding rather than relying on token scope.

For traffic control, Cloudflare AI Gateway lets you define a maximum number of requests within a time frame (its documentation uses 100 requests per 60 seconds as an example) using either a fixed window or a sliding window. Requests over the limit receive HTTP 429 and are not processed.

The choice between fixed and sliding windows changes how bursts behave near window boundaries. Under a limit of 10 requests per 10 minutes starting at 12:00:

  • Fixed window (12:00 to 12:10, 12:10 to 12:20): Ten requests at 12:09 and ten more at 12:11 all succeed, because each batch lands in a separate 10-minute interval.
  • Sliding window: Those requests at 12:11 fail, because more than 10 requests occurred within the preceding 10 minutes.

Gateway rate limits sit in front of the quotas enforced by upstream model vendors, which operate independently on the provider side. For more on how vendor-side throttling works, see our guide on AI API rate limits explained.

Documented gateway mechanisms side by side

Mechanism area LangSmith LLM Gateway (beta) Cloudflare AI Gateway
Caller authentication LangSmith API key with gateway:invoke permission check Required on new gateways; Authorization on REST API or cf-aig-authorization on native endpoints
Upstream credentials Workspace provider keys, Gateway Credits, or both BYOK stored keys, Unified Billing prepaid credits (Workers AI and supported providers), or request headers
Format translation Translates on standard endpoint; skipped on direct model access Routes through REST API or provider-native gateway endpoints
Pre-request controls Spend, rate, model access limits, and body redaction policies Fixed or sliding window rate limits returning HTTP 429; authentication to block invalid log traffic
Routing and failover Resolves route from endpoint and model ID, with configured fallback candidates Routes configured providers behind the gateway with unified logging, caching, and analytics
Deployment and isolation Cloud (region-locked keys), BYOC in your VPC, or self-hosted Account-scoped tokens; separate accounts or Worker bindings needed for per-gateway isolation

How is an LLM gateway different from model routing?

Model routing and an LLM gateway often operate in the same request path, yet they describe two distinct layers of functionality.

Model routing is the decision rule that determines which model or tier should handle a given request. A routing rule might direct short classification prompts to a smaller, faster model and reserve larger models for multi-step reasoning, or fall back to an alternate model when an upstream endpoint fails.

An LLM gateway is the proxy layer sitting in front of model providers. A gateway frequently performs routing as one step in its pipeline, such as when LangSmith resolves a route from a model ID and checks fallback candidates. Alongside routing, the gateway handles caller authentication, upstream key injection, spend and rate enforcement, schema translation, and logging.

You can implement model routing inside application code without a gateway by calling separate provider SDKs conditionally. Conversely, you can place an LLM gateway in front of a single fixed model purely to centralize keys, enforce rate limits, and capture traces.

What can an LLM gateway not guarantee?

An LLM gateway enforces controls at the proxy boundary, which leaves several security, compliance, and output-quality guarantees outside its scope.

First, a gateway cannot by itself prove the identity of a downstream model or guarantee data residency. A gateway can steer traffic to a regional endpoint or run inside your own network, as LangSmith BYOC does when keeping model requests and traces inside your VPC. Even so, sending traffic through a gateway does not prove that an upstream provider served the exact model you expect or kept inference inside a legal boundary. Proving model identity or data residency requires separate technical or contractual controls.

Second, a gateway cannot replace application-level authorization for your own users. Gateways check whether the calling service holds a valid key and gateway permission, such as gateway:invoke or AI Gateway Run. They do not know which end user inside your application is allowed to read a specific customer record or include private data in a prompt. Your application backend still has to enforce user and tenant permissions before calling the gateway.

Third, pre-request redaction policies are not guaranteed to catch every secret. When a gateway inspects request bodies to mask sensitive fields and later restores placeholders in the response, secrets in unexpected formats can still pass through unredacted.

Fourth, a gateway does not prevent an upstream model from hallucinating, and it does not automatically lower your API bill. Proxying traffic through a gateway only reduces spend if you configure features such as caching or routing to lower-cost models, alongside broader tactics covered in our guide on how to reduce AI API costs.

Fifth, gateway rate limits do not eliminate upstream provider limits. A gateway can reject excess calls from your services with HTTP 429 before they leave your perimeter, yet the model provider still enforces its own separate quotas on every request that reaches its API.

When do you actually need a gateway?

Engineering teams gain practical value from an LLM gateway when managing provider credentials, API schemas, and usage logs inside individual application services starts creating operational friction. Several concrete conditions point toward adding a gateway layer:

  • Multiple providers or frequent model swaps: When your services call more than one vendor or rely on configured fallback candidates, format translation and centralized route resolution reduce integration churn across application codebases.
  • Centralized credential and spend control: When multiple internal apps or teams share upstream provider access, storing keys in one gateway or using prepaid gateway credits lets you manage caller access and enforce spend, rate, or model access limits in one place.
  • Unified observability and policy auditing: Gateways capture usage, cost, routing metadata, policy outcomes, and traces across callers in a consistent pipeline.
  • Protecting log pipelines and edge capacity: Enforcing caller authentication and rate limits at the proxy blocks unauthorized traffic before it reaches upstream providers or inflates log storage.

If a single service calls one model provider with straightforward key management and existing application logging, calling the provider’s SDK directly avoids maintaining another network hop and another token-scoping boundary.

FAQ

Does an LLM gateway make AI API calls cheaper?

An LLM gateway does not make API calls cheaper by default. Adding a proxy layer only reduces your bill if you configure cost-saving features inside it, such as response caching for repeated prompts or routing simpler tasks to lower-priced models. Spend limits and rate caps also help prevent unexpected usage spikes from bugs or unauthorized callers.

What is the difference between gateway rate limits and provider rate limits?

Gateway rate limits are rules you configure on the proxy to cap how many requests your callers can send over a fixed or sliding window, returning HTTP 429 before traffic goes upstream. Provider rate limits are separate quotas enforced by the model vendor across your account, regardless of how your gateway is configured.

Can an LLM gateway replace provider API keys inside my application?

Yes, an LLM gateway can keep upstream provider keys out of your application code. Services authenticate to the gateway using a gateway or workspace token, and the gateway injects stored BYOK provider keys or applies prepaid gateway credits at runtime. Your team still needs to manage scoping and isolation for those gateway tokens carefully.

What happens when an LLM gateway skips API format translation?

When a gateway skips format translation, as in LangSmith’s direct model access mode, requests and responses remain in the upstream provider’s native format. The gateway still handles caller authentication, upstream credential loading, pre-request policy checks, and trace logging, while passing payloads through without converting between different vendor schemas.

Does using an LLM gateway guarantee my data stays in a specific region?

No, routing traffic through a gateway does not guarantee data residency by itself. Hosting a gateway in your own VPC, such as LangSmith BYOC, keeps gateway requests and traces inside your data plane, yet an external model provider’s processing location still depends on that provider’s own endpoints and contractual controls.

Sources

Written by

Chunyu Cai

Chunyu Cai is the CEO of Lotook, LLC and an entrepreneur who writes about AI models, agents, and how they change everyday work. Chunyu holds a master's degree from Imperial College London.