litellm configyaml
litellm configyaml – A Practical Playbook
Key Takeaways
- Litellm’s
config.yamlcentralizes all model, provider, and credential settings. - A well‑structured config file reduces runtime errors and speeds up CI/CD deployments.
- Use the provided checklists to validate configuration before launching services.
- Comparison table highlights differences between YAML, JSON, and environment variable approaches.
- FAQ section addresses common pitfalls and advanced use cases.
Understanding litellm configyaml
The config.yaml file is the backbone of Litellm’s runtime behavior. It specifies:
- Providers – OpenAI, Anthropic, Cohere, etc.
- Models – Which model versions to use.
- Credentials – API keys, secrets, and authentication methods.
- Routing Rules – How to distribute requests across providers.
- Rate Limits & Quotas – Per‑provider and global limits.
- Custom Plugins – Extensions for logging, monitoring, or post‑processing.
Step‑by‑Step Setup Checklist
- Create the file:
touch config.yamlin your project root. - Define providers:
- OpenAI:
openai_key: YOUR_KEY - Anthropic:
anthropic_key: YOUR_KEY - Others: Add under
providers:section.
- OpenAI:
- Add model mappings:
model_mapping: gpt-4: openai claude-2: anthropic - Set routing rules:
- Round‑robin:
routing: round_robin - Weighted:
routing: weightedwithweights:mapping.
- Round‑robin:
- Configure rate limits:
rate_limits: openai: max_requests_per_minute: 60 anthropic: max_requests_per_minute: 40 - Validate syntax: Run
yaml-lint config.yamlor use online validator. - Test locally: Execute
litellm --config config.yaml testto ensure connectivity. - Commit to source control – Exclude sensitive data using
.gitignoreor environment variables.
Comparison Table: YAML vs JSON vs Env Vars
| Aspect | YAML (config.yaml) | JSON (config.json) | Environment Variables |
|---|---|---|---|
| Readability | High – indentation and comments | Medium – strict syntax | Low – no inherent structure |
| File Size | Compact – no quotes for keys | Verbose – quotes everywhere | Depends on number of vars |
| Comments | Supported – # comment |
Not supported | Not applicable |
| Dynamic Values | Use anchors/aliases | No native support | Full flexibility via shell |
| Security | File can be git‑ignored; sensitive keys hidden | Similar to YAML, but harder to hide keys in git | Best practice for secrets (e.g., Docker secrets) |
| Tooling | Wide support (linters, editors) | Wide support | Native to CI pipelines |
Deployment Checklist
- Ensure
config.yamlis present in the deployment image or container volume. - Verify that all referenced API keys exist as environment variables or secrets.
- Run
litellm --config config.yaml validatein the container to catch syntax errors. - Set environment variables for
BASE_URLand other runtime flags. - Use health checks:
litellm healthto confirm provider connectivity. - Monitor logs for
config.yamlparsing errors during startup. - Automate tests in CI: stage
config.yamlvalidation before deployment.
FAQs
-
Can I use environment variables inside
config.yaml?Yes. Wrap the variable name with
${VAR_NAME}. Litellm will resolve it at runtime. For example:openai_key: ${OPENAI_API_KEY} -
How do I handle multiple model providers with overlapping model names?
Use the
model_mappingsection to explicitly map each model to a provider. This eliminates ambiguity during routing. -
What is the best way to secure my API keys in CI/CD pipelines?
Store keys in encrypted secrets (GitHub Actions secrets, GitLab CI variables, or Kubernetes Secrets) and reference them as environment variables in the
config.yaml. Avoid committing raw keys to the repository.