Featured project · part 2 of 3 · follows Local AI gateway

💬 Local AI: add a chat UI

Add Open WebUI — a polished ChatGPT-style frontend — to the same Docker stack you built in part 1. New tailnet hostname for chat; the API hostname keeps working unchanged. Pure addition, no re-wiring.

Featured AI/ML Intermediate ~30 min Prereqs: Local AI gateway (part 1)

Why this project

Part 1 left you with a working private API. Great for scripts and editor tools, awkward for actual chat. curl doesn't remember conversations, can't switch models mid-thread, isn't fun to use on a phone.

Open WebUI is a self-hosted ChatGPT-style UI that speaks the OpenAI-compatible API LiteLLM is already exposing. The clean way to add it: drop two more containers into the same compose file (Open WebUI itself, plus a second Tailscale sidecar for the chat hostname). Nothing about part 1's API endpoint changes — you just gain a second URL for chat.

👤Who this helps

  • You completed part 1 and now want a real interface, not curl
  • You want chat history, model switching, and system prompts persisted across sessions
  • You want the same chat on your phone, your work laptop, your iPad — all over the tailnet
  • You're considering letting family use the local AI but don't want to teach them an API

🎁What you get

  • Open WebUI running on the same private network as your engine + LiteLLM
  • A second tailnet hostname — https://ai-chat.tail-abc.ts.net — for the chat UI
  • The API hostname from part 1 still works for scripts and editor tools, unchanged
  • Multi-conversation history, model picker, system prompt presets — all stored locally

📋Prerequisites

  • Local AI gateway (part 1) running — engine, LiteLLM, ts-ai sidecar all up
  • The ~/local-ai/docker-compose.yml + .env files from part 1

Mental model

Two more containers join the private Docker network: Open WebUI (the chat app itself) and ts-chat (a second Tailscale sidecar that exposes Open WebUI under its own tailnet hostname). Open WebUI becomes one of LiteLLM's clients, just like any other OpenAI-compatible app.

CLIENTS PRIVATE EDGE DOCKER STACK 📜 / 🛠️ API clientsscripts · Continue · Aider 📱 / 💻 browser userschat over tailnet 🔒 ts-ai sidecarhttps://ai-rig.tail-abc.ts.net (from part 1) 🔒 ts-chat sidecar (NEW)https://ai-chat.tail-abc.ts.net PRIVATE DOCKER NETWORK 💬 Open WebUI (NEW)port 8080 · chat UI · stores history via virtual key 🔀 LiteLLM proxy (from part 1)port 4000 · master key + virtual keys 🦙 Ollama / ⚡ llama.cpp (from part 1)

Two new containers (highlighted with NEW). LiteLLM and the engine from part 1 are unchanged. The two sidecars expose two different tailnet hostnames; both ultimately terminate at LiteLLM, which terminates at the engine.

Steps

Six steps. Enable LiteLLM's key database, mint a virtual key for Open WebUI to use, mint a second Tailscale auth key for the chat sidecar, write the chat sidecar's serve config, add two services to the compose file, claim admin and verify.

Enable LiteLLM's key database ~3 min

Virtual keys live in a database. Part 1 didn't set one up — the master key alone was enough. Open WebUI will use a virtual key, so we need to wire that up now. (Part 3 leans on this same setup for friend keys, so you're getting a head start.)

LiteLLM's standard image expects Postgres — its Prisma migrations are Postgres-flavored and don't apply cleanly to SQLite. Add a tiny Postgres sidecar to your compose file. It runs alongside Ollama and LiteLLM on the same private network; nothing is exposed to the host or the tailnet.

Edit ~/local-ai/docker-compose.yml. Add this db service alongside your existing services, and add a top-level volumes section if you don't have one yet:

services:
  # ... existing ts-ai, litellm, ollama ...

  db:                                                  # NEW
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: litellm
      POSTGRES_PASSWORD: litellm
      POSTGRES_DB: litellm
    volumes:
      - litellm-db:/var/lib/postgresql/data
    networks: [ai-net]
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U litellm"]
      interval: 5s
      retries: 10

volumes:
  litellm-db: {}                                       # NEW (top-level)

Then update the litellm service block to know about the database. The existing depends_on: [ollama] (short list form) is incompatible with adding a healthcheck-gated dependency, so convert it to the long object form below — both entries together:

  litellm:
    # ... existing config ...
    environment:
      - LITELLM_MASTER_KEY=${LITELLM_MASTER_KEY?required}
      - DATABASE_URL=postgresql://litellm:litellm@db:5432/litellm   # NEW
    depends_on:                                        # REPLACES [ollama] short form
      ollama:
        condition: service_started      # same behavior as the old list form
      db:
        condition: service_healthy      # wait for pg_isready before booting

Don't add a database_url line to litellm-config.yaml. Prisma reads DATABASE_URL directly from the container's environment, and LiteLLM does the same — putting the URL in both places causes a known startup bug where the YAML value (literally os.environ/DATABASE_URL) gets re-exported over the env var, and Prisma then fails validation with "the URL must start with postgresql://". Compose env wins; leave the YAML alone.

general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY
  # database_url intentionally NOT here — env var alone is correct

Bring up the new service and recreate LiteLLM:

cd ~/local-ai
docker compose up -d
docker compose logs --tail=30 litellm
# Look for "Applied migration(s)..." (Prisma running schema setup on first boot)
# and "Application startup complete." with no DB errors.

Why Postgres for a home setup? Overkill on the surface, but the LiteLLM image ships with Postgres-flavored migrations baked in. Trying to use SQLite leaves the schema half-applied — the connection succeeds but tables are missing, which presents as the (misleading) "DB not connected" error. Postgres is the documented happy path and the container footprint is small (~30 MB image, idle CPU).

Mint a virtual key for Open WebUI ~3 min

Open WebUI will talk to LiteLLM as a client. We could give it the master key, but cleaner is to give it its own virtual key — that way you can revoke or rotate Open WebUI's access independently.

# From the home server (or any tailnet device with curl access):
curl -X POST https://ai-rig.tail-abc.ts.net/key/generate \
  -H "Authorization: Bearer sk-your-master-key" \
  -H "Content-Type: application/json" \
  -d '{"models": ["llama-3.2-3b"], "key_alias": "open-webui"}'

# Returns: { "key": "sk-...", ... }

Save that sk- key — it goes in the next step's env vars.

If you see "DB not connected", the previous step didn't take. Confirm database_url is in litellm-config.yaml, that the litellm container restarted, and that docker compose logs litellm shows no DB errors at startup.

Mint a second Tailscale auth key (for ts-chat) ~2 min

The new chat sidecar registers as its own tailnet device, so it needs its own auth key. Admin console → Settings → Auth keys → Generate. Single-use is fine; tag it tag:ai (same as ts-ai).

Append to your existing ~/local-ai/.env:

TS_AUTHKEY_CHAT=tskey-auth-XXXXX
OPENWEBUI_KEY=sk-virtual-key-from-step-1

Write the ts-chat serve config ~2 min

Create ~/local-ai/serve-config-chat.json. Same shape as the part 1 serve config, but forwards to open-webui instead of litellm:

{
  "TCP": { "443": { "HTTPS": true } },
  "Web": {
    "${TS_CERT_DOMAIN}:443": {
      "Handlers": { "/": { "Proxy": "http://open-webui:8080" } }
    }
  }
}

Append two services to the compose file ~5 min

Open ~/local-ai/docker-compose.yml and add these inside the existing services: block (don't replace anything from part 1):

  open-webui:
    image: ghcr.io/open-webui/open-webui:main
    environment:
      - OPENAI_API_BASE_URL=http://litellm:4000/v1
      - OPENAI_API_KEY=${OPENWEBUI_KEY?required}
      - WEBUI_URL=https://ai-chat.tail-abc.ts.net
    volumes:
      - open-webui-data:/app/backend/data
    restart: unless-stopped
    networks: [ai-net]
    depends_on: [litellm]

  ts-chat:
    image: tailscale/tailscale:latest
    hostname: ai-chat
    environment:
      - TS_AUTHKEY=${TS_AUTHKEY_CHAT?required}
      - TS_EXTRA_ARGS=--advertise-tags=tag:ai
      - TS_SERVE_CONFIG=/config/serve.json
      - TS_STATE_DIR=/var/lib/tailscale
    volumes:
      - ts-chat-state:/var/lib/tailscale
      - ./serve-config-chat.json:/config/serve.json
      - /dev/net/tun:/dev/net/tun
    cap_add: [net_admin, sys_module]
    restart: unless-stopped
    networks: [ai-net]
    depends_on: [open-webui]

Add the new volume to the bottom volumes: block:

volumes:
  ts-state:
  ollama-models:
  open-webui-data:    # NEW
  ts-chat-state:      # NEW

Bring up the new pieces (existing services are unaffected):

docker compose up -d
docker compose logs -f ts-chat
# Watch for the same registration lines as part 1's ts-ai logs:
#   active login: ai-chat.<your-tailnet>.ts.net
#   Switching ipn state Starting -> Running
#   serve: creating a new proxy handler for http://open-webui:8080
#   Startup complete, waiting for shutdown signal

Claim the admin account, verify chat ~5 min

From your laptop, navigate to https://ai-chat.tail-abc.ts.net. Open WebUI's setup screen appears.

Claim the admin account immediately. Open WebUI uses "first user becomes admin" as bootstrap auth. Even though your tailnet ACL gates the URL, you want to own the admin account before anyone else lands on it.

  1. Create your admin account with a real password.
  2. You should land in the chat UI. The model picker (top of the page) shows the models you've configured in LiteLLM.
  3. Pick a model, type a message, get a response.
  4. From your phone (also on the tailnet), navigate to the same URL. Sign in with the admin account. Same conversations, same models.

Reference

✓Verify

  • Open WebUI loads at https://ai-chat.tail-abc.ts.net from your phone
  • The model picker lists every model you have in LiteLLM's config
  • Chat conversations persist across page reloads
  • Part 1's API hostname (https://ai-rig.tail-abc.ts.net) still responds to curl with the master key — chat addition didn't break the API
  • Off-tailnet visitors can't reach either hostname

⚠Common issues

  • Model picker empty — Open WebUI can't reach LiteLLM, or LiteLLM rejected the virtual key. Test from inside the container: docker compose exec open-webui curl -H "Authorization: Bearer $OPENAI_API_KEY" http://litellm:4000/v1/models.
  • "Server error" sending a message — virtual key minted with a model whitelist that excludes the model you're chatting with. Re-mint with the right "models" array, or use the master key while debugging.
  • ts-chat says "auth failed" — auth key wrong, expired, or already used. Mint a fresh single-use key.
  • Chat hostname doesn't resolve — MagicDNS needs a moment after the new tailnet device registers. Try the full hostname; tailscale status from another device should list ai-chat.

⚐Caveats

  • Open WebUI's first-user-becomes-admin is the bootstrap auth. The tailnet ACL gates who can reach the signup page, but once they're at the page they could claim admin. Claim the admin account immediately after first deploying.
  • The virtual key Open WebUI uses is in the env file with whatever permissions you minted it. If a family member compromises the Open WebUI account, they have whatever access that key has. Mint with a sensible model whitelist.
  • Streaming responses come for free here — Open WebUI uses SSE by default, and Tailscale Serve passes it through without buffering.

Variations

Routing

Single hostname with path mounting

Instead of two hostnames (api + chat), put both behind https://ai-rig.tail-abc.ts.net using path-based routing. Works but Open WebUI generally expects to live at the document root, so this needs more careful Serve config and reverse-proxy headers. Two hostnames is the cleaner default.

Capability

Built-in RAG (document chat)

Open WebUI has document upload + retrieval baked in. Upload files in the UI's settings; it handles chunking and retrieval automatically. See the RAG pipeline project for a from-scratch alternative if you want custom logic.

Multi-user

Per-user chat accounts for family

Open WebUI's signup flow can be restricted post-admin-claim. Add accounts for family members; each gets their own chat history. Pair with stricter ACLs to limit who can hit the chat URL in the first place.

Mobile

Install as a phone app (PWA)

Add Open WebUI to your phone's home screen via "Add to Home Screen" in the browser share menu. Behaves like a native app — full-screen, app icon, no browser chrome — and still goes over the tailnet.

Where this leads

You and your devices can chat with your local AI. But what if you want friends to use it without inviting them to your tailnet? Or transparent cloud fallback when local is down or too slow? Or a single endpoint that mixes local + cloud models with per-user keys? That's part 3 — and it's purely configuration changes to the LiteLLM you already have. No new components, no rewiring.

→
Part 3 of 3 · Featured · advanced
🔀 Local AI: multi-user, cloud fallback, friend access
All config evolution. Add fallback rules, mint virtual keys for friends, point editor tools at the same endpoint.
›

Other follow-ups: