Blueprints · AI & LLMs
Production
25 min · LiteLLM
LiteLLM gateway production hardening
Binds the gateway to localhost, reads the master key from a mode 600 file, sets a daily budget, and turns message logging off so prompts and sk- keys are not written to the proxy log.
Live config
Baked-in protections
- The published host port is 127.0.0.1
- The master key is not stored in the compose file
- A daily max budget is set
- Message logging is off
- A database URL lets LiteLLM store generated virtual keys hashed
Step 1 · yaml
Gateway config
/opt/litellm/config.yaml
Set LITELLM_MASTER_KEY and DATABASE_URL in the env file. Virtual-key hashing needs the database URL.
model_list: [] general_settings: master_key: os.environ/LITELLM_MASTER_KEY database_url: os.environ/DATABASE_URL max_budget: 50 budget_duration: 1d litellm_settings: turn_off_message_logging: true drop_params: true
Step 2 · bash
Compose file and env file writer
/root/portgate-blueprints/litellm-write.sh
The writer creates an empty secret file. Fill it in before starting. The container command binds to localhost inside the published loopback port.
#!/bin/sh
set -eu
install -d -m 755 "/opt/litellm"
if [ ! -f "/opt/litellm/litellm.env" ]; then
umask 077
cat > "/opt/litellm/litellm.env" <<'EOF'
LITELLM_MASTER_KEY=
DATABASE_URL=
EOF
chmod 600 "/opt/litellm/litellm.env"
fi
cat > "/opt/litellm/compose.yaml" <<'EOF'
services:
litellm:
image: ghcr.io/berriai/litellm:main-stable
command: ["--host", "0.0.0.0", "--port", "4000", "--config", "/app/config.yaml"]
env_file:
- ./litellm.env
volumes:
- ./config.yaml:/app/config.yaml:ro
ports:
- "127.0.0.1:4000:4000"
read_only: true
tmpfs:
- /tmp
security_opt:
- no-new-privileges:true
restart: unless-stopped
EOF
echo "Gateway files written. The container was not started."