Skip to Content
Kai

HTTP API

The routes the web app uses, how they authenticate, and their errors.

The API exists for Kai's own web app. It isn't versioned and may change between releases; there are no API keys for scripts yet.

Conventions

  • Authentication: the better-auth session cookie, set by /api/auth/*. Every route except /api/health, /api/auth/*, /api/auth-config and the OAuth callback and client metadata needs it.
  • Workspace: the session's active workspace. No route takes a workspace id from the client.
  • Bodies: JSON, at most 2 MB (files go straight to S3 with presigned URLs).
  • Errors: one shape, { "error": "<code>", "message"?: "…" }, with the matching status: unauthorized (401), no_workspace and forbidden (403), not_found (404), busy and conflict (409), invalid_request and other input problems (422), rate_limited (429, with Retry-After), and provider_* (502) when the model provider failed. The full list is packages/core/errors; the web app keys its messages by code.
  • Secrets: never returned. Keys and credentials come back as hasKey and a short keyHint.
  • Streams: server-sent events with Last-Event-ID resumption.

Handlers live in apps/api/src/routes/<path>/route.ts; [id] segments become :id. scripts/gen-routes.mjs maps them to URLs in src/routes.gen.ts; the dev and build scripts run it, so a new file is picked up on restart.

Routes

Account and workspace

MethodPath
GET POST/api/auth/*better-auth: sign-up, sign-in, email codes, Google, sessions, organizations, invitations.
GET/api/auth-configWhich sign-in methods and sign-up mode the instance has. Public.
GET/api/meThe user, their workspaces and role.
PATCH/api/me/settingsPersonal settings.
POST DELETE/api/me/delete-accountPOST emails a code (and refuses while you own shared workspaces); DELETE with { code } deletes the account.
GET PATCH/api/workspace/settingsWorkspace settings (owners and admins).
GET PATCH/api/workspace/preferencesWorkspace defaults, like the default model.
POST/api/workspace/transfer-ownershipOwner only.
GET/api/workspace/usageToken usage by day, member or model.
GET/api/eventsSSE: the user's events in this workspace, shared across tabs (titles, new chats, runs finishing).
GET/api/healthLiveness. Public.

Keys and models

MethodPath
GET POST/api/connectionsList or add a key.
POST/api/connections/testTest a key before saving it.
GET PATCH DELETE/api/connections/:id
POST/api/connections/:id/test
POST/api/connections/:id/discoverAsk the provider which models the key can use.
GET PUT/api/connections/:id/modelsThe key's models and which are enabled.
GET/api/modelsEvery model the user can pick, with capabilities.

Chats and runs

MethodPath
GET POST/api/conversationsList (paged, searchable) or create.
GET PATCH DELETE/api/conversations/:idThe conversation with its active branch; rename, pin, archive.
POST/api/conversations/:id/messagesSend, edit or regenerate. Creates a run and returns its id.
GET/api/conversations/:id/messages/:messageId/siblingsA message's alternatives.
POST/api/conversations/:id/active-leafSwitch branch.
POST/api/conversations/:id/compactSummarize older messages.
GET/api/runs/:idA run's state.
GET/api/runs/:id/eventsSSE: the run's parts as they stream.
POST/api/runs/:id/cancelStop.
POST/api/runs/:id/interrupts/:interruptIdAnswer an approval: allow or deny, once, for the chat, or always.
GET/api/tool-outputs/:partIdA large tool output, from S3.
GET/api/tool-outputs/:partId/textThe same, as text.
POST/api/attachmentsStart an upload: returns a presigned PUT URL.
POST/api/attachments/:id/completeFinish it (images are resized here).
GET/api/attachments/:id/urlA presigned download URL.

Tools and agents

MethodPath
GET POST/api/mcp/serversList (with this user's status) or add.
GET PATCH DELETE/api/mcp/servers/:id
POST/api/mcp/servers/:id/testConnect and list tools.
PUT DELETE/api/mcp/servers/:id/credentialsThis user's values, or the shared ones.
POST/api/mcp/servers/:id/connectStart OAuth sign-in: returns the authorization URL.
DELETE/api/mcp/servers/:id/connectionSign out of the server.
GET/api/mcp/oauth/callbackThe OAuth redirect URI.
GET/api/mcp/oauth/client-metadata.jsonKai's OAuth client metadata document. Public.
POST/api/mcp/openapi/previewFetch an OpenAPI document and list the tools it would give.
GET/api/mcp/catalogThe library's servers.
GET DELETE/api/tool-grantsRemembered approvals; DELETE with { ids }.
DELETE/api/tool-grants/:id
GET POST/api/tool-groups
PATCH DELETE/api/tool-groups/:id
GET POST/api/agents
GET PATCH DELETE/api/agents/:id

On this page