Skip to content

LiteLLM

LiteLLM is a lightweight proxy that allows us to expose various LLM providers (Mistral, OpenCode Zen, etc.) via a single OpenAI-compatible API. It includes a management UI, a Postgres database for state persistence (keys, models), and native support for MCP (Model Context Protocol) servers.

ServicePortProtocolDescription
API / UI14000HTTPOpenAI API & Management Dashboard
Database5432TCPInternal Postgres 16 (Localhost only)

The service is available internally at http://<homelab-ip>:14000 and externally via Nginx proxy at https://litellm-home.javiersc.com. The UI is protected by credentials stored in 1Password.

Currently configured models in config.yaml:

  • mistral-small: Proxies to Mistral AI (mistral-small-latest).
  • big-pickle: Proxies to OpenCode Zen (big-pickle model).

LiteLLM uses a Postgres 16-alpine container for persistence. This allows it to store:

  • API Keys and usage tracking.
  • Model configurations.
  • MCP server registry.

The database is only accessible from localhost and uses the MASTER_KEY as the password for the litellm user.

LiteLLM connects to Home Assistant as an MCP server.

To use tools via the API, you must use the specialized LiteLLM MCP format. Using standard OpenAI tool definitions will cause a 400 Bad Request error from the upstream provider.

Terminal window
curl http://localhost:14000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer scarves8blanche.LOAD" \
-d '{
"model": "big-pickle",
"messages": [{"role": "user", "content": "Dime qué hay en la lista de la compra"}],
"tools": [
{
"type": "mcp",
"server_url": "litellm_proxy/mcp/home_assistant",
"server_label": "home_assistant",
"require_approval": "never"
}
]
}'
  • type: "mcp": Forces the proxy to intercept the tool call.
  • server_url: Must be litellm_proxy/mcp/<server_id>.
  • require_approval: "never": Required for automatic execution.

Secrets are fetched by litellm-secrets.service (using homelab.mkSecretService) into /run/litellm/env at boot, then litellm-config.service renders config.yaml and container environment files. No secrets are stored in the Nix store.

Secret1Password PathDescription
MISTRAL_API_KEYop://Homelab/PicoClaw - Mistral AI Token/credentialMistral AI API Key
OPENCODE_ZEN_TOKENop://Homelab/OpenCode - Zen Token/credentialOpenCode Zen API Key
MASTER_KEYop://Homelab/LiteLLM - Master Key/credentialUsed for DB auth and encryption
UI_USERop://Homelab/Homelab/usernameAdmin UI Username
UI_PASSop://Homelab/Homelab/passwordAdmin UI Password
HA_TOKENop://Homelab/Home Assistant - OpenClaw Token/credentialHA MCP Access Token
  • State Directory: /var/lib/litellm (persistent data).
  • Database Directory: /var/lib/litellm/postgres (Postgres data).
  • Runtime Configs: /run/litellm/ (generated config.yaml, litellm.env, db.env — RAM-based, regenerated on boot).
  • Backup Status: /var/lib/litellm is included in daily Restic backups. /run/litellm/ is excluded (tmpfs).

LiteLLM follows a three-stage startup chain: litellm-secretslitellm-configpodman-litellm + DB.

Terminal window
sudo systemctl restart litellm-secrets litellm-config podman-litellm-db podman-litellm
Terminal window
# Secret fetching & config rendering
sudo journalctl -u litellm-secrets -f
sudo journalctl -u litellm-config -f
# Main LiteLLM logs
sudo journalctl -u podman-litellm -f
# Database logs
sudo journalctl -u podman-litellm-db -f