Skip to content

API routes

All routes run on the Node runtime. Every route below Auth and Operations resolves identity with requireIdentity() and authorizes through can(); see Authorization model. A service-account API token is accepted wherever a session is, except the dashboard stream. A share link is accepted only by the stream.

test/docs-drift.test.ts holds this page to the route files: every route under src/app/api/ and every method it exports has a row here, and every row names one that exists.

Route Method Min role Notes
/api/dashboards GET viewer List dashboards. ?workspaceId= and ?editable=true only narrow the caller’s own workspaces — the candidates come from the claims and each is re-checked with can()
/api/dashboards POST editor Create; validates the spec and derives the workspace from trusted sources. A spec of an earlier specVersion (or none) is upgraded first, and the row is written at the current one
/api/dashboards/[id] GET viewer Current version with its spec
/api/dashboards/[id] PUT editor Appends a new immutable version, at the current specVersion; an older spec is upgraded first
/api/dashboards/[id] PATCH editor Metadata. description and tags are written to the row in place; a title appends a version, because the spec owns the name
/api/dashboards/[id] DELETE owner / source-admin Soft delete
/api/dashboards/[id]/duplicate POST viewer + editor Copies the current spec into a new dashboard at version 1, titled "… (copy)". Re-validates the spec, so a copy of a dashboard whose source was tombstoned fails loudly
/api/dashboards/[id]/favorite PUT / DELETE viewer Star or unstar it for the caller. No body: the subject is always the session’s own
/api/dashboards/[id]/export GET viewer Downloads the current spec as a JSON file (Content-Disposition: attachment). Carries source ids only — no workspace, author, or connection detail
/api/dashboards/[id]/versions GET viewer The version history, newest first, without specs: number, author sub, time, note, panel count. Keyset-paginated with ?before=<version>&limit= (default 20, max 100); also returns current
/api/dashboards/[id]/versions/[version] GET viewer One version with its spec, upgraded in memory to the current specVersion
/api/dashboards/[id]/versions/[version]/restore POST editor Appends a new version copying that version’s spec, noted restored from vN. Never repoints or edits an old row. The copy goes through the same source and SQL checks as a save, so a version reading a since-removed source, table or hidden column is refused (400)
/api/dashboards/import POST editor Creates a dashboard at version 1 from an exported file. The target workspace is a request field re-checked by can(); source ids are re-pointed by an explicit mapping and any still unresolved refuse the whole import
/api/dashboards/[id]/stream GET viewer SSE deltas, cookie-authenticated, or ?share=<token> for a share link, which ignores from/to and var-*. from/to pick the window; var-<name> (repeated for a multi-value variable) picks variable values, each checked against what the variable allows this viewer, or a 400
/api/dashboards/[id]/shares GET, POST editor List the dashboard’s share links, or create one; the token is in the create response only
/api/dashboards/[id]/shares/[shareId] DELETE editor Revoke a share link at once; its open streams close
/api/dashboards/[id]/annotations GET viewer The annotations the dashboard shows for from/to (its own range by default), from the dashboard’s own workspace only, honoring its annotations setting
/api/dashboards/[id]/panels/[panelId]/retry POST viewer Runs a panel the poller is backing off from now instead of at its retryAt, on every poller showing the dashboard. Refused (started: 0) for a panel that is not backing off or within MIN_REFRESH_INTERVAL_MS of its last attempt. The result arrives on the stream
/api/dashboards/[id]/chat POST viewer Takes an optional modelId, as /api/generate; the caller’s conversation here keeps it for later turns (#442). Read-only chat with a guarded runQuery tool. Rate limited and budgeted. The turn is kept in the caller’s own Explore conversation for this dashboard (made on the first turn; nothing kept when they keep no conversations), and the request’s abort signal cancels the model call
/api/dashboards/[id]/chat GET viewer The caller’s own conversation on this dashboard, with the modelId it uses, bounded by CHAT_HISTORY_MAX_MESSAGES / CHAT_HISTORY_RETENTION_DAYS, and its conversationId for Open in Explore. The subject comes from the session, never from the request
/api/dashboards/[id]/chat DELETE viewer Delete the caller’s own conversation on this dashboard. Nobody else’s

A template is a reusable Panel or Dashboard spec, workspace-scoped and authorized exactly like the dashboards it is made of — there is no template:* vocabulary in can(), because a template carries no capability its dashboard did not.

Route Method Min role Notes
/api/templates GET viewer Templates saved in a workspace. ?kind=panel|dashboard narrows; ?sourceId= additionally returns the built-in golden-signal starters parameterized by that source’s catalog
/api/templates POST editor Save a panel or dashboard as a template. The body is put through the same resolveAndValidateDashboard a save uses, so every statement is re-guarded and the workspace must match the one derived from the sources. 409 when the workspace already has that name
/api/templates/[id] DELETE owner / source-admin Hard delete — instantiating a template copies its spec, so nothing points back at the row

There is deliberately no instantiate route. Applying a template re-points its panels at a source the user picks, re-checks each statement through /api/sql/validate, and then goes out through the ordinary create or save, so a dashboard built from a template is indistinguishable from one built by hand.

Route Method Min role Notes
/api/generate POST editor Every mode takes an optional modelId from /api/models (#442); one the catalog does not grant the caller in the source’s workspace is a 400, and the pick becomes their default there. Streams a validated dashboard, panel, or explore-panel spec. Authorized against the workspace owning the selected source. The dashboard and dashboard-refine modes take up to two additionalSourceIds in that workspace (More than one source); each is authorized and checked on its own record, and one that fails refuses the request. Refuses with a 400 when a source’s catalog was never refreshed or names nothing that still exists. Rate limited and budgeted. A first attempt carries X-Generation-Id; { "repairOf": id } asks for its one repair, and is a 404 once taken or expired
/api/models GET viewer ?workspace=<id>: the models the caller may use there (#439): the server’s (env:<name>), the workspace’s own and, where the workspace allows them, the caller’s personal ones, each as { id, name, provider, model, scope, unavailable }, with defaultModel, the id a generation without a pick uses. Never settings beyond the model id, never credentials. Demo mode lists the server’s only
/api/models/discover POST source-admin, or editor for their own “List models” (#443): { owner, workspaceId, config, modelId? }, with the roles of the test routes (owner: "workspace" needs source:manage; "personal" needs dashboard:generate in a workspace that allows personal models). Asks the vendor which models the credentials may use, through the kind’s guarded fetch, the reply read under a 4 MiB cap; modelId’s stored credentials stand in for blank fields, for the same origin only. Admitted by the workspace’s rate limit. Answers { ok: true, models: [{ id, name? }] } or { ok: false, message }; a kind that cannot list (Azure, Bedrock) is a 400. Audited as workspace.model.discover or user.model.discover
/api/models/detect POST source-admin Re-scan for a model on this machine (#607): { workspaceId }, a workspace where the caller holds source:manage. Probes the server’s own LOCAL_MODEL_ENDPOINTS again (the request names none) through the base URL guard under the model-list cap and a 3-second timeout. Admitted by the workspace’s rate limit. Answers 200 with { ok: true, found, endpoints: [{ host, ok, models }] }, host being host:port and models a count, whatever the endpoints said; a 404 when LOCAL_MODEL_DETECT resolves to off. Audited as model.detect
/api/query POST editor One-shot guarded query for the editor’s preview. The body is a panel query in its source’s language: sql (with timeField) for a SQL source, promql (with instant, minStep) for a Prometheus one, or logql (with instant, minStep) for a Loki one (#562); the wrong language for the source is a 400. variables carries the values a preview binds for :name references: bound parameters for SQL, escaped matcher values for PromQL and LogQL
/api/sql/validate POST editor Runs the source’s guard against its catalog without executing: the SQL guard, the PromQL guard for a promql body, or the LogQL guard for a logql one. Always 200; the verdict is { ok, error? }, plus hints for a PromQL or LogQL label the catalog does not list. variables names the dashboard’s declared variables, which :name may reference
/api/sql/plan POST editor The statement exactly as the server would run it, without running it: the wrapped SQL, the bound parameters with what each was resolved from, the limits and the session statements. For a promql body, the rewritten expression, the endpoint, start/end/step (or time) with what each was resolved from, the timeout and the caps. For a logql body the same, with limit and direction in place of step for a log query. A refused statement is a 400 with the guard’s message. See Seeing what actually runs
/api/variables/options POST editor The values a dashboard variable allows, from its declaration: an enum’s list, a query variable’s guarded SELECT run as the caller, or a label-values variable’s label values from a Prometheus or Loki source, under the caller’s tenant matcher and capped at 200. Audited as query.execute
/api/generation-log GET source-admin The redacted prompt/spec pairs every generation leaves behind. Workspaces come from the caller’s claims, so ?workspaceId= narrows and can never widen; a viewer or editor reads an empty list rather than a 403. ?limit= is clamped
/api/audit GET source-admin The append-only audit log, newest first. Filters: workspaceId, from/to (ISO or now-24h), action, outcome; paged with limit and before (the previous page’s next). Workspaces come from the caller’s claims as above; a platform admin reads any workspace, and every row with no filter. An unusable filter is a 400

A conversation is the caller’s own: every route is keyed on the session’s subject, and someone else’s conversation is a 404, for a platform admin too. A share link reaches none of them.

Route Method Min role Notes
/api/chat GET signed in The caller’s conversations, most recently used first, 50 a page; ?after= is the previous page’s next. Conversations past CHAT_HISTORY_RETENTION_DAYS are not listed
/api/chat POST viewer Start a conversation: { sourceIds, timeRange }, or { dashboardId, timeRange? } for the caller’s one conversation on a dashboard they may view (made on first use, over the dashboard’s sources; Open in Explore and Ask in Explore). Each source needs source:use; all must be in one workspace, which is the conversation’s, and at most three. Past CHAT_CONVERSATIONS_MAX the caller’s least recently used conversation is deleted. A 409 when the caller turned Keep my conversations off
/api/chat DELETE signed in Delete every one of the caller’s conversations, at once
/api/chat/[id] GET owner The conversation and its messages. A drawn panel’s rows are never stored, so the page runs each panel again; unavailableSourceIds names the sources the caller can no longer use
/api/chat/[id] PATCH owner Rename it (title), or change its sourceIds (re-authorized, same workspace) or timeRange
/api/chat/[id] DELETE owner Delete it and its messages
/api/chat/[id]/messages POST owner, viewer on its sources One turn: { message, modelId? }, the new question only; a modelId becomes the conversation’s model, and without one the turn uses the conversation’s model while it is usable (#442); the history is the stored conversation. Streams the answer, with runQuery and showPanel. Rate limited and budgeted per workspace; the turn is stored with each panel’s rows stripped. Refused with a 403 when none of the conversation’s sources is usable any more
/api/chat/turn POST viewer One turn of a conversation that is not kept, for a caller with Keep my conversations off: { sourceIds, timeRange, modelId?, history, message }. Nothing is stored; the page sends the history it holds, each drawn panel reduced to its sample, at most 512 KB. The sources are checked as on create
/api/chat/[id]/panels/[panelId]/run POST owner, viewer on its source Run a drawn panel again. The body is { timeRange? } and nothing else: the statement is the stored panel’s, checked against its source’s catalog as it is now, under the caller’s row scope
Route Method Min role Notes
/api/sources GET viewer List sources in a workspace, each with its catalog health. A source admin gets full records; anyone else gets a listing with no connection details, secret_ref or catalog: its kind, id, name and status, plus the schema and table count for TimescaleDB, the layout and table count for DuckDB, the metric count for Prometheus or the stream label count for Loki, never its URL or path. canManage says which
/api/sources POST source-admin Create
/api/sources/generate POST editor Takes an optional modelId, as /api/generate. Streams a validated SourceDraft — never credentials. Rate limited and budgeted. Takes { "repairOf": id } for the one repair, as /api/generate does
/api/sources/[id] GET viewer The full record for a source admin, the listing for anyone else
/api/sources/[id] PUT/DELETE source-admin Delete tombstones when referenced
/api/sources/[id]/catalog GET viewer The catalog browser’s view: every column with its exposed flag for a source admin, exposed columns only for anyone else, plus catalog health. For a Prometheus source, the allowlisted metrics with their type, help and labels, the metrics the last refresh found no series for, and catalog health
/api/sources/[id]/catalog/impact GET source-admin ?table=&column=: the current panels on this source that hiding the column would break, decided by a dry run of the guard. Ids and titles only, never SQL, scoped to the source’s workspace
/api/sources/[id]/catalog PATCH source-admin Hide or expose one column, { table, column, exposed }. Takes effect on the next generation and execution. A Prometheus or Loki source is refused: a metric or label is allowlisted whole
/api/sources/[id]/impact GET source-admin Dashboards and panels currently referencing the source, scoped to its workspace
/api/sources/[id]/test POST source-admin Connectivity, latency, server and role identity, a read-only proof, and per-table reachability. All of it inside one rolled-back read-only transaction. For a Prometheus source: connect and query latency, what answered and its version, whether the credential was accepted, the write surface read from /api/v1/status/flags, and whether each allowlisted metric has series. For a Loki source: /ready, one labels call under the credential, the build read from status/buildinfo, and whether each allowlisted label has values in the discovery window. The one write: a TimescaleDB source records whether the server has the TimescaleDB extension (catalog_facts), from the server’s own answer
/api/sources/discover POST source-admin The tables and columns a prospective source’s read-only user can see, to pick an allowlist from. For kind: "prometheus" (url, auth, secretRef unless auth is none): the endpoint’s metric metadata, or with labelsFor the label names of those metrics. For kind: "loki" (the same fields, #563): the stream label names, or with valuesFor that label’s values (up to 100), both over the server’s PROMETHEUS_DISCOVERY_WINDOW. Nothing is persisted, the URL is checked against SOURCE_URL_ALLOWLIST, and the secret_ref grant is checked like any connection. For kind: "duckdb" (path, relative to DUCKDB_SOURCES_DIR): the tables and columns under that directory or .duckdb file, read on a locked engine after the path guard; errors and the audit row name no path
/api/sources/duckdb/paths GET source-admin ?workspaceId=: the directories and .duckdb files directly under DUCKDB_SOURCES_DIR, for the DuckDB form’s path picker. { ok: true, paths: [{ name, layout }] }: names only, one level, nothing hidden and nothing that resolves outside the root; { ok: false, error } naming the variable when it is unset or unreadable. Rate limited per caller, not audited
/api/sources/duckdb/uploads POST source-admin ?workspaceId= and a multipart/form-data body of files (#595, #596, #597): CSV and JSON files streamed to DUCKDB_SOURCES_DIR/uploads/<workspaceId>/<fresh id>/, one <name>.<ext> per file, name the file’s stem reduced to [a-z0-9_], ext its own when it is .json, .jsonl or .ndjson and .csv otherwise; an .xlsx or .xlsm workbook (#604, its macros never read) converted on arrival to one <name>.csv per visible sheet with data (<stem>_<sheet> when there are several) and not kept, its CSVs together under DUCKDB_UPLOAD_MAX_BYTES, at most 32 sheets of 1,000,000 rows; .xls, .xlsb, .ods and .numbers refused by name. All or nothing: a file over DUCKDB_UPLOAD_MAX_BYTES, more than DUCKDB_UPLOAD_MAX_FILES files, a file that is not UTF-8 text or is empty, a stem that reduces to nothing or two files with one stem refuse the whole upload, and a refused or cancelled one leaves no file. { ok: true, path, files: [{ name, bytes, views?, skipped? }] } (views a workbook’s tables, skipped its hidden and empty sheets), the path then saved with POST /api/sources; or a 400 with { ok: false, error, file? } naming no server path. Rate limited per caller, audited as source.upload. On success, the workspace’s upload directories that no source names and that are over an hour old are swept in the background
/api/sources/[id]/uploads POST source-admin Add files to an upload source (#604): the same multipart/form-data body of files and the same rules as /api/sources/duckdb/uploads, written into the source’s own directory. Authorized source:manage in the source’s workspace, from its record; a tombstoned source is a 409, and a source that was not made by uploading (another kind, or a DuckDB source over the server’s own files) is refused by name. All or nothing for this request’s files: a file whose table the source already has is refused (already a table in this source; rename it), DUCKDB_UPLOAD_MAX_FILES counts the files already there, and a refused or cancelled request leaves the existing files untouched and nothing new. { ok: true, path, files }, path the source’s own; or a 400 with { ok: false, error, file? }. The new files are not tables yet: apply them with /api/sources/[id]/refresh. Rate limited in the same bucket as /api/sources/duckdb/uploads, audited as source.upload on the source with added: true
/api/secret-refs GET source-admin ?workspaceId=: the secret_refs granted to that workspace, each with whether the server holds credentials. Names and booleans only, rate limited per caller. See Source secret references
/api/sources/[id]/refresh POST source-admin Re-introspect the catalog. With {} it is a preview: it writes nothing and answers with the diff and a digest. With { digest } it introspects again and writes only if the result matches, recording freshness, any allowlisted table the database no longer has and, for a TimescaleDB source, whether the server has the TimescaleDB extension; otherwise 409 with the new diff and digest. For a Prometheus source the diff names metrics missing or found again, labels added or removed, and changed metric types; for a Loki source, labels missing or found again and each label’s values added or gone
Route Method Min role Notes
/api/search GET viewer What the command palette searches. Dashboards and sources across every workspace the caller can already reach, taken from the claims — there is no workspace parameter to widen it. A source is projected to its id, name, workspace and whether the caller may manage it; the connection config and the catalog never leave the server
Route Method Min role Notes
/api/me GET signed in The caller’s own subject, display name, email, platform-admin flag and workspace roles, all from the session. No parameters, so it can only describe the identity that asked. The name and email are display-only and never reach can()
/api/me/preferences GET / PATCH signed in The caller’s own preferences: time zone, clock, start page, dashboard list defaults, what this browser remembers, chart patterns, Explore’s defaults, the dashboard chat button, and the model last picked per workspace. PATCH merges a partial object; an unknown key or an invalid value is a 400 naming the field, and a start dashboard must be one the caller can view. Turning rememberChats off deletes every one of the caller’s Explore conversations. No subject parameter, so nobody reads or writes another person’s row
/api/me/models GET, POST signed in The caller’s own models (#439): { models }, each with its id, name, settings (the provider kind and its settings) and the credentials’ state (set with its last four characters, none, or unreadable), never the credentials. POST takes { name, settings, credentials? }; a typed base URL is held to the base URL guard. Always the session’s own models; refused for a service-account token, and POST in demo mode. A name already taken is a 409. Audited as user.model.create
/api/me/models/[modelId] PUT, DELETE signed in Replace or delete one of the caller’s own models. PUT takes { name, settings, credentials? }: a missing credentials keeps the stored ones, for the same origin only, null clears them, and an object is held to the kind’s fields. Another person’s id is a 404. Refused for a service-account token and in demo mode. Audited as user.model.update and user.model.delete
/api/me/models/test POST editor { config, workspaceId, modelId? }: one minimal model call with that configuration, and modelId’s stored credentials when config leaves them out, admitted by workspaceId’s rate limit and budget, which must allow personal models. Answers { ok, model, latencyMs } or { ok: false, message }. Audited as user.model.test
Route Method Min role Notes
/api/workspaces/[id]/limits PATCH platform admin Set or clear the workspace’s ratePerMinute and dailyTokenBudget overrides in workspace_limits. A present key is written, null inherits the environment’s value again, 0 disables the limit, and an absent key is left alone. Gated on workspace:limits, which no workspace role grants. Each change writes a workspace_limits.changed log line and a workspace.limits.update audit row, both with the before and after values. Answers with the workspace’s effective limits and today’s usage; the next model call uses them, with no restart
/api/workspaces/[id]/prompt GET, PUT editor (GET), source-admin (PUT) The workspace’s prompt customization: { glossary, metricDefinitions, examples }. GET is gated on dashboard:generate, PUT on source:manage, both in the path’s workspace. PUT replaces the whole customization; an example whose panel fails the IR, runs no query, or whose SQL fails the guard against its source (which must be live and in this workspace) is a 400 naming the example. Audited as workspace.prompt.update, with the sizes, never the text
/api/workspaces/[id]/prompt/preview GET editor ?sourceId= — the system prompt a generation against that source is given, composed as /api/generate composes it. The source must belong to the path’s workspace, by its own record; otherwise 404
/api/workspaces/[id]/model GET, PUT source-admin The workspace’s model settings (#439): { workspaceId, models, defaultModel, config, allowPersonalKeys }, never a credential. PUT takes { defaultModel, allowPersonalKeys }: defaultModel is one of the workspace’s models, a server model’s env:<name>, or null for the server’s default; anything else is a 400. Refused in demo mode. Audited as workspace.model.update
/api/workspaces/[id]/models GET, POST source-admin The workspace’s models, as /api/workspaces/[id]/model answers. POST adds one: { name, settings, credentials? }, with the rules of /api/me/models. Refused in demo mode. Audited as workspace.model.create
/api/workspaces/[id]/models/[modelId] PUT, DELETE source-admin Replace or delete one of the workspace’s models, with the rules of /api/me/models/[modelId]. Deleting the default clears it. Another workspace’s id is a 404. Refused in demo mode. Audited as workspace.model.update and workspace.model.delete
/api/workspaces/[id]/models/test POST source-admin { settings, credentials? }: one minimal model call with an unsaved model, admitted by the workspace’s rate limit and budget. Answers as /api/me/models/test. Audited as workspace.model.test
/api/workspaces/[id]/models/[modelId]/test POST source-admin As /api/workspaces/[id]/models/test, with the model’s stored credentials when the body leaves them out (same origin only). Audited as workspace.model.test
/api/workspaces/[id]/annotations POST editor Write an annotation into the workspace in the path: { at, endedAt?, kind, title, description?, tags?, source? }. Audited as annotation.create
/api/workspaces/[id]/annotations/[annotationId] DELETE editor Delete one of that workspace’s annotations; another workspace’s id is a 404. Audited as annotation.delete
/api/workspaces/[id]/tokens GET, POST source-admin List the workspace’s API tokens, or create one ({ name, role, expiresInDays }); the token is in the create response only. Audited as token.create
/api/workspaces/[id]/tokens/[tokenId] DELETE source-admin Revoke a token; refused from its next request. Audited as token.revoke
Route Method Min role Notes
/api/mcp GET, POST signed in (bearer) The MCP server (#148). POST is the protocol: JSON-RPC over the stateless streamable HTTP transport (initialize, ping, tools/list, tools/call), each tool authorized with can() for the bearer’s identity exactly as the route it mirrors. The one route that accepts a realm-issued access token, in Authorization: Bearer, and the only credential it accepts besides a service-account ht_ token: no session cookie (#149). Unauthenticated, or refused, is a 401 whose WWW-Authenticate names the protected-resource metadata at /.well-known/oauth-protected-resource/api/mcp; see Keycloak setup. GET answers with the caller’s identity as /api/me does (a 405 when asked for an event stream). A 404 until OIDC_MCP_CLIENT_ID is set, and always in demo and local mode
Route Method Notes
/api/auth/login GET ?next=<path>: renews a session that has only expired, as refresh does, else begins the OIDC authorization-code flow; either way the browser comes back to next (a same-origin path, else /). Page requests without a session are sent here. In demo mode, mints a demo session; in local mode, the local owner’s (Demo and local mode)
/api/auth/callback GET Verifies the token, mints the session cookie, clears the signed-out cookie and returns to the page the sign-in started from. A 404 in demo and local mode
/api/auth/refresh POST Renews the session (#27). Authenticated by the /api/auth-scoped renewal cookie, not the session cookie, so it works after the token expired. Re-derives groups from the realm’s fresh id_token. 200 { expiresAt }; 401 when there is nothing to renew or the realm refused (both cookies cleared); 503 when the realm or database did not answer. A 404 in demo and local mode
/api/auth/logout POST Clears both session cookies, deletes the stored refresh token, and revokes the session’s token so a copy of the cookie stops working. With a realm, sets the signed-out cookie, which keeps pages on the sign-in card rather than going back to the realm
/api/auth/backchannel-logout POST Called by Keycloak, not a browser (#28). Form body logout_token, verified against the realm JWKS for issuer, audience (OIDC_CLIENT_ID), age and the back-channel events claim. Revokes the named sid (or every session of a bare sub), closes its open streams, deletes its sessions rows. 200 empty, or 400 {"error":"invalid_request"}. A 404 in demo and local mode or without OIDC

These three are outside the session: a probe and a scraper do not hold a cookie.

Route Method Access Notes
/api/health GET open Liveness. Always 200 while the process serves; carries the build identity
/api/ready GET open Readiness. Does I/O and fails while draining. See Health and readiness
/api/metrics GET token and/or CIDR Prometheus exposition format. 404 until configured. See Prometheus metrics

Statement-level SQL failures return 400 with the real message so an editor can correct and retry. Connection and infrastructure failures return a generic 500 and are never surfaced. This split is invariant 16.

Status Meaning
400 Invalid request, invalid spec, rejected SQL, or a failed statement
401 No valid session
403 Authenticated but not authorized for the action
404 Resource not found
409 Source is tombstoned, or a template name is already taken in the workspace
429 A model-backed route hit the workspace’s rate limit or token budget; the message says which and when it resets, and Retry-After is set. See LLM rate limits and budgets
500 Infrastructure failure — deliberately opaque

Every error body is { error, kind, requestId }. kind is one of validation, statement, authorization, not_found, conflict, rate_limit, or infrastructure, and it is what a client presents from — a 400 is both a rejected body and a failed statement, and only the route knows which. requestId is the same value as the x-request-id header, repeated in the body so the opaque path has something the user can quote back.