Sarghaby Araghatta
Home / Knowledge Base / LLM gateways / proxies (e.g. LiteLLM)
Serving & infrastructure · AI Engineering

LLM gateways / proxies (e.g. LiteLLM)

A proxy service (LiteLLM, Portkey, Cloudflare AI Gateway, Kong AI Gateway) that presents a single unified API — usually OpenAI-shaped — and translates to whatever provider actually serves the call, adding cross-cutting controls.

API CallApply ControlsRoute RequestRoute RequestResponseResponseAppClientLLM GatewayUnified APIProvider AAPIProvider BAPIAuth& Rate Limits
LLM Gateway Data Flow

How it works

When an application wants to interact with a language model, it sends requests to a gateway like LiteLLM using a virtual API key. This gateway acts as an intermediary, normalizing the request and response formats for different providers. For instance, if one model requires a specific JSON structure while another uses a different format, the gateway translates between these formats smooth. This normalization ensures that developers can focus on building features without worrying about the underlying differences between various AI services.

Once the request is formatted correctly, the gateway applies several cross-cutting controls before forwarding it to the appropriate backend provider. This includes authentication checks to ensure that the request is valid, as well as enforcing per-team budgets and rate limits to prevent any single team from overusing resources. The gateway also handles routing and fallback mechanisms, so if one provider is down, it can redirect requests to another provider. It implements caching to speed up response times for frequently requested data, retries for transient errors, and logging for observability, all while keeping sensitive information like personally identifiable information (PII) redacted.

For example, if an application needs to generate text using both OpenAI and Cohere models, the gateway allows the app to send a single request format. The gateway normalizes this request, applies the necessary controls, and then routes it to the appropriate model. The response is then sent back to the application in a consistent format, regardless of which model was used. This reduces complexity in the application code and allows for easier management of multiple AI providers.

  • Client sends request to gateway.
  • Gateway applies auth and rate limits.
  • Gateway routes request to appropriate provider.
  • Provider responds to gateway.
  • Gateway normalizes and returns response.

The software-engineering analogue

This setup is similar to an API gateway like Kong or Apigee, which centralizes access to various services and manages aspects like authentication and rate limiting. It’s also like a database proxy such as PgBouncer, which optimizes database connections. However, the key difference with an LLM gateway is that it also reconciles the semantic differences between various AI backends. This means it handles not just the technical aspects of API calls but also the differences in how each model expects input and produces output, allowing developers to interact with different models through a unified interface.

Why not the obvious alternative

A newcomer might think to wire each provider's SDK directly into every service they build. This approach scatters API keys, cost tracking, and fallback logic throughout the codebase, which complicates maintenance. When a new model needs to be integrated or a policy changes, this would require modifying multiple services, leading to a higher chance of errors and inconsistencies.

By using a gateway, all these concerns are centralized. Policy changes, such as adjusting rate limits or budgets, can be implemented in one place and deployed across the organization. This not only simplifies the code but also enhances security by reducing the number of places where sensitive information is stored and managed.

When to use which

If your organization has multiple teams working with different models and you need centralized budgeting and governance, then using a gateway is the way to go. It streamlines access and management across various AI services. On the other hand, if you are developing a single application that interacts with just one provider and operates at low volume, using the native SDK would likely introduce less latency and require one less network hop. However, keep in mind that the gateway could become a single point of failure (SPOF), so evaluate the trade-offs carefully.

Centralized Control Tradeoff While gateways simplify management, they can become a single point of failure (SPOF) if not designed with redundancy.

In production: when it breaks

The scenario The API response time exceeded 300ms, causing 15% user drop-off.
API LatencyCheck Provider ResponseCheck Rate LimitingAdjust Timeout SettingsOptimize API Call LogicAdd Caching Layer
Debugging LLM Gateway Failure

Why it happens. This latency increase can occur due to bottlenecks in the request routing or translation layer of the gateway. When the gateway translates requests to different LLM providers, it may be experiencing delays due to high traffic, inefficient routing algorithms, or rate limiting on the backend services.

  • Step 1: Measure the response times for each LLM provider to identify if one is significantly slower than others.
  • Step 2: Log the request routing paths to see if certain paths are consistently slower, indicating potential bottlenecks.
  • Step 3: A/B test with different routing algorithms or load balancing strategies to determine if performance improves with alternative configurations.
The call The fix + the tradeoff + what to monitor> To fix the latency issue, consider optimizing the request routing algorithm or implementing caching for frequently requested responses. This may increase complexity in the routing logic but can significantly reduce response times. Monitor the average response times and the distribution of latencies across different LLM providers to ensure the issue is resolved and does not recur.

What it delivers

The main benefits of using an LLM gateway are vendor-agnostic code, organization-wide cost and access governance, and the implementation of cross-cutting features like caching, logging, and PII redaction. You write these once, and they apply uniformly across all interactions with different models, which simplifies development and enhances maintainability.