Skip to content

AI gateway (aigw)

One place for everything that uses the local AI: a LiteLLM gateway in front of both Ollama servers, and the AI apps next to it, in the community-scripts Podman LXC aigw on node04. Deployed by ansible-playbook playbooks/aigw.yml (role aigw, also part of site.yml; Semaphore template aigw).

apps / scripts / you ── key ──▶ LiteLLM  https://aigw.home.janwiebe.eu/v1  (OpenAI API)
                                   │ order 1                 │ order 2 (after a failure)
                                   ▼                         ▼
                      ollama-amd-64gb (2× V620)    ollama-nvidia-20gb (3080 + RTX 4000)
LXC aigw on node04, community-scripts Podman
Gateway https://aigw.home.janwiebe.eu/v1 (Traefik → :4000), UI at /ui (user admin)
Keys one per client, in /etc/aigw/keys/<name> on the LXC; usage per key in the UI
Secrets /etc/aigw/ (0700): master key, UI password, Postgres password — never in the repo

Apps in the LXC

All apps talk to http://litellm:4000/v1 with their own key. Their images come from ghcr.io/jwklijnsma/<app> and update daily through podman auto-update.

App URL Published port Model
helmreview https://helmreview.home.janwiebe.eu 8766 qwen3-coder:30b
ansreview https://ansreview.home.janwiebe.eu 8765 qwen3-coder:30b
fixplan https://fixplan.home.janwiebe.eu 8767 qwen3-coder:30b
docpipe https://docpipe.home.janwiebe.eu 8770 qwen3-coder:30b
lorekeeper https://lorekeeper.home.janwiebe.eu 8771 qwen3:30b-a3b + nomic-embed-text
vulnboard https://vulnboard.home.janwiebe.eu 8772 qwen3-coder:30b

Web UI tokens: /etc/aigw/apps/<app>.token on the LXC (open https://<app>…/?token=<token>). Repositories for the review apps go in /srv/git (seen as /repos); lorekeeper also indexes /srv/docs. vulnboard scans the images running in this LXC (no cluster here).

Outside the LXC: labscout (node09) uses the gateway with key labscout (roles/labscout switches automatically once /etc/aigw/keys/labscout exists), local-autofix with backend: openai and key local-autofix, and key jan is yours for curl, Open WebUI or scripts.

How routing works

  • Every model on every Ollama server becomes a deployment, named by its Ollama tag (qwen3-coder:30b). The role reads /api/tags on both servers at every run, so a newly pulled model shows up after the next deploy.
  • A model on both servers: the V620s (order: 1) take all traffic while healthy; the NVIDIA host (order: 2) only gets a request after the V620s failed for it. A model on one server goes there directly.
  • num_ctx from the app wins; without one the gateway sets 32768.
  • nomic-embed-text is pulled on the V620s when missing (lorekeeper needs it).

Using it yourself

KEY=$(pct exec <vmid> -- cat /etc/aigw/keys/jan)      # on node04
curl -s https://aigw.home.janwiebe.eu/v1/models -H "Authorization: Bearer $KEY"
curl -s https://aigw.home.janwiebe.eu/v1/chat/completions -H "Authorization: Bearer $KEY" \
  -H 'Content-Type: application/json' \
  -d '{"model": "qwen3-coder:30b", "messages": [{"role": "user", "content": "hi"}]}'

Any OpenAI client works: base URL https://aigw.home.janwiebe.eu/v1, the key as API key. A new client: add its name to aigw_extra_keys and run the playbook.

Troubleshooting

pct enter <vmid>
systemctl status litellm aigw-postgres helmreview      # one unit per container
journalctl -u litellm -f                               # which server answered, errors
podman ps                                              # health of every container
  • 401 from the gateway: wrong key, or the key was not registered — rerun the playbook.
  • A model is missing: it is not on either Ollama server, or that server was down during the last run (the play says so) — rerun the playbook.
  • Everything slow: check the Ollama servers themselves (OllamaModelOnCpu, Ollama); the gateway adds milliseconds, not seconds.