An LLM gateway is a proxy that speaks one API and talks to many providers. It holds the keys, picks the model, retries when a provider fails, counts what everything cost, and writes it all down. Four or five products do this well, and the question I get asked is which one to buy.
The prior question is whether you need one at all. A gateway is another service on the path of every AI request you serve: its outage is your outage and its latency is your latency. That is a real price, and plenty of teams pay it to solve problems they do not yet have.
I contribute to litellm, including a fix for streaming fallback correctness in its responses bridge, so a provider failing mid-stream degrades instead of dropping the response. That is the sort of detail that decides whether a gateway helps you or quietly hurts you, and it is the lens for this post.
What a gateway actually does
The feature lists across products are close to identical. LiteLLM's proxy describes itself as an OpenAI-compatible server for calling 100+ LLMs with virtual keys, budgets and rate limits, routing, fallbacks, caching, logging, guardrails and spend tracking. Cloudflare's AI Gateway lists caching, spend limits, rate limiting, dynamic routing, guardrails, data loss prevention, bring-your-own-keys, analytics, logging and custom costs. Portkey and OpenRouter cover the same ground with different emphasis.
The differences that matter are operational:
- Where the failover logic lives. LiteLLM's proxy separates plain
fallbacksfromcontext_window_fallbacksandcontent_policy_fallbacks, withnum_retriesbefore falling back andallowed_failspluscooldown_timeto take a broken model out of rotation. It also recordsattempted_fallbacksandoriginal_model_groupin the spend logs, so you can tell later which requests were served by the backup. - Whether failover is provider-level or model-level. OpenRouter load balances across the providers serving a model, "prioritizing price", with
allow_fallbacksdefaulting to true. That answers a different question from "use Claude, and if Anthropic is down use GPT". - What happens to streaming. A fallback halfway through a streamed response is the hard case, and it is where correctness bugs live. Ask for the behaviour in writing, then test it by killing a provider mid-stream.
The three shapes
A library runs inside your process. The LiteLLM Python SDK and the Vercel AI SDK both give you one interface over many providers, retries and fallback logic, and a place to hook cost logging. No extra network hop, nothing new to run, and no third party holding your prompts. What you do not get is a key you can hand to another team and revoke, or a central budget someone else cannot bypass.
A self-hosted gateway is the same features as a service you run. LiteLLM and Portkey both publish open-source gateways under MIT. Portkey's repo claims a sub-millisecond overhead and a 122 KB footprint; LiteLLM's README claims 8 ms at the 95th percentile at 1,000 requests a second. Treat vendor benchmarks as directional and measure your own, but the honest summary is that the proxy hop is small next to a model call.
The cost that gets underestimated is operational. Virtual keys in LiteLLM need a database: the docs are explicit that you "need a postgres database (e.g. Supabase, Neon, etc)", a DATABASE_URL and a master key. So you now run a stateful service on the hot path of every AI feature, with upgrades, backups and someone on call.
A hosted gateway hands that work to a vendor. You get dashboards on day one, and you accept that your prompts pass through someone else's infrastructure and that their availability multiplies into yours, in the way every dependency in series does.
What it costs
Two pricing shapes are in use, and the difference compounds with your spend.
| Product | Shape | Published price |
|---|---|---|
| LiteLLM (self-hosted) | open source, MIT, plus a paid enterprise tier | your own infrastructure; enterprise price not published |
| Portkey Developer | subscription, priced on logs | free, 10,000 logs a month, 3-day log retention |
| Portkey Production | subscription | $49 a month, 100,000 logs, $9 per extra 100,000 |
| Portkey Enterprise | subscription | custom, from 10M logs, VPC deployment, SOC 2 and HIPAA |
| OpenRouter | percentage on credits | 5.5% on card purchases ($0.80 minimum), 5% on crypto; model prices passed through |
| Cloudflare AI Gateway | free core, percentage on unified billing | core features free; 5% on credits bought through Unified Billing |
OpenRouter's bring-your-own-key route is worth knowing: you can use your own provider keys with no fee up to $25,000 of monthly list-price inference, and 5% above that. Cloudflare's log limits are the constraint on the free path: 100,000 logs in total on the Workers free plan, 10 million per gateway on the paid one.
A percentage fee is fine while spend is small and becomes the most expensive line on the page when it is not. A subscription priced on logged requests does the opposite: it barely moves as spend grows, but a high-traffic, low-cost workload can blow through the log allowance.
quick check
Your model spend is $50,000 a month and you are choosing between a gateway with a 5% fee on credits and a $49-a-month subscription tier priced on logs. What is the difference in gateway cost?
5% of $50,000 is $2,500 a month against $49 for the subscription, before any log overage. Both pass through model prices, so the fee is pure overhead; the subscription's cost scales with logged requests instead of spend.
When you do not need one
Most teams asking this question have one provider, one application and one team. For them the answer is no.
- One provider, one app. Provider SDKs plus your own logging beat a gateway. Add a library when you want portability, not a service.
- You want fallbacks and nothing else. A retry with a second provider is twenty lines in your own code, and it fails in ways you can debug from your own stack traces.
- You want cost tracking. Log tokens, cached tokens, model and feature per call and put them in your warehouse. You need that log line anyway, and a gateway's dashboard is not a substitute for your own observability.
- You are pre-launch. A gateway solves coordination problems between teams. If there is one team, there is nothing to coordinate.
The strongest genuine reasons to run one are about people, not models: several teams calling models, someone needing per-team budgets and revocable keys, a central place to enforce guardrails, and one dashboard that finance can be pointed at.
Work out your own answer
Tick what is true today, not what might be true next year.
checklist · what your situation actually needs
Do you need an LLM gateway?
tick what is true today, not what might be true next year
constraints on who runs it
what is pushing the answer
The percentage fee is a rough guide for gateways that resell inference with pass-through billing: OpenRouter charges 5.5% on credit purchases, Cloudflare charges 5% on credits bought through Unified Billing, and both pass model prices through unchanged. Subscription gateways price on logged requests instead. Self-hosted cost assumes a small container and a managed Postgres, which the LiteLLM proxy needs for virtual keys; it does not price your time, which is the larger number.
Five things to check before you commit
- Where the logs live, and for how long. Your prompts are in them. Check retention, region and who at the vendor can read them; Portkey publishes 3-day log retention on its free tier and 30 days on Production, which is also a data-exposure question, not just a debugging one.
- What happens when the gateway is down. Fail open to direct provider calls, or fail closed? Whichever you choose, write the fallback path first and test it by blocking the gateway's hostname.
- Streaming and tool calls through a fallback. The common bug is a provider failing mid-stream and the client getting a truncated or empty response rather than a degraded one. Test it deliberately.
- Whether the cost numbers are yours. Gateways price requests using published rates, which will not match your negotiated rates or your batch discounts. Cloudflare exposes custom costs for exactly this reason. If the dashboard is your source of truth for billing, make sure it is right.
- How you get out. An OpenAI-compatible interface makes leaving easy; proprietary prompt management and stored routing rules do not. Keep the config in your repo.
None of this argues against gateways. It argues for adopting one when the work it does is work you actually have, and for knowing that the cheapest version of that work is often a library and a good log line. If you want to see how I write that layer, some of it is in the open, and the per-feature cost arithmetic it feeds is in LLM cost per user.
questions people ask
What is an LLM gateway?
A proxy between your application and model providers. It exposes one API, holds provider keys, routes requests, retries or falls back when a provider fails, can cache responses, enforces budgets and rate limits, and logs cost per request.
Do I need an LLM gateway?
Only when the work it does is work you have. One provider, one app and one team rarely needs one. Several teams, per-team budgets, revocable keys and central spend attribution are the point at which it earns its place.
LiteLLM or OpenRouter?
They solve different problems. LiteLLM is software you run, self-hosted or as a library, with virtual keys and spend tracking; OpenRouter is a hosted service that resells inference across providers, passing model prices through and charging about 5.5% when you buy credits.
How much does an LLM gateway cost?
Either a percentage of spend or a subscription. OpenRouter charges 5.5% on card credit purchases; Cloudflare charges 5% on credits through Unified Billing; Portkey's Production tier is $49 a month for 100,000 logs. Self-hosting costs infrastructure plus your time.
Does a gateway add latency?
It adds a network hop. Vendors claim overheads from under a millisecond to single-digit milliseconds at high throughput, which is small next to a model call, but it is also one more component that can be slow or down.
Is a self-hosted LLM gateway free?
The software is open source, but running it is not free. The LiteLLM proxy needs a Postgres database for virtual keys and spend tracking, and it becomes a service on the critical path that somebody has to upgrade and be on call for.
The short version
A gateway is the same set of features wherever you put it. The real question is who operates it and what it costs you to have another service on the request path.
With one team and one provider, use the provider SDKs and a library, and spend the effort on a good log line instead. With several teams, keys to revoke and budgets to enforce, a gateway earns its place, and then the choice is money against staff time: a percentage fee is $250 a month on $5,000 of spend and $2,500 on $50,000, while a self-hosted proxy is about $60 of infrastructure plus a Postgres and someone's attention.
Whichever you pick, test the failure path yourself. The value of a gateway is entirely in what it does on the bad day, and the bugs live in streaming, fallbacks and the moment the proxy itself goes down.