This repository contains a complete Docker setup for LiteLLM proxy with PostgreSQL database support. LiteLLM is a lightweight proxy server that provides a unified interface for calling 100+ LLMs including Azure OpenAI, Anthropic Claude, and more.
- 🚀 Unified API: Call 100+ LLMs through a single OpenAI-compatible interface
- 🔐 Authentication: Virtual key management with spend tracking and rate limits
- 📊 Database Support: PostgreSQL integration for persistent storage
- 🐳 Docker Ready: Complete containerized setup with docker-compose
- 🔄 Load Balancing: Built-in load balancing across multiple Azure OpenAI deployments
- 📈 Monitoring: Built-in logging, metrics, and health checks
- GPT-4: Load balanced across Central US and Australia East deployments
- GPT-3.5-turbo: Load balanced across Central US and East US 2 deployments
- GPT-4o: High-capacity model with 120K context (South India)
- GPT-4o-mini: Efficient model for lighter tasks (South India)
- Embeddings: text-embedding-3-large and text-embedding-3-small (East US 2)
- Claude 3 Haiku: Fast and efficient model
- Claude 3 Sonnet: Balanced performance model
- Claude 3 Opus: Most capable model
- Claude 3.5 Sonnet: Enhanced version with 7K max tokens
- Claude 3.7 Sonnet: Latest version with 12K max tokens
- Docker and Docker Compose installed
- You need to configure your own API keys (see Setup section below)
git clone <your-repo-url>
cd LiteLLLMProxyIMPORTANT: You must set up your own API keys before using this proxy.
Copy the example environment file:
cp env.example .envRequired Setup: Edit the .env file and configure:
-
Master Key: Generate a secure master key for admin access
LITELLM_MASTER_KEY=your-secure-master-key-here -
Azure OpenAI API Keys: Add your Azure OpenAI API keys and endpoints
AZURE_API_KEY_CENTRAL_US=your-azure-api-key-here AZURE_API_BASE_CENTRAL_US=your-azure-endpoint-here # ... add other Azure endpoints as needed -
Anthropic Claude API Key: Add your Anthropic API key
ANTHROPIC_API_KEY=your-anthropic-api-key-here -
PostgreSQL Configuration: The database credentials are pre-configured but you can modify them if needed
docker-compose up -dThis will start:
- LiteLLM proxy server on port 4000
- PostgreSQL database on port 5432
Check if the services are running:
docker-compose psTest the proxy health:
curl -H "Authorization: Bearer YOUR_MASTER_KEY" http://localhost:4000/healthOnce running, you can make OpenAI-compatible API calls to your proxy:
curl -X POST 'http://localhost:4000/chat/completions' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_MASTER_KEY' \
-d '{
"model": "gpt-4",
"messages": [
{
"role": "user",
"content": "Hello, how are you?"
}
]
}'You can call any of these models:
Azure OpenAI Models:
gpt-4(load balanced)gpt-3.5-turbo(load balanced)gpt-4ogpt-4o-minitext-embedding-3-largetext-embedding-3-small
Anthropic Claude Models:
claude-3-haikuclaude-3-sonnetclaude-3-opusclaude-3-5-sonnetclaude-3-7-sonnet
Generate virtual keys for different users or applications:
curl -X POST 'http://localhost:4000/key/generate' \
-H 'Authorization: Bearer YOUR_MASTER_KEY' \
-H 'Content-Type: application/json' \
-d '{
"models": ["gpt-4", "claude-3-5-sonnet"],
"max_budget": 100,
"rpm_limit": 60
}'import openai
client = openai.OpenAI(
api_key="sk-your-virtual-key-here",
base_url="http://localhost:4000"
)
# Use Azure OpenAI GPT-4 (load balanced)
response = client.chat.completions.create(
model="gpt-4",
messages=[
{"role": "user", "content": "Hello!"}
]
)
print(response.choices[0].message.content)import anthropic
client = anthropic.Anthropic(
api_key="sk-your-virtual-key-here",
base_url="http://localhost:4000"
)
response = client.messages.create(
model="claude-3-5-sonnet",
max_tokens=1000,
messages=[
{"role": "user", "content": "Hello!"}
]
)
print(response.content[0].text)| Variable | Description | Setup Required |
|---|---|---|
LITELLM_MASTER_KEY |
Master key for admin access | YOU MUST SET THIS |
LITELLM_SALT_KEY |
Salt key for encryption | Pre-configured |
POSTGRES_USER |
PostgreSQL username | litellm_user |
POSTGRES_PASSWORD |
PostgreSQL password | litellm_password_123 |
POSTGRES_DB |
PostgreSQL database name | litellm_db |
AZURE_API_KEY_* |
Azure OpenAI API keys | YOU MUST SET THESE |
AZURE_API_BASE_* |
Azure OpenAI endpoints | YOU MUST SET THESE |
ANTHROPIC_API_KEY |
Anthropic Claude API key | YOU MUST SET THIS |
The setup includes automatic load balancing for:
- GPT-4: Distributes requests between Central US and Australia East deployments
- GPT-3.5-turbo: Distributes requests between Central US and East US 2 deployments
This provides:
- Higher availability
- Better performance
- Automatic failover
- Distributed rate limits
# View all logs
docker-compose logs
# View specific service logs
docker-compose logs litellm
docker-compose logs postgres
# Follow logs in real-time
docker-compose logs -f litellm- Health endpoint:
http://localhost:4000/health - Readiness endpoint:
http://localhost:4000/health/readiness - Liveness endpoint:
http://localhost:4000/health/liveliness
Access the admin UI at http://localhost:4000/ui (if enabled in configuration).
-
Database Connection Issues
- Ensure PostgreSQL is running:
docker-compose ps - Check database logs:
docker-compose logs postgres - Verify environment variables in
.env
- Ensure PostgreSQL is running:
-
API Key Issues
- Make sure you have configured your own API keys in the
.envfile - Check that environment variables are referenced correctly in
config.yaml - Verify your Azure OpenAI and Anthropic API keys are valid
- Make sure you have configured your own API keys in the
-
Model Not Found
- Verify model configuration in
config.yaml - Check that the model name matches what you're requesting
- Verify model configuration in
-
Permission Denied
- Use your configured master key from the
.envfile - Check that you're using the correct authorization header
- Use your configured master key from the
To reset the database and start fresh:
docker-compose down -v
docker-compose up -d- You must generate your own secure master key
- You must provide your own API keys for Azure OpenAI and Anthropic
- Consider rotating API keys regularly in production
- Monitor usage and set appropriate rate limits
- Never commit API keys to version control
For production use:
- Use a managed PostgreSQL service
- Set up proper SSL certificates
- Configure reverse proxy (nginx, traefik)
- Set up monitoring and alerting
- Use Docker secrets or external secret management
- Configure backup strategies
- Ensure all API keys are properly secured
You need to obtain and configure the following API keys:
- Generate a secure random string (minimum 32 characters)
- This will be used for admin access to your LiteLLM proxy
- Example:
sk-your-secure-master-key-here-32-chars-min
- Sign up for Azure OpenAI service
- Create deployments for the models you want to use
- Get API keys and endpoints for each deployment
- Configure them in your
.envfile
- Sign up for Anthropic Claude API access
- Get your API key from the Anthropic console
- Add it to your
.envfile
# Master Key (REQUIRED - Generate your own)
LITELLM_MASTER_KEY=your-secure-master-key-here
# Azure OpenAI (REQUIRED - Add your own)
AZURE_API_KEY_CENTRAL_US=your-azure-api-key-here
AZURE_API_BASE_CENTRAL_US=https://your-resource.openai.azure.com/
# Anthropic (REQUIRED - Add your own)
ANTHROPIC_API_KEY=your-anthropic-api-key-here
# Database (Pre-configured, modify if needed)
POSTGRES_USER=litellm_user
POSTGRES_PASSWORD=litellm_password_123
POSTGRES_DB=litellm_dbThis project is licensed under the MIT License - see the LICENSE file for details.