dhi.io/litellm
LiteLLM is a universal LLM API gateway that provides OpenAI-compatible APIs for 100+ LLM providers including Bedrock, Azure, OpenAI, Anthropic, Vertex AI, and more.
All examples in this guide use the public image. If you’ve mirrored the repository for your own use (for example, to your Docker Hub namespace), update your commands to reference the mirrored image instead of the public one.
For example:
dhi.io/<repository>:<tag><your-namespace>/dhi-<repository>:<tag>For the examples, you must first use docker login dhi.io to authenticate to the registry to pull the images.
This Docker Hardened LiteLLM image includes a universal LLM API gateway that provides OpenAI-compatible APIs for 100+ LLM providers in a single, security-hardened package:
Run the following command and replace <tag> with the image variant you want to run.
docker run -p 4000:4000 \
-v ./config.yaml:/app/config.yaml \
-e OPENAI_API_KEY=your-openai-key \
-e ANTHROPIC_API_KEY=your-anthropic-key \
dhi.io/litellm:<tag> --config /app/config.yaml
Use LiteLLM as a unified proxy to route requests across multiple LLM providers (OpenAI, Anthropic, Azure, Bedrock, etc.) with automatic failover and load balancing.
model_list:
- model_name: gpt-4
litellm_params:
model: openai/gpt-4
api_key: os.environ/OPENAI_API_KEY
- model_name: claude-3
litellm_params:
model: anthropic/claude-3-sonnet-20240229
api_key: os.environ/ANTHROPIC_API_KEY
Monitor usage and costs across different LLM providers, implement budget controls and rate limiting per user or API key.
docker run -p 4000:4000 \
-v $(pwd)/config.yaml:/app/config.yaml \
-e DATABASE_URL=postgresql://user:password@hostname:5432/litellm \
-e OPENAI_API_KEY=your-openai-key \
dhi.io/litellm:<tag> --config /app/config.yaml
Make existing applications that use OpenAI's API compatible with other LLM providers without code changes.
curl -X POST http://localhost:4000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4",
"messages": [{"role": "user", "content": "Hello, world!"}],
"max_tokens": 100
}'
Easily switch between different LLM models and providers during development and testing phases. Configure common environment variables:
OPENAI_API_KEY: OpenAI API keyANTHROPIC_API_KEY: Anthropic API keyAZURE_API_KEY: Azure OpenAI API keyVERTEX_PROJECT: Google Cloud Project ID for Vertex AIAWS_ACCESS_KEY_ID: AWS access key for BedrockDATABASE_URL: PostgreSQL database URL for trackingLITELLM_LOG: Log level (DEBUG, INFO, WARNING, ERROR)Centralized authentication, authorization, and monitoring for LLM access across an organization.
Configure authentication and team management in your config.yaml:
general_settings:
master_key: sk-master-key-here
database_url: postgresql://user:pass@host:5432/litellm
authentication:
enable: true
api_key_header: "Authorization"
max_budget: 1000
budget_duration: 30d
model_list:
- model_name: gpt-4-production
litellm_params:
model: openai/gpt-4
api_key: os.environ/OPENAI_API_KEY
metadata:
team: "engineering"
max_requests_per_minute: 100
Create API keys for different teams:
curl -X POST http://localhost:4000/key/generate \
-H "Authorization: Bearer sk-master-key-here" \
-H "Content-Type: application/json" \
-d '{
"team_id": "engineering-team",
"max_budget": 500,
"models": ["gpt-4-production"],
"duration": "30d"
}'
Distribute requests across multiple model deployments with automatic retry logic and failover capabilities.
model_list:
- model_name: gpt-4
litellm_params:
model: openai/gpt-4
api_key: os.environ/OPENAI_API_KEY
rpm: 100
- model_name: gpt-4
litellm_params:
model: azure/gpt-4-deployment
api_base: https://myazure.openai.azure.com
api_key: os.environ/AZURE_API_KEY
rpm: 200
- model_name: gpt-4-fallback
litellm_params:
model: anthropic/claude-3-opus-20240229
api_key: os.environ/ANTHROPIC_API_KEY
router_settings:
routing_strategy: "least-busy"
num_retries: 3
timeout: 30
fallbacks:
gpt-4: ["gpt-4-fallback"]
Standardize LLM integration across development teams while easily switching between providers to optimize for cost, performance, or availability.
model_list:
- model_name: chat-cheap
litellm_params:
model: anthropic/claude-3-haiku-20240307
api_key: os.environ/ANTHROPIC_API_KEY
metadata:
cost_per_token: 0.00025
use_case: "simple_queries"
- model_name: chat-powerful
litellm_params:
model: openai/gpt-4-turbo
api_key: os.environ/OPENAI_API_KEY
metadata:
cost_per_token: 0.01
use_case: "complex_analysis"
- model_name: chat-compliant
litellm_params:
model: azure/gpt-4-deployment
api_base: https://private.openai.azure.com
api_key: os.environ/AZURE_API_KEY
metadata:
data_residency: "us-east"
compliance: "hipaa"
Use the same client code to work with any configured model:
curl -X POST http://localhost:4000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key" \
-d '{
"model": "chat-cheap",
"messages": [{"role": "user", "content": "Hello!"}]
}'
| Feature | Standard LiteLLM Image | Docker Hardened LiteLLM |
|---|---|---|
| Security | Standard base with common utilities | Minimal, hardened base with security patches |
| Shell access | Full shell (bash/sh) available | Bash included for the upstream entrypoint script |
| Package manager | apt/apk available | No package manager in runtime variants (pip available for Python packages) |
| User | Runs as root by default | Runs as nonroot user |
| File permissions | /app writable by the runtime user | Application tree root-owned; only /app/.cache writable at runtime |
| Attack surface | Larger due to additional utilities | Minimal, only essential components |
| Debugging | Traditional shell debugging | Use Docker Debug or Image Mount for troubleshooting |
| Provenance | Standard image metadata | Signed provenance attestations and complete SBOM |
| Vulnerability tracking | Standard CVE reporting | VEX documents explaining remaining CVEs |
| Upstream compatibility | N/A | Based on official litellm/litellm, maintains full API compatibility |
The LiteLLM runtime image includes Bash because the upstream entrypoint script /app/docker/prod_entrypoint.sh requires
it. The image does not include a system package manager (pip remains available in the LiteLLM virtual environment) and
otherwise remains minimal:
The hardened images intended for runtime don't contain debugging tools beyond the shell and basic utilities. Common debugging methods for applications built with Docker Hardened Images include:
Docker Debug provides a shell, common debugging tools, and lets you install other tools in an ephemeral, writable layer that only exists during the debugging session.
For example, you can use Docker Debug:
docker debug <container-name>
or mount debugging tools with the Image Mount feature:
docker run --rm -it --pid container:my-litellm \
--mount=type=image,source=dhi.io/busybox,destination=/dbg,ro \
dhi.io/litellm:<tag> /dbg/bin/sh
Docker Hardened Images come in different variants depending on their intended use. Image variants are identified by their tag.
Runtime variants are designed to run your application in production. These images are intended to be used either
directly or as the FROM image in the final stage of a multi-stage build. These images typically:
litellm is an exception to the shell point above: the upstream entrypoint script
/app/docker/prod_entrypoint.sh needs bash, so the runtime variants include a shell. They still have no system
package manager.
Build-time variants typically include dev in the variant name and are intended for use in the first stage of a
multi-stage Dockerfile. These images typically:
FIPS variants include fips in the variant name and tag. They come in both runtime and build-time variants. These
variants use cryptographic modules that have been validated under FIPS 140, a U.S. government standard for secure
cryptographic operations. In this image, the validated OpenSSL provider covers Python's ssl and hashlib modules,
which carry the proxy's TLS listener, its outbound HTTPS calls to LLM providers and its key hashing; the
cryptography package, built against the system OpenSSL, which handles JWT verification, license checks, request
signing for OCI and the encryption of credentials stored in the database; and the Prisma query and schema engines.
Components that bundle their own cryptography stay outside that boundary: the Node.js runtime that drives
prisma migrate deploy at startup, the pynacl wheel (libsodium) that decrypts credentials stored by older releases,
grpcio (BoringSSL) used by gRPC-based providers such as Vertex AI, and the Rust-based extensions (hf_xet,
granian, polars, and the Datadog and Pyroscope agents). For example, usage of MD5 fails in FIPS variants.
To view the image variants and get more information about them, select the Tags tab for this repository, and then select a tag.
To migrate your application to a Docker Hardened Image, you must update your Dockerfile. At minimum, you must update the base image in your existing Dockerfile to a Docker Hardened Image. This and a few other common changes are listed in the following table of migration notes:
| Item | Migration note |
|---|---|
| Base image | Replace litellm/litellm or other base images (ghcr.io/berriai/litellm, etc.) with the Docker Hardened LiteLLM image. |
| Package management | Non-dev images don't contain Debian package managers. Python's pip is included as part of the Python installation in a virtual environment at /opt/litellm, allowing you to extend with custom callbacks and packages. Note that adding packages can potentially introduce new CVEs or break previously remediated CVEs if not done carefully. |
| Non-root user | |
| Multi-stage build | For custom extensions, use a multi-stage build approach. Build stages can use dev variants for compilation, then copy artifacts to the runtime stage. |
| TLS certificates | Docker Hardened Images contain standard TLS certificates by default. There is no need to install TLS certificates. |
| Ports | Non-dev hardened images run as a nonroot user by default. As a result, applications in these images can't bind to privileged ports (below 1024) when running in Kubernetes or in Docker Engine versions older than 20.10. Configure LiteLLM to listen on port 4000 or another unprivileged port. |
| Entry point | Docker Hardened Images may have different entry points than upstream images. The DHI LiteLLM image uses /app/docker/prod_entrypoint.sh as the entry point. |
| Shell | LiteLLM runtime variants include Bash because the upstream entrypoint requires it. Use Docker Debug or mounted tools for troubleshooting instead of modifying the running container. |
The following steps outline the general migration process.
Find hardened images for your app. Check the available Docker Hardened LiteLLM image tags in your namespace to find the variant that meets your needs.
Update the base image in your Dockerfile. Update the base image in your application's Dockerfile to the hardened image. For example:
FROM dhi.io/litellm:<version-tag>
# Switch to UID 0 for file operations and package installations
USER 0
# Copy your custom callbacks and configuration
COPY custom_callbacks.py /app/custom_callbacks.py
COPY litellm-config.yaml /app/config.yaml
# Install additional Python packages if needed
COPY requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt
# Ensure files have correct permissions for nonroot user
RUN chown nonroot:nonroot /app/custom_callbacks.py /app/config.yaml /app/requirements.txt
RUN chmod 644 /app/custom_callbacks.py /app/config.yaml /app/requirements.txt
# Set working directory
WORKDIR /app
# Switch back to nonroot user for runtime security
USER nonroot
# Use the standard DHI entrypoint
ENTRYPOINT ["/app/docker/prod_entrypoint.sh"]
For multi-stage Dockerfiles, update the runtime image in your Dockerfile. To ensure that your final image is as minimal as possible, you should use a multi-stage build when adding system-level dependencies.
Install additional packages The LiteLLM software is installed in a virtualenv at /opt/litellm. The litellm
executable and pip are both symlinked to that location, keeping them out of a system-level Python environment. Use
pip to install any additional Python packages your callbacks or custom code requires.
The hardened images intended for runtime don't contain debugging tools beyond the shell and basic utilities. The recommended method for debugging applications built with Docker Hardened Images is to use Docker Debug to attach to these containers. Docker Debug provides a shell, common debugging tools, and lets you install other tools in an ephemeral, writable layer that only exists during the debugging session.
The LiteLLM software is installed in a virtualenv at /opt/litellm. The litellm executable and pip are both
symlinked to that location, keeping them out of a system-level Python environment. When installing additional packages,
they will be installed directly into this virtual environment.
By default, image variants intended for runtime run as the nonroot user. Ensure that necessary files and directories are accessible to the nonroot user. You may need to copy files to different directories or change permissions so your application running as the nonroot user can access them.
Non-dev hardened images run as a nonroot user by default. As a result, applications in these images can't bind to privileged ports (below 1024) when running in Kubernetes or in Docker Engine versions older than 20.10. The default LiteLLM port 4000 works without issues.
Docker Hardened Images may have different entry points than upstream images. The DHI LiteLLM image uses
/app/docker/prod_entrypoint.sh instead of /docker/prod_entrypoint.sh as the entry point . Use docker inspect to
verify the entry point and update your Dockerfile if necessary.