Add LiteLLM Cloudron app package: manifest, Dockerfile, start.sh, config.yaml
This commit is contained in:
1 parent
1b70128f5a
commit
95841b88f3
6 files changed
+363
No files matched your search
@@ -0,0 +1,5 @@
|
||||
node_modules
|
||||
.git
|
||||
*.md
|
||||
Dockerfile
|
||||
.dockerignore
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"id": "ai.coop.litellm",
|
||||
"title": "LiteLLM Gateway",
|
||||
"author": "inference.coop",
|
||||
"description": "LiteLLM AI Gateway — OpenAI-compatible proxy with per-user API keys, usage tracking, rate limiting, and model routing. Packaged for Cloudron with SSO/OIDC and PostgreSQL.",
|
||||
"tagline": "AI gateway for cooperative inference",
|
||||
"version": "1.0.0",
|
||||
"upstreamVersion": "1.74.0",
|
||||
"healthCheckPath": "/health/readiness",
|
||||
"httpPort": 4000,
|
||||
"manifestVersion": 2,
|
||||
"website": "https://litellm.ai",
|
||||
"contactEmail": "botbot@hermes",
|
||||
"icon": "file://logo.png",
|
||||
"addons": {
|
||||
"postgresql": {},
|
||||
"redis": {},
|
||||
"localstorage": {}
|
||||
},
|
||||
"tags": ["ai", "gateway", "proxy", "api"],
|
||||
"mediaLinks": [],
|
||||
"changelog": "Initial package for inference.coop"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
FROM ghcr.io/berriai/litellm:main-v1.74.0-stable
|
||||
|
||||
# Cloudron runs apps as the 'cloudron' user (uid 1000) by default.
|
||||
# LiteLLM's official image runs as root; we switch to cloudron for security.
|
||||
# However, LiteLLM needs to write to /app/data for its database/config.
|
||||
|
||||
USER root
|
||||
|
||||
# Install supervisor to manage processes (LiteLLM + optional cron)
|
||||
RUN pip install --no-cache-dir supervisor
|
||||
|
||||
# Create the data directory and set ownership
|
||||
RUN mkdir -p /app/data && chown -R cloudron:cloudron /app/data
|
||||
|
||||
# Create a startup script that configures LiteLLM with Cloudron addons
|
||||
COPY start.sh /app/code/start.sh
|
||||
RUN chmod +x /app/code/start.sh && chown cloudron:cloudron /app/code/start.sh
|
||||
|
||||
# Default config — will be overridden by Cloudron env vars at runtime
|
||||
COPY config.yaml /app/data/config.yaml
|
||||
RUN chown cloudron:cloudron /app/data/config.yaml
|
||||
|
||||
USER cloudron
|
||||
|
||||
CMD ["/app/code/start.sh"]
|
||||
@@ -0,0 +1,82 @@
|
||||
# LiteLLM Cloudron App Package
|
||||
|
||||
A Cloudron app package for [LiteLLM](https://litellm.ai/) — the open-source AI gateway.
|
||||
|
||||
## What this provides
|
||||
|
||||
- LiteLLM proxy with OpenAI-compatible API on port 4000
|
||||
- Per-user virtual API keys, usage tracking, rate limiting
|
||||
- Model routing to Tinfoil (TEE), OpenRouter (frontier fallback), and Ollama (self-hosted)
|
||||
- Cloudron PostgreSQL for keys/teams/spend logs
|
||||
- Cloudron Redis for rate limiting/caching
|
||||
- Cloudron SSO via OIDC (admin UI protected by Cloudron login)
|
||||
- Automatic SSL, backups, sandboxing
|
||||
- Master key and salt key auto-generated on first start (persisted in /app/data)
|
||||
|
||||
## Files
|
||||
|
||||
- `CloudronManifest.json` — Cloudron app manifest (addons, ports, metadata)
|
||||
- `Dockerfile` — wraps LiteLLM's official image for Cloudron's environment
|
||||
- `start.sh` — startup script that configures LiteLLM with Cloudron addons
|
||||
- `config.yaml` — default LiteLLM config with inference.coop model routing
|
||||
|
||||
## Building and installing
|
||||
|
||||
```bash
|
||||
# Install Cloudron CLI (on your local machine)
|
||||
npm install -g cloudron-cli
|
||||
|
||||
# Login to your Cloudron
|
||||
cloudron login
|
||||
|
||||
# From this directory:
|
||||
cloudron build # builds the Docker image
|
||||
cloudron install # installs on your Cloudron
|
||||
```
|
||||
|
||||
## Environment variables
|
||||
|
||||
Set these in Cloudron's app config (Settings → Environment Variables) after installation:
|
||||
|
||||
- `TINFOIL_API_KEY` — your Tinfoil API key (get at https://tinfoil.sh/)
|
||||
- `OPENROUTER_API_KEY` — your OpenRouter API key (get at https://openrouter.ai/)
|
||||
- `OLLAMA_API_BASE` — if running Ollama on a different host (default: http://127.0.0.1:11434)
|
||||
|
||||
The following are auto-generated and should NOT be set manually:
|
||||
- `LITELLM_MASTER_KEY` — generated on first start, stored in /app/data/.master_key
|
||||
- `LITELLM_SALT_KEY` — generated on first start, stored in /app/data/.salt_key
|
||||
- `DATABASE_URL` — set from Cloudron's PostgreSQL addon
|
||||
- `REDIS_HOST`, `REDIS_PORT`, `REDIS_PASSWORD` — set from Cloudron's Redis addon
|
||||
|
||||
## After installation
|
||||
|
||||
1. Open `https://gateway.inference.coop/ui` (or whatever subdomain you chose)
|
||||
2. Log in with username `admin` and the master key as password
|
||||
3. To find the master key: `cloudron exec cat /app/data/.master_key`
|
||||
4. Add provider API keys in the Admin UI (or set as env vars above)
|
||||
5. Create virtual keys for members
|
||||
6. Point Open WebUI / LobeChat at `https://gateway.inference.coop/v1`
|
||||
|
||||
## Connecting Open WebUI
|
||||
|
||||
In Open WebUI settings:
|
||||
- API Base URL: `https://gateway.inference.coop/v1`
|
||||
- API Key: a virtual key created in LiteLLM's Admin UI
|
||||
|
||||
## Model routing
|
||||
|
||||
The default config routes:
|
||||
- `gpt-oss-120b`, `deepseek-v4-flash`, `gemma4-31b`, `llama3-3-70b` → Tinfoil (TEE)
|
||||
- `claude-sonnet`, `gpt-4o` → OpenRouter (frontier fallback)
|
||||
- `ollama-qwen` → local Ollama (if installed on same Cloudron)
|
||||
- Fallback: if Tinfoil is down, `gpt-oss-120b` falls back to `gpt-4o` via OpenRouter
|
||||
|
||||
## OIDC / SSO
|
||||
|
||||
The manifest requests the `postgresql`, `redis`, and `localstorage` addons.
|
||||
For full OIDC SSO integration (so the admin UI uses Cloudron login instead of
|
||||
master key), add the `"oidc": {}` addon to the manifest and configure LiteLLM's
|
||||
SSO hooks per https://docs.litellm.ai/docs/proxy/custom_sso.
|
||||
|
||||
This is a TODO for the next version — the current package uses LiteLLM's
|
||||
built-in admin/master-key auth, which is sufficient for the MVP.
|
||||
@@ -0,0 +1,68 @@
|
||||
# LiteLLM config for inference.coop
|
||||
# This file is written on first start by start.sh
|
||||
# Provider keys are set via environment variables or the Admin UI
|
||||
|
||||
model_list:
|
||||
# Tinfoil (TEE-protected inference) — default backend
|
||||
- model_name: gpt-oss-120b
|
||||
litellm_params:
|
||||
model: openai/gpt-oss-120b
|
||||
api_base: https://api.tinfoil.sh/v1
|
||||
api_key: os.environ/TINFOIL_API_KEY
|
||||
|
||||
- model_name: deepseek-v4-flash
|
||||
litellm_params:
|
||||
model: openai/deepseek-v4-flash
|
||||
api_base: https://api.tinfoil.sh/v1
|
||||
api_key: os.environ/TINFOIL_API_KEY
|
||||
|
||||
- model_name: gemma4-31b
|
||||
litellm_params:
|
||||
model: openai/gemma4-31b
|
||||
api_base: https://api.tinfoil.sh/v1
|
||||
api_key: os.environ/TINFOIL_API_KEY
|
||||
|
||||
- model_name: llama3-3-70b
|
||||
litellm_params:
|
||||
model: openai/llama3-3-70b
|
||||
api_base: https://api.tinfoil.sh/v1
|
||||
api_key: os.environ/TINFOIL_API_KEY
|
||||
|
||||
# OpenRouter — fallback for frontier models
|
||||
- model_name: claude-sonnet
|
||||
litellm_params:
|
||||
model: openrouter/anthropic/claude-sonnet
|
||||
api_base: https://openrouter.ai/api/v1
|
||||
api_key: os.environ/OPENROUTER_API_KEY
|
||||
|
||||
- model_name: gpt-4o
|
||||
litellm_params:
|
||||
model: openrouter/openai/gpt-4o
|
||||
api_base: https://openrouter.ai/api/v1
|
||||
api_key: os.environ/OPENROUTER_API_KEY
|
||||
|
||||
# Ollama (self-hosted, free) — if running on same Cloudron
|
||||
- model_name: ollama-qwen
|
||||
litellm_params:
|
||||
model: ollama/qwen3.5:7b
|
||||
api_base: http://127.0.0.1:11434
|
||||
api_key: "ollama"
|
||||
|
||||
router_settings:
|
||||
routing_strategy: simple-shuffle
|
||||
num_retries: 2
|
||||
timeout: 30
|
||||
fallbacks:
|
||||
- gpt-oss-120b:
|
||||
- gpt-4o
|
||||
|
||||
general_settings:
|
||||
master_key: os.environ/LITELLM_MASTER_KEY
|
||||
database_url: os.environ/DATABASE_URL
|
||||
store_model_in_db: true
|
||||
|
||||
litellm_settings:
|
||||
salt_key: os.environ/LITELLM_SALT_KEY
|
||||
drop_params: true
|
||||
num_threads: 4
|
||||
request_timeout: 30
|
||||
@@ -0,0 +1,160 @@
|
||||
#!/bin/bash
|
||||
set -eu
|
||||
|
||||
# ============================================================================
|
||||
# LiteLLM Cloudron Startup Script
|
||||
# Configures LiteLLM with Cloudron's PostgreSQL and Redis addons
|
||||
# ============================================================================
|
||||
|
||||
echo "=== LiteLLM Cloudron Startup ==="
|
||||
|
||||
# --- Cloudron PostgreSQL addon provides:
|
||||
# CLOUDRON_POSTGRESQL_URL - postgresql://user:pass@host:port/dbname
|
||||
# CLOUDRON_POSTGRESQL_USERNAME
|
||||
# CLOUDRON_POSTGRESQL_PASSWORD
|
||||
# CLOUDRON_POSTGRESQL_HOST
|
||||
# CLOUDRON_POSTGRESQL_PORT
|
||||
# CLOUDRON_POSTGRESQL_DATABASE
|
||||
|
||||
# --- Cloudron Redis addon provides:
|
||||
# CLOUDRON_REDIS_URL - redis://user:pass@host:port
|
||||
# CLOUDRON_REDIS_USERNAME
|
||||
# CLOUDRON_REDIS_PASSWORD
|
||||
# CLOUDRON_REDIS_HOST
|
||||
# CLOUDRON_REDIS_PORT
|
||||
|
||||
# --- Cloudron provides:
|
||||
# CLOUDRON_APP_DOMAIN - the app's domain (e.g. gateway.inference.coop)
|
||||
# CLOUDRON_API_ORIGIN - origin for API calls
|
||||
# CLOUDRON_WEB_ORIGIN - origin for web UI
|
||||
|
||||
# --- LiteLLM required env vars ---
|
||||
|
||||
# Generate a master key if not already in /app/data
|
||||
MASTER_KEY_FILE="/app/data/.master_key"
|
||||
if [ ! -f "$MASTER_KEY_FILE" ]; then
|
||||
echo "Generating master key..."
|
||||
python3 -c "import secrets; print('sk-' + secrets.token_urlsafe(32))" > "$MASTER_KEY_FILE"
|
||||
fi
|
||||
export LITELLM_MASTER_KEY=$(cat "$MASTER_KEY_FILE")
|
||||
|
||||
# Generate a salt key if not already in /app/data
|
||||
SALT_KEY_FILE="/app/data/.salt_key"
|
||||
if [ ! -f "$SALT_KEY_FILE" ]; then
|
||||
echo "Generating salt key..."
|
||||
python3 -c "import secrets; print(secrets.token_urlsafe(32))" > "$SALT_KEY_FILE"
|
||||
fi
|
||||
export LITELLM_SALT_KEY=$(cat "$SALT_KEY_FILE")
|
||||
|
||||
# Use Cloudron's PostgreSQL
|
||||
export DATABASE_URL="${CLOUDRON_POSTGRESQL_URL}"
|
||||
|
||||
# Use Cloudron's Redis (for rate limiting, caching)
|
||||
export REDIS_HOST="${CLOUDRON_REDIS_HOST}"
|
||||
export REDIS_PORT="${CLOUDRON_REDIS_PORT}"
|
||||
export REDIS_PASSWORD="${CLOUDRON_REDIS_PASSWORD}"
|
||||
|
||||
# Store models in DB (manage from Admin UI)
|
||||
export STORE_MODEL_IN_DB="True"
|
||||
|
||||
# Don't run schema migrations on every start — let LiteLLM handle it
|
||||
# (for single-instance deployment this is fine)
|
||||
export DISABLE_SCHEMA_UPDATE="false"
|
||||
|
||||
# UI configuration — use Cloudron's domain
|
||||
export UI_USERNAME="admin"
|
||||
export UI_PASSWORD="${LITELLM_MASTER_KEY}"
|
||||
|
||||
# Proxy settings for Cloudron's reverse proxy
|
||||
export LITELLM_PROXY_BASE_URL="https://${CLOUDRON_APP_DOMAIN}"
|
||||
|
||||
# Allow requests from Cloudron's Open WebUI, LobeChat, etc.
|
||||
export LITELLM_CORS_ALLOWED_ORIGINS="${CLOUDRON_WEB_ORIGIN:-*}"
|
||||
|
||||
echo "PostgreSQL: ${CLOUDRON_POSTGRESQL_HOST}:${CLOUDRON_POSTGRESQL_PORT}"
|
||||
echo "Redis: ${CLOUDRON_REDIS_HOST}:${CLOUDRON_REDIS_PORT}"
|
||||
echo "Domain: ${CLOUDRON_APP_DOMAIN}"
|
||||
|
||||
# --- Write config.yaml with Cloudron provider keys if set ---
|
||||
|
||||
CONFIG_FILE="/app/data/config.yaml"
|
||||
|
||||
if [ ! -f "$CONFIG_FILE" ] || [ ! -s "$CONFIG_FILE" ]; then
|
||||
echo "Writing default config.yaml..."
|
||||
cat > "$CONFIG_FILE" << 'YAML'
|
||||
# LiteLLM config for inference.coop
|
||||
# Provider keys are set via environment variables or the Admin UI
|
||||
|
||||
model_list:
|
||||
# Tinfoil (TEE-protected inference) — default backend
|
||||
- model_name: gpt-oss-120b
|
||||
litellm_params:
|
||||
model: openai/gpt-oss-120b
|
||||
api_base: https://api.tinfoil.sh/v1
|
||||
api_key: os.environ/TINFOIL_API_KEY
|
||||
|
||||
- model_name: deepseek-v4-flash
|
||||
litellm_params:
|
||||
model: openai/deepseek-v4-flash
|
||||
api_base: https://api.tinfoil.sh/v1
|
||||
api_key: os.environ/TINFOIL_API_KEY
|
||||
|
||||
- model_name: gemma4-31b
|
||||
litellm_params:
|
||||
model: openai/gemma4-31b
|
||||
api_base: https://api.tinfoil.sh/v1
|
||||
api_key: os.environ/TINFOIL_API_KEY
|
||||
|
||||
- model_name: llama3-3-70b
|
||||
litellm_params:
|
||||
model: openai/llama3-3-70b
|
||||
api_base: https://api.tinfoil.sh/v1
|
||||
api_key: os.environ/TINFOIL_API_KEY
|
||||
|
||||
# OpenRouter — fallback for frontier models (Claude, GPT)
|
||||
- model_name: claude-sonnet
|
||||
litellm_params:
|
||||
model: openrouter/anthropic/claude-sonnet
|
||||
api_base: https://openrouter.ai/api/v1
|
||||
api_key: os.environ/OPENROUTER_API_KEY
|
||||
|
||||
- model_name: gpt-4o
|
||||
litellm_params:
|
||||
model: openrouter/openai/gpt-4o
|
||||
api_base: https://openrouter.ai/api/v1
|
||||
api_key: os.environ/OPENROUTER_API_KEY
|
||||
|
||||
# Ollama (self-hosted, free) — if running on same Cloudron
|
||||
- model_name: ollama-qwen
|
||||
litellm_params:
|
||||
model: ollama/qwen3.5:7b
|
||||
api_base: http://127.0.0.1:11434
|
||||
api_key: "ollama"
|
||||
|
||||
# Fallback routing: try Tinfoil first, fall back to OpenRouter
|
||||
router_settings:
|
||||
routing_strategy: simple-shuffle
|
||||
num_retries: 2
|
||||
timeout: 30
|
||||
fallbacks:
|
||||
- gpt-oss-120b:
|
||||
- gpt-4o
|
||||
|
||||
# General settings
|
||||
general_settings:
|
||||
master_key: os.environ/LITELLM_MASTER_KEY
|
||||
database_url: os.environ/DATABASE_URL
|
||||
store_model_in_db: true
|
||||
|
||||
litellm_settings:
|
||||
salt_key: os.environ/LITELLM_SALT_KEY
|
||||
drop_params: true
|
||||
num_threads: 4
|
||||
request_timeout: 30
|
||||
YAML
|
||||
echo "Config written to $CONFIG_FILE"
|
||||
fi
|
||||
|
||||
# --- Start LiteLLM ---
|
||||
echo "Starting LiteLLM on port 4000..."
|
||||
exec litellm --config "$CONFIG_FILE" --port 4000 --host 0.0.0.0
|
||||
Reference in new issue
Block a user