
Summarize this article using AI
Every team that ships AI to real customers hits the same wall. One provider has an outage, another changes pricing, a customer demands a different model, and API keys end up scattered across repositories. An AI gateway is the standard answer: put one layer in front of every model and manage the chaos in one place.
This guide explains what LiteLLM and AI gateways do, how the main options compare, and how to run one safely, including what the 2026 LiteLLM security incident teaches about trusting the layer that holds all your keys.
What Is LiteLLM and What Is an AI Gateway?
An AI gateway is a service that sits between applications and large language model providers, exposing a single unified API while handling authentication, routing, retries, cost tracking and logging. LiteLLM is an open-source project, maintained by BerriAI, that provides this as a Python SDK and as a proxy server, using the OpenAI request format to reach many model providers.
The terms AI gateway and LLM gateway are used interchangeably. "LLM router" usually means the narrower job of choosing which model handles each request.
In practice, your application sends one standard request and the gateway translates it to whichever provider you configured, such as OpenAI, Anthropic, Google, AWS Bedrock, Azure or a self-hosted model. Swapping models becomes a configuration change, not a code rewrite.
Why Teams Put a Gateway Between Apps and Models
Five problems push teams toward a gateway.
Provider lock-in. Hardcoding one vendor's SDK makes switching painful. A common interface keeps options open as models and prices change.
Key sprawl. Without a gateway, provider keys live in many services and laptops. A gateway lets applications use scoped virtual keys while real provider keys stay in one place.
Cost surprises. Budgets per team, project or customer stop a runaway agent from burning a month of spend overnight.
Reliability. Providers go down and rate limit. Fallbacks and load balancing across models or regions keep the product running.
Visibility. One place to log every request makes debugging and audits possible.
These are the same operational gaps behind why AI projects fail and how forward deployed engineers fix it: models work in demos, then production exposes cost, reliability and ownership problems.
What an AI Gateway Actually Does: Core Capabilities
This table summarizes the capabilities you should expect and ask about when comparing tools.
Feature maturity varies, so test the rows you need most.
LiteLLM Explained: SDK vs Proxy Server
LiteLLM is used in two distinct ways, and mixing them up causes confusion.
The Python SDK is a library you call directly in code. You use one function signature and change the model name to switch providers. It suits scripts, notebooks and applications where the developer controls the environment.
The proxy server is a standalone service, often run in Docker, that exposes an OpenAI-compatible endpoint. Applications in any language point at it. This is the form most people mean by "LiteLLM gateway." It adds the team-level features: virtual keys, budgets, rate limits, spend tracking and logging integrations.
LiteLLM is open source and free to self-host. The company also sells an enterprise offering with additional features and support, so check the vendor's pricing page for current terms. Searchers frequently ask whether LiteLLM costs money. The core project does not, but you pay for infrastructure and any provider tokens, and enterprise features are paid.
LiteLLM vs OpenRouter vs Other AI Gateways
The market has several categories, and mixing them is the main source of bad comparisons.
A short guide to choosing:
- Choose LiteLLM when customer data or keys must stay in your environment and your team can operate the service.
- Choose a hosted router like OpenRouter when you want one account and bill across many models and do not need to host anything.
- Choose a managed platform when governance, analytics and support matter more than owning the infrastructure.
- Choose an API gateway extension when your platform team already runs that gateway and wants one control plane.
Features and pricing change often, so confirm details on each vendor's site and test with real traffic.
AI Gateway vs API Gateway: What Is the Difference?
A traditional API gateway handles authentication, rate limiting and routing for any HTTP API. An AI gateway adds concerns specific to language models: token-based cost and limits, model-aware routing, prompt and response logging, caching of semantically similar prompts, and content guardrails.
Many API gateway vendors now add AI features, so the line is blurring. If you already run one, extending it may be simpler than adding another system.
A related question is how an MCP gateway differs from an LLM gateway. An LLM gateway manages calls to models. An MCP gateway manages how agents access tools and data sources through the Model Context Protocol. Larger deployments increasingly need both.
The LiteLLM Supply Chain Attack: What It Teaches About Gateways
A gateway holds provider keys, cloud credentials and often a database of upstream secrets. That makes it a prime target, and 2026 showed it.
According to Wiz's incident analysis, a malicious version 1.107.0 of the litellm package was published to PyPI on October 21, 2026, and quarantined about two hours later. Docker images carrying several tags, including the latest tag, also contained the trojanized code, and the last known safe version was 1.106.2. LiteLLM attributed the release access to stolen GitHub tokens from engineers.
The payload used a Python startup mechanism to run whenever the interpreter started, even without importing LiteLLM. Wiz reported that it targeted cloud credentials, AI provider keys, SSH keys, shell history and the upstream credentials stored in the proxy's database, and that attackers later used stolen cloud credentials in ways typical of model-hijacking abuse.
Search results show earlier and later discussion of other LiteLLM security events, so check LiteLLM's own security advisories for the full and current picture. The lessons apply to any gateway or dependency.
Pin and verify versions. Never run an unpinned latest tag in production. Pin exact versions, and use hash-checking and private mirrors where possible.
Delay upgrades slightly. A short cooling-off period before adopting new releases avoids windows like this one.
Assume secrets can leak. Keep provider keys scoped, budget-limited and rotatable. If a host ran an affected version, treat every credential on it as exposed and rotate.
Reduce what the gateway can reach. Run it in an isolated network with least-privilege cloud roles, so a compromise cannot walk across your environment.
Watch for abuse. Alert on unusual model listing, new regions or sudden spend spikes in provider accounts.
None of this makes gateways a bad idea. It makes them critical infrastructure that deserves the hardening of your secrets manager.
How to Run an AI Gateway Safely in Production
A baseline checklist for any gateway, whether LiteLLM or another.
- Pin versions and images by exact tag or digest, and review release notes before upgrading.
- Store provider keys in a secrets manager, not in environment files committed anywhere.
- Issue virtual keys per team or customer with budgets and rate limits.
- Isolate the network. Restrict outbound traffic to known provider endpoints where feasible.
- Use least-privilege cloud roles for the host or container.
- Log with care. Capture what you need for debugging and audit, and mask sensitive content.
- Alert on spend, errors and unusual access, and test failover before you need it.
How to Roll Out a Gateway for a Customer Project
When you deploy AI inside a customer's environment, the gateway decisions are partly the customer's decisions.
- Ask where data may go. Some customers allow only specific providers or regions. Configure the allowlist in the gateway.
- Decide who hosts it. A self-hosted gateway inside the customer's network satisfies strict data rules. A hosted service is faster but moves traffic outside.
- Give each business unit its own virtual key and budget. This supports chargeback and limits blast radius.
- Define fallback rules with the customer. Falling back to a different provider may break data residency commitments, so agree on it first.
- Hand over runbooks for key rotation, upgrades and incidents.
When You Do Not Need an AI Gateway
A gateway adds a moving part. Skip it for a single model in a single application or a prototype. Add one when you use several providers, serve multiple teams or customers, need cost attribution or face audit requirements.
Why Gateway Decisions Belong to Forward Deployed Engineers
Someone has to decide which models are allowed, how keys are protected, what happens during an outage and how costs are attributed. That is the job of a forward deployed engineer: someone embedded with the customer who owns the deployment from discovery to production. A gateway is a standard part of the tech stack forward deployed engineers use, alongside retrieval, evaluation and observability. The skills a forward deployed engineer needs include exactly this mix of integration, security awareness and customer communication, and the role involves real code, as explained in whether forward deployed engineers code.
Demand is growing, as covered in why companies are hiring forward deployed engineers. For daily practice, read a day in the life of a forward deployed engineer
TL;DR
- An AI gateway (or LLM gateway) is a layer between your applications and model providers that gives you one API, central key management, routing, fallbacks, budgets and logging.
- LiteLLM is the best-known open-source option. It offers a Python SDK and a proxy server that speak the OpenAI format to many providers.
- Alternatives include hosted routers such as OpenRouter, managed gateways such as Portkey, and API gateway vendors adding AI features. The right pick depends on who runs it and where data may flow.
- A gateway concentrates your secrets, so it becomes a high-value target. A 2026 supply chain attack on LiteLLM's PyPI package and Docker images showed why version pinning and secret hygiene matter.
- Start with a gateway when you use more than one model, serve several customers, or need cost control. Skip it for a single-model prototype
Frequently Asked Questions
What is LiteLLM used for?
LiteLLM provides one OpenAI-compatible interface to many model providers. Teams use its SDK to switch models in code, and its proxy server to manage keys, budgets, routing and logging across applications.
What is an AI gateway?
An AI gateway is a layer between applications and model providers that unifies the API and adds routing, fallbacks, cost tracking, rate limits, guardrails and observability. It is also called an LLM gateway.
Does LiteLLM cost money?
The open-source project is free to self-host, though you pay for infrastructure and model tokens. The company also offers paid enterprise features, so check its current pricing page.
What is the difference between LiteLLM and OpenRouter?
LiteLLM is open-source software you run yourself, which keeps keys and data in your environment. OpenRouter is a hosted service that gives access to many models through one account and bill. Self-hosting trades convenience for control.
What is the difference between an AI gateway and an API gateway?
An API gateway manages general HTTP traffic. An AI gateway adds model-specific features such as token-based limits, model routing, semantic caching and prompt guardrails. Some API gateway vendors now offer AI extensions.
Is it safe to use LiteLLM in production?
It can be, with controls. A 2026 supply chain incident affected a malicious release and Docker images, so pin exact versions, isolate the network, scope and rotate keys, and watch LiteLLM's security advisories before upgrading.
Become one of India’s first Forward-Deployed Engineers.
The world is hiring - and this Academy prepares you for it.
