An LLM feature often starts with a few lines of code: a service stores an API key, calls a model provider, and returns the response. As more features are added, that simple setup becomes harder to manage. Several services may call different providers, each with its own API keys, retry logic, and usage tracking. A provider outage can disrupt multiple features, and a sudden increase in spending can be difficult to trace back to the team responsible.
An LLM gateway addresses these problems by providing a shared layer between applications and model providers. Model requests pass through the gateway, giving teams one place to manage routing, rate limits, failures, caching, and costs.
In this chapter, we'll walk through how an LLM gateway works and examine its main responsibilities: model routing, fallbacks, token-based rate limiting, caching, and cost tracking.