LiteLLM: One API Gateway to Control 100+ LLM Providers (Virtual Keys, Routing, and Guardrails)
Your team is burning through $50k/month in LLM API costs and you have no idea who's responsible. Sound familiar?
Every developer has their own API key. Some are testing with GPT-4 when GPT-3.5 would suffice. Others forgot to remove debugging loops that hammer the API. And that intern? They just ran a script that made 10,000 requests in an hour.
This is the reality for most companies using LLMs in 2026. And it's exactly why LiteLLM exists.
What LiteLLM Actually Does
LiteLLM is an open-source proxy that sits between your applications and LLM providers. Think of it as a smart gateway that:
- Routes requests to 100+ LLM providers using a unified OpenAI-compatible API
- Tracks every token, every request, every dollar spent
- Creates virtual API keys with budgets and rate limits
- Enforces guardrails before requests hit expensive models
The best part? Your existing code works unchanged. If you're calling OpenAI's API, you just swap the base URL to point at your LiteLLM proxy. Done.
Virtual Keys: Give Everyone Access Without Giving Away the Farm
Here's the typical nightmare: you share your OpenAI API key with the team. Within a week, it's committed to GitHub, costs are through the roof, and you're rotating credentials at 2 AM.
LiteLLM solves this with virtual keys. Each team member, project, or customer gets their own key that:
| Feature | What It Does |
|---|---|
| Budget limits | Caps spending per key (e.g., $100/month) |
| Rate limits | Prevents runaway scripts (e.g., 100 req/min) |
| Model restrictions | Limits which models a key can access |
| Expiration | Auto-revokes keys after a set date |
Creating a virtual key is straightforward:
curl -X POST 'http://your-litellm:4000/key/generate' \
-H 'Authorization: Bearer YOUR_MASTER_KEY' \
-H 'Content-Type: application/json' \
-d '{
"max_budget": 50.0,
"budget_duration": "30d",
"models": ["gpt-4", "gpt-3.5-turbo"],
"metadata": {"user": "frontend-team"}
}'
The key you get back works exactly like an OpenAI key, but with all your constraints baked in.
Cost Tracking That Actually Works
LiteLLM logs every request with:
- Token counts (input and output)
- Model used
- Calculated cost (using up-to-date pricing)
- User/team attribution
- Latency metrics
You can query spend by user, team, model, or time period:
curl 'http://your-litellm:4000/spend/logs?user_id=frontend-team&start_date=2026-02-01'
The response breaks down exactly where your money went. No more guessing why costs spiked on Tuesday.
Model Routing and Fallbacks
Here's where LiteLLM gets interesting. You can configure intelligent routing:
model_list:
- model_name: gpt-4
litellm_params:
model: azure/gpt-4
api_base: https://my-azure.openai.azure.com
- model_name: gpt-4
litellm_params:
model: openai/gpt-4
This configuration means: try Azure first, fall back to OpenAI if Azure fails. LiteLLM handles retries, load balancing, and failovers automatically.
You can also route based on:
- Cost: Send simple queries to cheaper models
- Latency: Route time-sensitive requests to faster providers
- Region: Keep EU data on EU servers for compliance
Guardrails: Stop Bad Requests Before They Cost You
LiteLLM's guardrails let you intercept requests before they hit the LLM:
guardrails:
- guardrail_name: "block-prompt-injection"
litellm_params:
guardrail: presidio
mode: pre_call
Common guardrails include:
- PII detection: Block requests containing social security numbers, credit cards
- Content filtering: Prevent harmful or off-topic prompts
- Token limits: Reject requests that would exceed a token threshold
- Custom validators: Run your own logic before each request
Deploy on Elestio in 3 Minutes
Setting up LiteLLM traditionally means configuring Docker, managing SSL, setting up monitoring. Elestio handles all of that.
- Go to elest.io/open-source/litellm
- Select your provider (Hetzner, DigitalOcean, AWS, etc.)
- Choose a plan (2 CPU / 4GB RAM minimum recommended)
- Click Deploy
Elestio provisions your instance with:
- Automated SSL via Let's Encrypt
- Daily backups
- Monitoring and alerts
- Auto-updates
Once deployed, access your LiteLLM dashboard through the provided URL. Add your LLM provider credentials (OpenAI, Azure, Anthropic, etc.) and start routing requests.
For custom domain setup with automated SSL, follow the official Elestio documentation.
Configuration Example
Here's a production-ready config that routes between multiple providers:
model_list:
- model_name: fast-model
litellm_params:
model: groq/llama-3.1-8b-instant
- model_name: smart-model
litellm_params:
model: anthropic/claude-3-5-sonnet-20241022
- model_name: cheap-model
litellm_params:
model: openai/gpt-3.5-turbo
general_settings:
master_key: "sk-your-master-key"
database_url: "postgresql://user:pass@localhost/litellm"
litellm_settings:
drop_params: true
set_verbose: false
Troubleshooting Common Issues
Keys not working? Check that your master key is set in general_settings. Virtual keys won't generate without it.
Cost tracking shows $0? Ensure your database URL is configured. LiteLLM needs a database to persist spend data.
Requests timing out? Verify your LLM provider credentials are correct. Check container logs:
docker logs litellm -f
Models not routing correctly? The model_name in your request must match exactly what's defined in model_list.
Why Self-Host Your LLM Gateway?
You might wonder: why not just use OpenAI directly?
Three reasons:
- Control: You own the logs, the keys, the routing logic. No vendor lock-in.
- Cost visibility: Real-time spend tracking across all providers in one place.
- Compliance: Data stays on your infrastructure. Critical for healthcare, finance, and EU operations.
At roughly $16/month for a capable Elestio instance, you'll likely save that in the first week just from catching runaway API calls.
Wrapping Up
LiteLLM transforms LLM operations from chaos into something manageable. Virtual keys give you access control. Cost tracking gives you visibility. Guardrails give you peace of mind.
Deploy it on Elestio, configure your providers, and hand out virtual keys to your team. You'll wonder how you ever managed without it.
Thanks for reading.