Skip to content

API Routes

All successful responses are wrapped in SuccessResponse[T] from loryth-fastapi:

{
  "data": { ... }
}

User identity is passed via the X-User-Id header (set by the IAM gateway after JWT validation).

Resources are identified by UUID. All timestamps are ISO 8601.


Conversation Router

POST /conversations

Create a new conversation.

Request Body:

{
  "space_id": "uuid",
  "title": "string",
  "model_binding_id": "uuid | null"
}

Response: SuccessResponse[ConversationModel] (201)

GET /conversations

List conversations for a space.

Query Parameters: - space_id (uuid, required)

Response: SuccessResponse[list[ConversationModel]]

GET /conversations/{conversation_id}

Get a single conversation by UUID.

Response: SuccessResponse[ConversationModel]

Errors: 404 if not found

POST /conversations/{conversation_id}/messages

Append a message to a conversation.

Request Body:

{
  "role": "user | system",
  "content": "string",
  "attachments": "object | null"
}

Response: SuccessResponse[MessageModel] (201)

Errors: 404 if conversation not found, 403 if not owner

GET /conversations/{conversation_id}/messages

List all messages in a conversation.

Response: SuccessResponse[list[MessageModel]]

Errors: 404 if conversation not found

POST /conversations/{conversation_id}/fork

Fork a conversation, optionally reassigning ownership.

Request Body:

{
  "new_owner_id": "uuid | null"
}

Response: SuccessResponse[ConversationModel] (201)

Errors: 404 if conversation not found


Run Router

POST /conversations/{conversation_id}/runs

Start a new run (model↔tool orchestration loop).

Request Body:

{
  "model_binding_id": "uuid | null",
  "prompt": "string | null"
}

Response: SuccessResponse[RunModel] (201)

Errors: 404 if conversation not found

GET /runs/{run_id}

Get run details including steps.

Response: SuccessResponse[RunModel]

Errors: 404 if not found

GET /runs/{run_id}/stream

Stream run events via Server-Sent Events (SSE).

Response: text/event-stream

Note: Currently returns a stub. RunOrchestrator integration is pending.

POST /runs/{run_id}/cancel

Request cancellation of a running run.

Response: SuccessResponse[RunModel]

Errors: 404 if not found


Tool Router

GET /tools

List all enabled tools.

Response: SuccessResponse[list[ToolModel]]

GET /tools/catalog-revision

Get the current (latest) tool catalog revision.

Response: SuccessResponse[CatalogRevisionModel]

Errors: 404 if no revisions exist


Admin Router

POST /admin/tools/refresh

Trigger a refresh of all active tool sources. Fetches manifests, detects changes via content hashing, and bumps the catalog revision if tools have changed.

Response: SuccessResponse[CatalogRevisionModel]


Ingestion Router

POST /web/fetch

Fetch a URL, extract text content, and store in MinIO.

Request Body:

{
  "url": "string (1-4096 chars)",
  "space_id": "uuid"
}

Response: SuccessResponse[SourceDocumentModel]

Note: Currently raises NotImplementedError. HTTP fetching and MinIO storage integration is pending.


Embedding Router

POST /embeddings/generate

Generate embeddings for all messages in a conversation.

Request Body:

{
  "conversation_id": "uuid",
  "force": "boolean (default: false)"
}

Response: SuccessResponse[{"message_count": int, "vector_count": int}]

POST /conversations/search

Search conversations by embedding similarity.

Request Body:

{
  "space_id": "uuid",
  "query": "string (1-2048 chars)",
  "limit": "int (1-100, default: 10)"
}

Response: SuccessResponse[list[SearchResultModel]]

Each result contains conversation_id, message_id, content, and similarity score.


Common Patterns

  • Error Mapping: Domain NotFoundError → HTTP 404, ValidationError → HTTP 400/422
  • Ownership: Conversation mutations validate x_user_id matches owner_id
  • Space Scoping: List queries filter by space_id for data isolation
  • Delete: Returns 204 No Content with no body (not yet implemented for this service)

Journal and audio

All routes use the existing approved-account check and require x-user-id matching the bearer token. Successful JSON responses use SuccessResponse[T].

Method Path Request Response data
GET /journal/status User header interview_configured, transcription_configured, transcription_provider, transcription_model
POST /audio/transcriptions Multipart file, optional language text, language, duration_seconds, confidence
POST /journal/interview system_prompt, nonempty turns (interviewer|me, content) question
POST /journal/synthesis turns containing at least one me turn prose

Audio uploads accept audio/* and video/webm, up to 25 MB (415 for MIME rejection, 413 for size). Missing provider configuration returns 503; provider failures return safe 502 messages. Synthesis drops a trailing interviewer question and asks for prose in one completion, without tools.

GET /admin/settings also returns deepgram_model, deepgram_configured, deepgram_stored_key, and deepgram_stored_key_unreadable. PUT accepts any non-empty subset of the DeepSeek and Deepgram model, API key, and removal fields. Each provider section updates only its own fields; omitted fields keep their current values. Both provider changes commit together. Keys are encrypted with LORYTH_SETTINGS_KEY and are omitted from settings responses.

GET /admin/settings/keys/{provider} requires an approved admin. Provider is deepseek, deepgram, or mojeek. It returns SuccessResponse[StoredKeyModel] with data.api_key, decrypting only the database key, never an environment fallback. No saved key returns 404 (No saved API key.); an unreadable saved key returns 409. Responses include Cache-Control: no-store. Settings fetches a saved key only when an admin chooses Copy or Show API key. Revealing an unchanged key does not resubmit it on save.

GET /admin/search-usage and GET /admin/token-usage

Both routes require an approved active admin, accept days from 1 to 90 (default 30), and return SuccessResponse with Cache-Control: no-store. Reports contain tracking_since (null before the first recorded request), from_date, to_date, totals and zero-filled daily rows for UTC calendar days.

Search reports also contain providers rows for Yahoo, Mojeek and Brave. Counts include searches, succeeded, failed, upstream_requests, result_count and summed duration_ms. Outbound requests include retry and redirect attempts; requests rejected before provider selection are excluded.

Token reports also contain models rows grouped by configured model and source (chat or journal). Counts include requests, failed, with_usage, prompt_tokens, completion_tokens, cached_tokens, reasoning_tokens and total_tokens. requests - with_usage counts missing usage reports. Token totals sum provider-reported usage only; cached/reasoning tokens are subsets of prompt/ completion tokens. Usage tracking starts at migrations v16/v17 without backfill. No queries, prompt/reply text, user IDs or keys appear in usage records.