HTTP API#
The /v1 chats API, served by create_app, is a thin adapter over a
ChatStore plus a QueryEngine. A client with a session cookie (or a
bearer token) creates chats and posts messages; every generation answer
comes back as an SSE stream (Streaming).
Sessions#
POST /v1/sessions mints a session and returns its session_id in the
response body (404 unless ServeConfig.bearer_tokens is enabled). The session id
is the bearer credential — sent as a cookie, or in the Authorization: Bearer <token> header. A request without a valid session is 401 UNAUTHORIZED.
Chats and messages#
Method & path |
Body |
Returns |
|---|---|---|
|
|
a fresh chat and the streamed answer to the opening message |
|
— |
the session’s chats, newest first, paginated |
|
— |
one chat and its messages |
|
— |
removes the chat and its messages |
|
|
appends a user message and streams the answer |
|
|
regenerate (or edit) the message at |
Cap checks (MAX_MESSAGES_PER_CHAT, MAX_CHATS_PER_SESSION) and a content
over max_content_chars all surface as 422; a missing chat or message as
404; lock contention during a generation as 409; a rate limit exceeded
(when ServeConfig.rate_limiting_enabled, see Admission: rate limiting and client IP/country) as 429
with code RATE_LIMIT. Every JSON error body is {"error": {"code", "message"}}; a request-level failure like these carries a free-form code
such as INVALID_REQUEST or NOT_FOUND, while a generation that starts and
then fails carries one of the error_code values (e.g. MODEL_ERROR,
TIMEOUT) documented in Streaming.
Health#
GET /healthz returns {"status": "ok"} without touching the query engine.
Metrics#
GET /metrics exports a Prometheus text exposition of the app’s own traffic
and generation series; see Metrics.
See also#
Streaming for the SSE frame shapes; Metrics for GET /metrics;
Admission: rate limiting and client IP/country for rate limiting and client IP/country resolution;
Configuration for the fields that gate these routes;
examples/15_asking.py for a client that talks to this API;
Frontend types for the generated OpenAPI document and
TypeScript types this API’s contract is now published as.