An LLM gateway such as LiteLLM, Portkey, Cloudflare AI Gateway or Kong AI Gateway presents one unified API, usually OpenAI-shaped, and translates each call to whichever provider serves it, applying cross-cutting controls on the way.
The request path through a gateway
An application sends its request to the gateway using a virtual API key. The gateway normalizes request and response formats across providers. If one model expects a specific JSON structure and another expects a different one, the gateway translates between them, so developers build against one interface.
A single request format can serve OpenAI and Cohere models alike. The response comes back in a consistent shape whichever model answered, which removes provider-specific code from the application.
- The client sends a request to the gateway with a virtual key.
- The gateway applies authentication and rate limits.
- The gateway routes the request to the chosen provider.
- The provider responds to the gateway.
- The gateway normalizes the response and returns it.
Controls applied before the call leaves
Before forwarding, the gateway checks authentication, enforces per-team budgets and rate limits, and keeps one team from consuming a shared allowance. It also handles routing and fallback, so a provider outage can redirect traffic to another provider.
Caching speeds up responses for frequently requested data, retries cover transient errors, and logging supports observability. It can also redact personally identifiable information (PII) from what it logs.
The closest software analogues are an API gateway such as Kong or Apigee, which centralizes authentication and rate limiting, and a database proxy such as PgBouncer. An LLM gateway adds one more job: it reconciles the semantic differences between backends, meaning how each model expects input and produces output.
Gateway or direct provider SDKs
Wiring each provider SDK into every service scatters API keys, cost tracking and fallback logic through the codebase. Adding a model or changing a policy then means editing several services, with a higher chance of inconsistency. A gateway centralizes these concerns, so a change to a rate limit or budget is made once. It also reduces the number of places where sensitive information such as provider keys is stored and managed.
| Situation | Choice |
|---|---|
| Several teams, several models, central budgets and governance | Use a gateway. |
| One application, one provider, low volume | Use the native SDK. It adds one less network hop and less latency. |
Example scenario: latency above 300 ms
Example scenario: API response time exceeds 300 ms and 15% of users drop off. These figures are illustrative.
A likely cause is a bottleneck in the routing or translation layer, from high traffic, inefficient routing, or rate limiting on a backend service. Work through it in order:
- Measure response times per LLM provider to see whether one is much slower than the others.
- Log the routing paths to see whether particular paths are consistently slower.
- A/B test other routing algorithms or load balancing strategies.
The fix is to optimize the routing algorithm or cache frequently requested responses, at the cost of more complex routing logic. Monitor average response time and the latency distribution across providers.