LiteLLM
Every agent stack on a host wants a provider key, and each copy of a key is one more place it can leak from. LiteLLM holds them all behind an OpenAI-compatible proxy, and hands each agent a virtual key with its own budget and model list, revocable without touching the provider.
In Kaio that means the real keys live in one stack’s secrets, and the other stacks only ever see a virtual key.
1. Write the Compose file
Section titled “1. Write the Compose file”services: litellm: image: docker.litellm.ai/berriai/litellm:${LITELLM_TAG:-main-stable} restart: unless-stopped environment: DATABASE_URL: postgresql://litellm:${POSTGRES_PASSWORD}@db:5432/litellm LITELLM_MASTER_KEY: ${LITELLM_MASTER_KEY} LITELLM_SALT_KEY: ${LITELLM_SALT_KEY} STORE_MODEL_IN_DB: "True" ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY} OPENAI_API_KEY: ${OPENAI_API_KEY} ports: - "127.0.0.1:4000:4000" networks: - default - llm depends_on: db: condition: service_healthy healthcheck: test: - CMD-SHELL - python3 -c "import urllib.request; urllib.request.urlopen('http://localhost:4000/health/liveliness')" interval: 30s timeout: 10s retries: 3 start_period: 40s
db: image: docker.io/library/postgres:16 restart: unless-stopped environment: POSTGRES_DB: litellm POSTGRES_USER: litellm POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} volumes: - db:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -d litellm -U litellm"] interval: 2s timeout: 5s retries: 10
networks: llm: name: llm
volumes: db:STORE_MODEL_IN_DBkeeps the model list in Postgres, edited from the admin UI, so the stack needs noconfig.yamlbeside it. A file next to the Compose file would be a bind mount, and a copy leaves bind mounts behind.- The
llmnetwork has a fixed name so other stacks can join it. LiteLLM answers there ashttp://litellm:4000, and the database stays on the stack’s own network, out of their reach. - Port 4000 on the loopback is for you and the admin UI; agents use the network.
2. Write its variables
Section titled “2. Write its variables”LITELLM_TAG=main-stablePOSTGRES_PASSWORD=generate-with-openssl-rand-hex-32LITELLM_MASTER_KEY=sk-generate-with-openssl-rand-hex-32LITELLM_SALT_KEY=sk-generate-with-openssl-rand-hex-32ANTHROPIC_API_KEY=sk-ant-...OPENAI_API_KEY=sk-...Every one but the tag is flagged as a secret
by its name. LITELLM_SALT_KEY encrypts the provider credentials stored in the
database and cannot be rotated once models are added: the stack versions
keep it, and a backup of Kaio’s database is now also
a backup of that key.
3. Deploy it
Section titled “3. Deploy it”kaio-cli stack deploy litellm ./compose.yml --env-file .envkaio-cli stack logs litellm --followThe admin UI answers on http://localhost:4000/ui, logged in with the master
key. Add the models there.
4. Give an agent a virtual key
Section titled “4. Give an agent a virtual key”curl -s http://localhost:4000/key/generate \ -H "Authorization: Bearer $LITELLM_MASTER_KEY" \ -H "Content-Type: application/json" \ -d '{"key_alias": "hermes", "max_budget": 20}'The agent’s stack joins the network and carries that key, never a provider’s. For the Hermes Agent stack, the key goes in as a variable:
services: hermes: environment: - LITELLM_VIRTUAL_KEY=${LITELLM_VIRTUAL_KEY} networks: - default - llm
networks: llm: external: trueand Hermes is told where to find it, in /opt/data/config.yaml:
model: default: claude-sonnet provider: custom base_url: http://litellm:4000/v1 key_env: LITELLM_VIRTUAL_KEYdefault is a model name as you entered it in LiteLLM’s UI. key_env makes
Hermes read the key from the environment, so it stays a Kaio secret rather
than a line in the volume. Other agents take an OpenAI-compatible endpoint
under their own setting names: check their documentation for the base URL.
A leaked virtual key is revoked in the UI, and the agent stack gets the new one
with stack env set and stack apply.
5. Run it day to day
Section titled “5. Run it day to day”kaio-cli stack check-update litellm # did main-stable move?kaio-cli stack update litellm --waitkaio-cli stack scan litellmkaio-cli stack rollback litellm 3With --wait, the update answers only once LiteLLM passes its
/health/liveliness check, and puts back the images it ran before when it does
not get there, so a broken main-stable never stays in front of the agents.
A rollback restores the Compose file and its variables, keys included, but not the database: models and virtual keys created since stay where they are.
Deploy this stack before the ones that join llm: it is the one that creates
the network, and an external network has to exist when a stack comes up.
Kaio, built by Régis Gaidot