Skip to content

HTTP server (ka serve)

Terminal window
ka serve # binds 127.0.0.1:8417
ka serve --addr 127.0.0.1:9000 --token "$KA_TOKEN"

A hand-rolled HTTP/SSE server: same process, no framework. The bearer token is required on every request when set. It binds to loopback by default; if you expose it, set a token.

Create a session and the conversation streams over SSE. Sessions can start from, or resume, strands on disk:

Terminal window
curl -s http://127.0.0.1:8417/sessions \
-H 'content-type: application/json' \
-d '{"resume": "latest"}'

"resume" accepts "latest" or a strand id / prefix; the prior transcript is replayed over SSE before the new turn, so a restarted client sees the full conversation.

The stream honors Last-Event-ID: a dropped connection resumes from the last event received, rather than restarting the turn. Combined with strand persistence, a ka serve session survives client restarts and network blips.

Any number of observers can stream a session without owning it: GET /sessions/{id}/events replays the ring-buffered history, then streams live events, and honors Last-Event-ID for mid-session reconnects. Presence changes broadcast as {"type":"presence","busy":…,"attached":…} events. GET /sessions lists every session with presence and title; GET /sessions/{id} returns one.

ka attach [id] is the built-in observer: a read-only TUI over that SSE stream, with busy · N attached in the footer. The write path stays single-owner: observers have no prompt route; POST /sessions/{id}/prompt remains the only writer API.

  • a local web UI or tool that wants a conversation without embedding the engine
  • scripting ka from languages where spawning a process is clumsy
  • bridging one ka conversation to several viewers (each with its own Last-Event-ID)