Dev tools
LLM Gateway: Do You Need OpenRouter or LiteLLM?
An LLM gateway puts one API in front of many AI models. Compare OpenRouter vs LiteLLM, see what a gateway adds, what it costs, and when you need one.
An LLM gateway is a single API that sits between your application and the AI model providers you use. Instead of wiring your code separately to OpenAI, Anthropic, Google and open models, you send every request to the gateway, and it forwards each one to the right provider. Along the way it can switch providers when one goes down, track spending, enforce budgets and log every call.
This guide explains what an LLM gateway does, how it differs from a classic API gateway, how the two most popular options compare (OpenRouter, a hosted service, and LiteLLM, an open source gateway you run yourself), and when a gateway is worth adding.
What Is an LLM Gateway?
Without a gateway, every model provider is a separate integration: its own SDK, its own API key, its own request format, its own error codes and its own bill. That's manageable with one provider. With three or four, it turns into a tangle of special cases.
An LLM gateway, also called an AI gateway, gives you one front door:
- Your app sends a request to the gateway, usually in the OpenAI-compatible format most tools already speak.
- The gateway picks the provider and model, based on the model name you asked for and any routing rules.
- It translates the request if needed, sends it, and returns the answer in the same format every time.
- It records what happened: which model, how many tokens, how long it took and what it cost.
Because most gateways mimic the OpenAI API, switching your app to one often means changing just the base URL and API key.
Why Use an LLM Gateway?
One API for every model
Trying a new model becomes a one-line change: swap the model name. That makes it much easier to compare models or move to a cheaper one when it's good enough.
Fallbacks when a provider fails
Every provider has outages, rate limits and slow periods. A gateway can retry automatically and fall back to another provider or model when one fails, so your app keeps working.
Cost tracking and budgets
A gateway sees every request, so it can show spend per app, team, user or feature, and stop requests when a budget runs out. That's often the first thing finance teams ask for once AI usage grows. Our guide to reducing LLM costs shows what to do with that data.
Key management and security
Instead of handing real provider keys to every developer and service, you issue gateway keys with their own limits. If one leaks, you revoke it without rotating your main provider keys.
Logging, caching and routing
Central logs make debugging and quality checks easier. Some gateways also cache repeated requests and route traffic by rules, such as sending simple requests to a cheaper model.
LLM Gateway vs API Gateway
A traditional API gateway, such as the ones offered by cloud providers or Kong, sits in front of your own services. It handles routing, authentication, rate limiting and request logging for ordinary HTTP APIs.
An LLM gateway does similar work, but understands AI traffic specifically:
- It knows the request and response formats of different model providers and can translate between them.
- It counts tokens and cost, not just requests, because AI pricing is per token. See our guide to LLM API pricing.
- It handles streaming responses, which arrive piece by piece.
- It supports model-level fallbacks: "if this model fails, try that model," not just "try another server."
Some API gateway products now include AI features, and some LLM gateways are built on top of general gateway technology. The question is whether the tool understands models, tokens and providers, or only sees generic HTTP calls.
LLM Gateway vs LLM Router and MCP Gateway
Two related terms often get mixed up with gateways.
An LLM router decides which model should handle each request, for example sending easy questions to a small, cheap model and hard ones to a stronger model. Some routers are simple rules; others use a small model to predict which model will answer best. Routing is often a feature inside a gateway, but a router can also be a separate component in your app. The gateway is the front door; the router is the decision about which room to send each visitor to.
An MCP gateway sits in front of MCP servers, the tools and data sources that AI agents call, rather than in front of model providers. It centralises access control and logging for tool calls the way an LLM gateway does for model calls. Larger setups sometimes run both.
OpenRouter: A Hosted LLM Gateway
OpenRouter is a hosted service that gives you one API key and one OpenAI-compatible endpoint for a large catalogue of models from many providers. You buy credits, and each request is charged at the model's price.
How its pricing works, according to its documentation:
- No markup on inference: model prices match the underlying providers' rates.
- A fee on credit purchases: 5.5% with a $0.80 minimum when paying by card, and 5% for crypto.
- Bring your own keys (BYOK): you can use your own provider keys through OpenRouter. On pay-as-you-go, a monthly allowance comes with no BYOK fee, and usage beyond it costs 5% of what the same request would cost on OpenRouter.
It also routes between providers for the same model and falls back automatically to the next provider if one returns an error. Model variants let you prefer the fastest providers (:nitro) or the cheapest (:floor). Privacy settings let you skip providers that log or train on data.
Strengths: nothing to host, instant access to many models, one bill, quick to try new models.
Weaknesses: your prompts pass through a third party, you depend on its uptime, the credit fee adds a few percent to every dollar you spend, and organisation-level controls depend on its plans rather than your own infrastructure.
LiteLLM: An Open Source LLM Gateway
LiteLLM is an open source project with two parts: a Python library that calls many providers through one interface, and a proxy server that its documentation calls the LiteLLM AI Gateway. You run the gateway yourself, on a server or in your own cloud.
According to its documentation, the gateway provides:
- One OpenAI-compatible endpoint in front of more than 100 providers, so existing OpenAI clients work by changing the base URL and key.
- Virtual keys for each user, team or project, each with its own allowed models, budgets and rate limits.
- Spend tracking, recording the cost of each request by key, team, user or tag.
- Load balancing, fallbacks and retries across deployments.
- Logging to observability tools such as Langfuse, Datadog, OpenTelemetry and Prometheus.
Strengths: you keep traffic and logs inside your own infrastructure, there are no per-request gateway fees, and it works with local models too. If you run LLMs locally with tools like Ollama, LiteLLM can put them behind the same API as cloud models.
Weaknesses: you have to deploy, secure, update and monitor it, usually with a database for keys and spend data. It's another service your app depends on. Some enterprise features, such as single sign-on, are part of a paid tier.
OpenRouter vs LiteLLM at a Glance
| OpenRouter | LiteLLM | |
|---|---|---|
| Type | Hosted service | Open source, self-hosted |
| Setup | Sign up, get a key | Deploy the proxy, add provider keys |
| Model access | Its catalogue, one bill | Any provider you have keys for, plus local models |
| Cost model | Provider prices plus a fee on credit purchases | Free software; you pay hosting and your providers |
| Provider keys | Optional (BYOK) | Required: you bring all keys |
| Fallbacks | Automatic between providers | Configurable across models and deployments |
| Budgets and team keys | Account-level controls | Virtual keys with budgets and rate limits |
| Data path | Through OpenRouter | Stays in your infrastructure |
| Best for | Prototypes, small teams, trying many models | Companies with several teams, compliance needs, cost control |
The OpenRouter vs LiteLLM choice usually comes down to one question: do you want someone else to run the gateway, or do you need it inside your own walls?
Other LLM Gateway Options
OpenRouter and LiteLLM aren't the only choices. Others include Portkey and Bifrost (both offer open source gateways), Cloudflare AI Gateway, Vercel AI Gateway, Kong's AI gateway features and Envoy AI Gateway, plus observability tools that add proxy features. Cloud platforms also offer their own AI gateway services for models hosted there. They differ in hosting model, supported providers, caching, guardrails and pricing. Many teams start with one of the two big options and switch only if they hit a specific limit.
How to Point Your App at an LLM Gateway
Because most gateways speak the OpenAI API format, the official OpenAI SDK can talk to them. You change the base URL and the key, and use the gateway's model names:
from openai import OpenAI
client = OpenAI(
base_url="https://openrouter.ai/api/v1", # or your LiteLLM proxy, e.g. http://localhost:4000
api_key="YOUR_GATEWAY_KEY",
)
response = client.chat.completions.create(
model="provider/model-name", # the model ID as listed by your gateway
messages=[{"role": "user", "content": "Summarise this ticket in one sentence."}],
)
print(response.choices[0].message.content)OpenRouter model IDs include the provider, in the form provider/model-name. With LiteLLM, you define model names in its configuration and map each one to a provider and key.
Do You Need an LLM Gateway?
You probably don't need one yet if:
- You use a single provider and a couple of models.
- You have one app and one team.
- Your provider's own dashboard covers cost tracking well enough.
You probably do if:
- You call two or more providers, or want to switch models easily.
- Outages or rate limits have already hurt your users.
- Several teams or customers share AI usage and you need budgets per team.
- You need central logs for debugging, quality checks or compliance.
A sensible path: start direct with one provider, move to a hosted gateway like OpenRouter when you want many models quickly, and adopt a self-hosted open source gateway like LiteLLM when cost control, data handling or team management become priorities.
Risks and Trade-offs
- Extra hop: every request passes through one more service, adding a little latency.
- Single point of failure: if the gateway goes down, all your AI features do. Run it with redundancy or keep a direct fallback.
- Feature lag: new provider features may take time to appear in a gateway's unified format. Check that the features you rely on, such as tool calling, structured outputs or prompt caching, pass through correctly.
- Data handling: with a hosted gateway, prompts and responses pass through another company. Review its data policies, or self-host.
FAQ
What is an LLM gateway?
An LLM gateway is a service that gives your application one API for many AI model providers. It forwards each request to the right model, and usually adds fallbacks when a provider fails, cost tracking, budgets, key management and logging.
What is the difference between OpenRouter and LiteLLM?
OpenRouter is a hosted service: you get one key and access to many models, paying model prices plus a fee when you buy credits. LiteLLM is open source software you run yourself: you bring your own provider keys and get virtual keys, budgets, fallbacks and logging inside your own infrastructure.
Is an AI gateway the same as an API gateway?
Not quite. A regular API gateway handles routing, authentication and rate limits for any web API. An AI gateway adds model-specific features: translating between provider formats, counting tokens and cost, handling streaming and falling back between models.
Does an LLM gateway add latency?
A little, because each request passes through one more service. For most applications, that's small compared with the time the model takes to generate an answer, and features like fallbacks and caching can improve overall reliability and speed.
Is LiteLLM free?
The core LiteLLM library and gateway are open source and free to use. You pay for the servers you run it on and for your model providers. Some enterprise features are offered as a paid tier.