LLM Gateways: What They Do and How to Choose One
What an LLM gateway does, when you need one and how to choose: authentication, routing, budgets, caching, logging and policy, with a vendor-neutral scorecard.
Topics:AI platform engineering
Illustrative scenario: three months after a company's first AI pilot, five teams are calling model providers directly. Each holds its own API key, none of them share a budget, and the month-end bill arrives as a single number that nobody can break down by team or by feature. The security team asks which models see customer data, and the honest answer is "we would have to read five codebases". An LLM gateway is the layer that turns that situation into one place to look.
TL;DR
An LLM gateway is a service that every model call passes through. It handles identity, routing, budgets and rate limits, caching, logging and policy in one place, so applications do not each rebuild them. You need one when several teams or products call models and you must control cost, access or data handling centrally. Choose by measuring the overhead it adds, how it behaves when it fails and what it stores, not by feature count.
What a gateway is
Without a gateway, each application talks to a model provider with its own client library and its own key. With one, applications talk to the gateway using a common interface, and the gateway talks to providers. The application does not need to know which model or provider served the request.
Step 1: Authenticate
Identify the calling team, service or agent, and check what it is allowed to use
Step 2: Apply policy
Enforce allowed models, redact sensitive data and check limits before anything leaves
Step 3: Route
Choose the model or provider, with fallbacks if one is unavailable
Step 4: Cache
Return a stored answer for a repeated request when policy allows
Step 5: Call and stream
Forward to the provider and stream the response back
Step 6: Record
Log tokens, cost, latency and outcome against the caller
The pattern is covered in the LLM gateways and routing chapter and in the model router pattern. For where it sits in the whole stack, see the Enterprise AI Engineering Blueprint.
What a gateway should do
Not every gateway does everything, and you may not need every job on day one. These are the responsibilities worth knowing, with what good and bad look like.
Identity and access
Good: Each team or agent has its own identity, scoped to the models it may use
Red flag: One shared key that every service uses
Routing and fallback
Good: Requests can be sent to different models, with a fallback when a provider fails
Red flag: A provider outage takes every product down
Budgets and rate limits
Good: Per-team budgets, alerts and hard stops
Red flag: The first sign of overspend is the monthly invoice
Caching
Good: Repeated requests can be answered without a model call, scoped by tenant
Red flag: A shared cache that could leak one user's answer to another
Logging and tracing
Good: Every call recorded with caller, model, tokens, cost and latency
Red flag: No way to say who spent what, or reconstruct a bad answer
Policy
Good: Allowed models per data class, redaction and limits enforced centrally
Red flag: Policy exists only in a document, not at the call
Do you need one yet?
A gateway is infrastructure to run, so adding it too early is a cost of its own.
If
One team, one product, one provider
Choose
Not yet, but keep provider calls behind one internal function
Because
The overhead outweighs the benefit, and a thin wrapper keeps your options open
If
Several teams or products calling models
Choose
Yes, start now
Because
Central budgets, identity and logging become valuable quickly
If
Sensitive data or regulated workloads
Choose
Yes, with policy enforcement
Because
You need one place to control which models see which data
If
A spend you cannot attribute
Choose
Yes
Because
Per-caller metering answers who is spending what
If
Heavy dependence on a single provider's outages
Choose
Yes, for routing and fallback
Because
A second route reduces the blast radius
The cost blowup challenge starts from a bill that rose far faster than traffic, and finding the cause depends on knowing where the spend came from. Even a very small gateway that only records caller, model and tokens gives you that attribution.
Build or buy
Gateways come as open-source software you run, managed services and features inside larger platforms. This post does not rank products, because the right choice depends on your constraints and any product list goes stale quickly. Decide the approach first.
Build and run your own
- Fits unusual policy or integration needs exactly
- You own latency, upgrades, security and on-call
- Easy to underestimate the long tail: streaming, tool calling, retries, provider changes
- Reasonable when the need is small and well defined
Adopt an existing gateway
- Faster to start and keeps pace with provider changes
- You depend on its roadmap, pricing and data handling
- Check what it stores and where it runs
- Reasonable when you need breadth, not a bespoke design
A vendor-neutral selection scorecard
Whichever route you take, evaluate the candidates against the same criteria. Run these against your own traffic where you can, because published numbers describe someone else's workload.
Latency overhead
Good: You measured the added time on your own requests, including streaming
Red flag: Only a vendor claim, or never measured
Failure behaviour
Good: You know whether it fails open or closed and have tested it
Red flag: Behaviour during an outage is unknown
Streaming and tool calling
Good: Streaming and tool-call responses pass through correctly
Red flag: Works in a demo but breaks structured or streamed output
Provider coverage
Good: The providers and models you use are supported and kept current
Red flag: New models take weeks to appear
Observability export
Good: Traces and metrics go to your existing tools
Red flag: Logs live only in the gateway's own console
Data handling
Good: You know exactly what it stores, for how long and where
Red flag: Prompts and responses are retained by default and unnoticed
Policy as code
Good: Rules are versioned, testable and reviewable
Red flag: Rules are edited by hand in a UI with no history
Exit cost
Good: You could move away without rewriting every application
Red flag: Applications depend on gateway-specific features
A minimal configuration, as an illustration
A gateway's configuration is where policy becomes real. This is an illustrative shape, not any product's schema.
routes:
- name: support-assistant
callers: ["team:support-eng"]
allowed_models: ["model-small", "model-large"]
data_class: internal
redact: ["email", "phone"]
budget:
monthly_usd: 3000
alert_at_percent: 80
hard_stop: true
fallback: ["model-large", "model-small"]
log: { prompts: false, metadata: true }Note the last line. Logging full prompts is useful for debugging and risky for privacy, so make it a deliberate choice per route, with retention you can defend.
How a gateway fails, and how to design for it
- It becomes a single point of failure. Everything depends on it, so run it redundantly, test failure behaviour and decide per route whether to fail open (allow calls through) or closed (block them).
- It adds latency. Measure it, especially for streaming, where time to first token matters.
- It breaks features. Streaming, tool calling and structured outputs vary between providers, so test the ones you rely on.
- It stores sensitive data. Prompts and responses may be retained. Decide what is logged and for how long.
- It can be bypassed. If code can still call a provider directly, the controls are optional. Remove direct provider keys from applications so the gateway is the only route.
Rolling one out without a big bang
Step 1
Put one low-risk service behind the gateway in logging-only mode and compare results with direct calls
Step 2
Turn on identity and budgets for that service, then add a second team
Step 3
Enforce policy and routing, remove direct provider keys from applications, and test a failure drill
Step 4
Make the gateway the default for every new AI feature, with a short onboarding guide
Cost levers such as caching and routing to cheaper models come after you can see where the money goes. How to reduce LLM costs covers them, and the AI Cost Calculator lets you model the effect with your own numbers.
Frequently asked questions
What is an LLM gateway? A service that every model call passes through. It handles authentication, routing and fallbacks, budgets and rate limits, caching, logging and policy in one place, so each application does not rebuild them.
Do I need an LLM gateway? You probably do once several teams or products call models and you need central control of cost, access or data handling. With one team and one provider, a thin internal wrapper around provider calls is usually enough until that changes.
What is the difference between an LLM gateway and a model router? Routing is one job a gateway can do: choosing which model serves a request. A gateway also covers identity, budgets, caching, logging and policy. A router can exist inside a gateway or on its own.
Should I build or buy a gateway? Build when your needs are unusual and small, and you can own latency, upgrades and on-call. Adopt an existing one when you need breadth and speed, but check its data handling, roadmap and exit cost first.
Does a gateway slow my application down? It adds a hop, so it adds some latency. How much depends on the gateway and your setup, so measure it on your own requests, including time to first token for streaming, rather than relying on a published number.
What happens if the gateway goes down? Everything that depends on it is affected unless you planned for it. Run it redundantly, test failure behaviour, and decide per route whether it should fail open or closed.
Does a gateway store my prompts? It may. Check what is logged, for how long and where, and make prompt logging a deliberate per-route choice with a retention period you can defend.
Related
AI platform engineering
Your next step
Reading is the start. Turn it into skill: read the chapter, practise on something real, check the numbers, then follow a path.
More on AI platform engineering
- What an AI Platform Engineer Actually OwnsWhat an AI platform team builds and runs: gateway, serving, evaluation pipelines, observability, cost and security, and where product teams take over.
- API or Local Models: Where the Cost Break-Even SitsWhen does running a model yourself beat paying for an API? A total-cost framework, an illustrative break-even calculation and the non-cost factors that decide.
- LLM Observability: What to Trace and WhyWhat to trace and log in a production LLM app: prompts, retrieved context, tool calls, tokens, cost and latency, with sampling, privacy and alerting guidance.
Discuss this article
Got a question, a counter-example or a correction? Bring it to the community.
Prefer a feed reader? Follow by RSS.