Skip to content

AI

The cluster runs no models of its own. Everything AI goes through one gateway, LiteLLM in the ai namespace, which forwards model calls to hosted providers and MCP calls to a set of MCP servers. Apps and workstations hold a scoped LiteLLM key, never a provider key. Per-server details and gotchas are in App Notes.

Overview

graph LR
    cc(Claude Code / Desktop<br/>on a Mac) -->|litellm.bykaj.app/mcp/| int[envoy-internal]
    int --> proxy[LiteLLM proxy]
    phone(Browser / Hermes app) -->|chat.bykaj.app| int2[envoy-internal]
    int2 --> hermes[Hermes]
    hermes -->|litellm.ai.svc:4000<br/>/v1 and /mcp/| proxy
    apps(Karakeep, Paperless, Windshift,<br/>Seafile, kguardian) -->|litellm.ai.svc:4000/v1| proxy
    proxy --> models[(MiniMax, OpenAI)]
    proxy --> mcp[MCP servers]
    proxy --- pg[(Postgres)]
    proxy --- df[(Dragonfly)]
    op[litellm-operator] -.->|reconciles CRs| proxy
  • Apps in the cluster call the proxy's Service directly (http://litellm.ai.svc.cluster.local:4000/v1, OpenAI-compatible).
  • Workstations reach it at https://litellm.bykaj.app, which only has a route on envoy-internal. They use it for MCP only.
  • Admin UI logins go through Pocket ID; the API and /mcp/ take keys (see App Notes).

Everything is declared as custom resources of the litellm-operator, which runs from its own folder, kubernetes/apps/ai/litellm-operator (Flux Kustomization litellm-operator: the operator HelmRelease and its CRDs). Apps that declare their own LiteLLM keys depend on it. The proxy is split over two Flux Kustomizations in kubernetes/apps/ai/litellm:

Kustomization Path Contents
litellm app/ LiteLLMProxy, models, egress policy, ServiceMonitor, Postgres (postgres), cache (dragonfly) and the ChatGPT token volume (kopiur)
litellm-mcp mcp/ MCP servers, the claude-code team and key, and the hermes team

Postgres holds keys, teams, users and spend; Dragonfly is the response cache and router state. Models and MCP servers are file-backed (store_model_in_db: false): Git is the only source, and anything added in the Admin UI is lost on the next reconcile.

Models

Each model is a LiteLLMModel under app/models/<provider>/, named <provider>/<model> in LiteLLM (the name clients and keys use). Provider API keys come from the litellm 1Password item through litellm-secret; the ChatGPT models sign in with a login instead (see below).

Provider Models Notes
ChatGPT gpt-6-astra, gpt-6-luna, gpt-6.1-sol The OpenAI row's GPT-6 models, billed to the ChatGPT Plus subscription instead of OPENAI_API_KEY; see ChatGPT subscription
MiniMax MiniMax-M3, MiniMax-M3.1-Flash Each twice: plain names use MiniMax's OpenAI-compatible API (/v1, with reasoning_split), -anthropic names its Anthropic-compatible API (/anthropic)
OpenAI GPT-6 Astra/Luna, GPT-6.1 Sol, gpt-4.1-mini, gpt-4o-mini, text-embedding-3-small GPT-6 models use the Responses API and drop temperature

The MiniMax models have prompt-cache injection points for the system prompt and the last message; OpenAI caches prompts automatically.

Spend in the Admin UI comes from LiteLLM's bundled cost map (offline mode, see App Notes), which has no prices for the anthropic/ routes, MiniMax-M3.1-Flash or M3's price tier above 512K input tokens. The MiniMax models therefore set MiniMax's official prices themselves (input_cost_per_token, output_cost_per_token, cache_read_input_token_cost and the _above_512k_tokens variants in params.additional); update them when MiniMax changes its pricing. The chatgpt/ models log $0, because the subscription isn't billed per token. Instead, the Plus fee ($20 a month from the 20th) is a subscription account on the ChatGPT account, counted once per billing period. It's set in the Admin UI and lives only in the database: neither the config nor the operator can manage subscription accounts yet.

ChatGPT subscription

The chatgpt/ models use LiteLLM's ChatGPT provider, which signs in to the ChatGPT Plus account through the Codex OAuth flow instead of using an API key. Usage counts against the subscription's rolling and weekly limits, not API billing. The provider calls chatgpt.com (Codex backend) and auth.openai.com (token refresh), which litellm-egress allows. The Codex backend adds its own system prompt to every request and ignores response_format and output token limits, so structured output comes only from the client's prompt.

The login lives in auth.json in CHATGPT_TOKEN_DIR (/app/chatgpt_tokens), on the litellm PVC, backed up hourly by Kopiur. The proxy rewrites the file whenever it refreshes the access token, and the refresh token is single-use, so the file has to be on writable storage that survives restarts: a copy kept anywhere else (1Password, a Secret) goes stale at the first refresh. The proxy can't run the device-code login itself, so the file is created on a workstation and copied in:

  1. Sign in, which prints a URL and a code to enter there; it writes ~/.config/litellm/chatgpt/auth.json:

    uvx --from litellm python -c \
      "from litellm.llms.chatgpt.authenticator import Authenticator; Authenticator().get_access_token()"
    
  2. Copy it onto the volume and restart the proxy, which only loads a deployment's login at startup:

    kubectl -n ai cp ~/.config/litellm/chatgpt/auth.json \
      "$(kubectl -n ai get pod -l app.kubernetes.io/name=litellm -o name | cut -d/ -f2)":/app/chatgpt_tokens/auth.json
    kubectl -n ai rollout restart deployment litellm
    
  3. Delete the local copy (~/.config/litellm/chatgpt/auth.json); the cluster copy is the only one that stays current.

Do the same when the proxy logs ChatGPT refresh token failed, re-login required. Without a valid file, requests to the chatgpt/ models fail with There are no healthy deployments for this model.

Keys and teams

Nobody gets the master key. Every client has its own LiteLLMVirtualKey, which the operator creates through the proxy's admin API and writes to a Secret (api-key) next to the CR. The key's models list is what the client may call.

Key Lives in Models MCP
claude-code ai (team claude-code) none all servers except flux and kagi
hermes ai/hermes (team hermes) chatgpt/gpt-6-luna, chatgpt/gpt-6.1-sol, minimax/MiniMax-M3, minimax/MiniMax-M3.1-Flash all servers
karakeep default/karakeep chatgpt/gpt-6-luna, openai/text-embedding-3-small —
kguardian observability/kguardian minimax/MiniMax-M3-anthropic —
paperless default/paperless chatgpt/gpt-6-luna, openai/text-embedding-3-small —
seafile default/seafile chatgpt/gpt-6-luna, openai/text-embedding-3-small —
windshift default/windshift minimax/MiniMax-M3 —
  • Consumer keys are declared in the consuming app's own app/ folder, with proxyNamespace: ai. The app reads the Secret by secretKeyRef, except Windshift, where the key is pasted into its AI Connection settings.
  • Consumer apps depend on litellm-operator, not litellm, on purpose: they only need the CRD, and depending on the proxy would hold back every reconcile of the app while LiteLLM, its Postgres or Dragonfly is unhealthy. On a fresh install the key waits for the proxy and Flux retries. kguardian is the exception: it depends on litellm, which is accepted as is.
  • MCP access is granted per team: a key gets no MCP servers unless its team lists them, and the operator has no per-tool allowlist. The claude-code team lists every server except flux, kagi and kubectl, and the model no-default-models, which matches nothing, so its key can't spend money. kagi is paid per search and Claude Code has its own web search, so only the hermes team gets it.
  • Cluster access (the flux server, which can fix things, and the read-only kubectl server) only goes to the hermes team, the agent used for ops work. Claude Code on the Macs has kubectl and flux itself and doesn't get them.

MCP servers

All MCP servers sit behind the proxy at /mcp/, so a client needs one URL and one key for all of them. Tools appear as <server>-<tool>.

Server Runs Reaches
context7 Context7's hosted server mcp.context7.com, bearer key from the litellm item
flux Operator-run pod (flux-operator-mcp) The Kubernetes API as ServiceAccount flux-mcp; see below
home_assistant Operator-run pod (ha-mcp) Home Assistant, as a dedicated user
kagi Kagi's hosted server mcp.kagi.com, bearer key from the litellm item; only the hermes team has it
kguardian kguardian's own llm-bridge observability/kguardian-llm-bridge:8080, no auth
kubectl Operator-run pod (kubectl-mcp-server, --read-only) The Kubernetes API as ServiceAccount kubectl-mcp, with the same read-only roles as flux (view and flux-mcp-read); only the hermes team has it
kubesearch Operator-run pod kubesearch.dev and GitHub clones (reference repos always cloned)
unifi_network Operator-run pod The UniFi gateway, as a dedicated local account

Operator-run servers are LiteLLMMCPServer resources with a workload and listen on port 3000; each has a network policy that admits only the proxy. Agents use kubesearch first and Context7 only as a fallback (AGENTS.md).

Fixing the cluster through an agent

The flux server runs flux-operator-mcp with its write tools on: reconcile, suspend and resume Flux objects, apply a manifest, delete a resource. The Flux controllers deploy whatever a Flux object points at as cluster-admin, so a free patch to one (another repo URL, path or values) would be cluster-admin too. What the server may do is therefore limited in the cluster, in mcp/servers/flux:

Layer Allows
flux-mcp-read and view get, list and watch on everything troubleshooting needs, pod logs included; no Secrets, pods/exec, port-forward, node proxy or ServiceAccount tokens
flux-mcp-operate patch on Kustomizations, HelmReleases and sources, patch on Deployments and StatefulSets, delete on pods. No create anywhere, and no Flux object can be deleted (that would prune the app, PVCs included)
flux-mcp-flux-objects (VAP) On Flux objects only the reconcile.fluxcd.io/* annotations (reconcile, force, reset) and spec.suspend may change
flux-mcp-workloads (VAP) On Deployments and StatefulSets only spec.replicas and the pod template's kubectl.kubernetes.io/restartedAt annotation (rollout restart) may change

That covers reconciling, suspending and resuming, forcing a stuck HelmRelease, scaling an app back up after a resume (which keeps a manual scale), restarting a workload and deleting a stuck pod. Anything that loses data or can't be undone (deleting a PVC, a Kopiur cache, a Flux object) stays a job for a workstation. Both admission policies only match system:serviceaccount:ai:flux-mcp.

Check the policies with a server-side dry run as the ServiceAccount; admission runs on dry runs too:

SA=system:serviceaccount:ai:flux-mcp
# allowed
kubectl -n default annotate kustomization paperless --as=$SA --dry-run=server --overwrite \
  reconcile.fluxcd.io/requestedAt="$(date +%s)"
kubectl -n default patch kustomization paperless --as=$SA --dry-run=server --type merge -p '{"spec":{"suspend":true}}'
kubectl -n default patch deployment paperless --as=$SA --dry-run=server --type merge -p '{"spec":{"replicas":1}}'
# denied
kubectl -n default patch kustomization paperless --as=$SA --dry-run=server --type merge -p '{"spec":{"path":"./x"}}'
kubectl -n default patch deployment paperless --as=$SA --dry-run=server --type json \
  -p '[{"op":"replace","path":"/spec/template/spec/containers/0/image","value":"busybox"}]'

Hermes

Hermes is a self-hosted agent that runs all the time, in kubernetes/apps/ai/hermes: chat from a browser or an app, scheduled jobs, memory, skills and a local shell in its own pod. The web app is https://chat.bykaj.app, the admin dashboard https://hermes.bykaj.app, both on envoy-internal only, so away from home they need One-Click VPN (UniFi Endpoint app). Both sign in through Pocket ID (see App Notes).

The apps connect to the web app's address: Hermes Desktop on the Macs, and Hermex (a community app, 2.1 or later) on iPhone and iPad. They sign in to the gateway in the system browser, and the gateway does the Pocket ID login, so they need nothing in Pocket ID of their own.

It calls models and MCP servers only through LiteLLM's Service, with the hermes key from the pod's environment (LITELLM_API_KEY): its models and every MCP server, flux included. Hermes is the agent for ops work on the cluster, the network and Home Assistant, and the Home Assistant and UniFi servers can already change things, so a second, read-only key would protect nothing. What it can do to the cluster is limited in the cluster itself (see Fixing the cluster through an agent).

/etc/hermes/config.yaml (from app/resources/config.yaml) is a read-only overlay for sign-in, ports and security settings. Everything else lives on the hermes PVC (backed up by Kopiur). Hermes seeds a new default profile (/opt/data/config.yaml) with anthropic/claude-opus-4.6 through OpenRouter, and providers and MCP servers have to live in the profile itself: put in the overlay, every dashboard save strips them from the profile. So the setup init container (app/resources/setup.sh), after running the image's config migration, creates the named profiles listed in HERMES_PROFILES (now ops, under /opt/data/profiles/) if they don't exist yet, and points the default profile and those at LiteLLM with Hermes' own CLI (hermes config set, which keeps the rest of the file and its comments), before the gateway starts:

Setting When
providers.litellm (the proxy's /v1, key_env: LITELLM_API_KEY, model discovery) and mcp_servers.litellm (/mcp/, x-litellm-api-key header, connect_timeout: 120, since a cold tool list through LiteLLM can pass the default 30 s) Every start: Git wins over changes in the dashboard
secrets.command (named profiles only): echo LITELLM_API_KEY=$(cat /mnt/secrets/litellm/api-key) Every start
model.provider: custom:litellm, model.default: chatgpt/gpt-6.1-sol, model.base_url, model.context_length: 272000 Only while the profile doesn't use LiteLLM yet, so a model picked in the dashboard survives restarts

model.context_length is the LiteLLM model's maxInputTokens: Hermes can't read a context length from LiteLLM and would assume 256K. To start the model settings over, set model.provider to anything else and restart. The seed adds about 15 seconds to every start. hermes mcp test litellm (run in the pod with HOME and HERMES_HOME set to /opt/data) lists the tools Hermes gets through the proxy; add -p <profile> for a named one.

The gateway serves every profile from one process (gateway.multiplex_profiles), and to keep their credentials apart a named profile never reads them from the pod's environment, only from its own .env and secret sources. The default profile uses the LITELLM_API_KEY environment variable; the named ones get the same hermes key from the hermes-litellm Secret, mounted at /mnt/secrets/litellm, through the secrets.command helper above, so a key rotation by the operator reaches them on the next start. All profiles share the key and so the same models and MCP servers.

To add a profile, add its name to HERMES_PROFILES in the HelmRelease. Its persona goes in /opt/data/profiles/<name>/SOUL.md (optional, read with every message; without one Hermes uses its default), and scheduled jobs belong to a profile: hermes -p <name> cron create ... with --deliver bot-chat:<name> puts the result in that profile's chat in the web app. Removing a name from the list leaves the profile in place; delete it by hand with hermes profile delete <name>.

The ops profile also talks Signal, through the signal-cli daemon in the same namespace: only the owner may message it (allowed by number and by Signal UUID), and --deliver signal sends a cron report to the owner. Hermes keeps no internet access for this; only signal-cli reaches Signal's servers.

The terminal has mise for installing CLI tools: its binary comes from the ghcr.io/jdx/mise image, mounted as an image volume at /opt/mise, and tools, shims and the global config (/opt/data/.config/mise/config.toml) live on the PVC. The MISE_* directories are fixed in the pod's environment because the terminal's HOME moves into each profile, so every profile shares one install. Downloads may only come from GitHub (see App Notes), so tools that GitHub releases or the aqua registry serve install, and tools from other hosts don't. mise calls GitHub's API without a token, which allows 60 requests an hour.

Network

The proxy holds every provider key, so litellm-egress allows it to reach only DNS, its Postgres and Dragonfly, the MCP servers, Pocket ID, the SMTP relay, GitHub's API and the model providers by FQDN. A blocked attempt fires CiliumEgressPolicyDenied. Why it is this strict is in the LiteLLM compromise write-up.

Workstation setup

Claude Code and Claude Desktop on the Macs use the claude-code key. The key is read from the cluster when needed and never stored in Git.

Claude Code, from the repo (local scope, so the key stays out of the shared .mcp.json):

claude mcp add --scope local --transport http litellm https://litellm.bykaj.app/mcp/ \
  --header "x-litellm-api-key: Bearer $(kubectl -n ai get secret claude-code-litellm -o jsonpath='{.data.api-key}' | base64 -d)"
claude mcp list   # litellm: ✔ Connected

Claude Desktop only runs stdio servers, so it starts a small script (~/.local/bin/litellm-mcp) that reads the key with kubectl, exports it as LITELLM_API_KEY and runs npx mcp-remote <url> --transport http-only --header 'x-litellm-api-key:Bearer ${LITELLM_API_KEY}' from the repo, so the key stays out of the process arguments and the repo's pinned Node is used. The script's absolute path goes under mcpServers.litellm.command in claude_desktop_config.json. Its log is ~/Library/Logs/Claude/mcp-server-litellm.log.

Monitoring

A ServiceMonitor scrapes /metrics with the master key as bearer token (prometheus success callback), which gives request, token and spend metrics per key and model. Spend per key is also in the Admin UI. LiteLLM sends its own email alerts through the SMTP relay.

Changing things

Add a model
Add a LiteLLMModel under app/models/<provider>/ and to that folder's kustomization.yaml. A new provider host also needs a toFQDNs entry in litellm-egress, and its API key a field in the litellm item and externalsecret.yaml. Then add the model to the keys that should use it.
Add an MCP server
Add a folder under mcp/servers/ with a LiteLLMMCPServer (plus a network policy that admits only the proxy and limits its egress). A port other than 3000, or a server outside the operator, needs its own rule in litellm-egress. Then add its alias to the hermes team, and to claude-code unless it can change the cluster. Add a section to App Notes.
Add a consumer app
Add a LiteLLMVirtualKey with proxyNamespace: ai and only the models it needs to the app's app/ folder, read the Secret into the app, point it at http://litellm.ai.svc.cluster.local:4000/v1, and add dependsOn: litellm-operator (namespace ai) to its ks.yaml.
Change litellm-secret
The proxy doesn't restart on Secret changes, and the operator reverts a kubectl rollout restart. After the ExternalSecret has refreshed, delete the litellm pod by its exact name.