Skip to Content
Kai

Backups and operations

What to back up, health checks, logs and keeping the cache healthy.

Backups

Back up three things together:

  1. Postgres — everything except files.
  2. KAI_ENCRYPTION_KEY — without it, every stored API key, MCP credential and OAuth token is unreadable after a restore; people would have to enter them again.
  3. The object storage bucket — attachments and large tool outputs.

Redis holds only short-lived state (run event streams, rate limits, caches) and doesn't need backing up.

Health

GET /api/health returns 200 with {"postgres":true,"redis":true} when both answer. The image's health check uses it.

Logs

Kai writes one JSON line per event to stdout: a line per model request (run, model, stop reason, token counts, time to first token, duration, request id), a line per tool call (server, tool, duration, status), and errors. Secrets and message content are never logged.

The prompt cache

Kai is built so that each model request starts with the previous one, byte for byte, and providers bill most of a long conversation at the cached rate. The Usage page shows the cache hit ratio; it should be high. When a step that should have hit the cache doesn't, Kai logs a cache_miss warning with the conversation id.

Things that legitimately start fresh: changing a chat's model, turning tools on or off (except on Anthropic with mid-conversation tool changes on), a summary replacing the older part of a chat, and the cache expiring (5 minutes by default, or an hour; see BYOK). Prompt caching has the details.

Restarts

On SIGTERM, Kai stops taking new runs, gives running ones 20 seconds, then marks the rest interrupted. People see what had arrived and can regenerate. Runs waiting for someone (an approval) aren't affected.

On this page