Why LiteLLM?
- Unified API - Call any LLM provider using the OpenAI format
- Centralized key management - Store all provider API keys on the proxy, not in the client
- Spend tracking - Monitor usage and costs across all providers in one place
- Load balancing - Distribute requests across multiple deployments of the same model
- Fallbacks - Automatically retry with a different provider if one fails
Setup
- Deploy a LiteLLM proxy server (quickstart guide) and note the URL. If your proxy requires authentication, also note a master key or virtual key.
-
Set the proxy URL and optional API key in
.env.local:
- Set the gateway in your config:
chat.config.ts
Model IDs must match the model names configured in your LiteLLM proxy. These typically follow the
provider/model format (e.g., openai/gpt-4o, anthropic/claude-sonnet-4-20250514).Authentication
| Variable | Description |
|---|---|
LITELLM_BASE_URL | Required. The base URL of your LiteLLM proxy (e.g., http://localhost:4000) |
LITELLM_API_KEY | Optional. A master key or virtual key for your LiteLLM proxy |
Available Models
Models are fetched at runtime from your LiteLLM proxy’s/v1/models endpoint and cached for 1 hour. The available models depend entirely on what you have configured in your proxy’s config.yaml.
Example proxy configuration
litellm_config.yaml
Image Generation
Image generation support depends on the models available through your LiteLLM proxy. If your proxy is configured with an image generation model (e.g.,dall-e-3), enable it in your config:
chat.config.ts
Using the LiteLLM Python SDK
You can also interact with your LiteLLM proxy using the Python SDK:Related
- Gateways Overview for the full gateway comparison
- LiteLLM Documentation for proxy setup and configuration
- Custom Gateway if you need more control than this gateway provides