Conversations API
Canonical reference: docs/api-reference.md (generated endpoint directory) — this page is a task-oriented summary.
Manage multi-turn conversations with AI models. Conversations support provider switching mid-session, SSE streaming, and usage tracking.
List Conversations
GET /api/v1/conversations
Returns all conversations for the authenticated user. Admin users see all conversations.
Response
{
"items": [
{
"id": "conv_abc123",
"model": "glm-5.1",
"created_at": 1716192000000,
"updated_at": 1716192100000
}
],
"total": 1,
"limit": 50,
"offset": 0,
"page": 1,
"total_pages": 1,
"has_more": false
}
Standard pagination applies (limit/offset, or page/per_page).
Get Conversation Detail
GET /api/v1/conversations/:conv_id
Returns the conversation with all messages and metadata.
Response
{
"id": "conv_abc123",
"model": "glm-5.1",
"messages": [
{
"id": "msg_001",
"role": "user",
"content": "Explain the OTP supervision tree",
"created_at": 1716192000000,
"meta": {}
},
{
"id": "msg_002",
"role": "assistant",
"content": "The OTP supervision tree is a hierarchical process structure...",
"created_at": 1716192001000,
"meta": {"model": "glm-5.1", "tokens": 150}
}
],
"usage": {
"input_tokens": 45,
"output_tokens": 150,
"total_tokens": 195
}
}
usage is present only when the conversation has recorded usage.
Error Responses
| Code | Description |
|---|---|
| 403 | Not the conversation owner (Zerg envelope, forbidden) |
| 404 | Conversation not found (Zerg envelope, not found) |
Conversation Creation
Every POST /v1/messages request creates a new conversation server-side
(best-effort) and stores the request messages in it — there is no explicit
conversation-create endpoint, and no client-supplied conversation_id
continuation parameter on either completion route. /v1/chat/completions
does not create conversations.
Stream Conversation Events
GET /api/v1/conversations/:conv_id/stream
Subscribe to real-time events for a conversation via Server-Sent Events (SSE).
Response
Returns Content-Type: text/event-stream. Message events are emitted under
the message_append event name, filtered to the subscribed conversation;
idle keep-alives are SSE comment pings (every 15 s), and the stream ends
with an event: done frame when the subscription terminates:
event: message_append
data: {"type":"message_append","data":{"conv_id":"conv_abc123","role":"assistant","content":"..."}}
: ping
event: done
data: {}
The route holds an SSE admission slot; over-budget calls answer 429
(sse_limit_reached / subscription_limit_reached).
Error Responses
| Code | Description |
|---|---|
| 403 | Not the conversation owner (plain body) |
| 404 | Conversation not found (plain body) |
Delete a Conversation
POST /api/v1/conversations/:conv_id/delete
Permanently delete a conversation and all its messages. Only the owner can delete.
Response
{
"status": "ok"
}
Error Responses
| Code | Description |
|---|---|
| 403 | Not the conversation owner |
| 404 | Conversation not found |
Get a Single Message
GET /v1/messages/:message_id
Retrieve a specific message by its ID. Ownership is checked via the parent conversation. Note the route lives on the Anthropic wire family: the 404 body is the Anthropic error envelope ({"type":"error","error":{"type":"not_found_error","message":"message not found"}}).
Response
{
"id": "msg_002",
"role": "assistant",
"content": "The OTP supervision tree is a hierarchical process structure...",
"created_at": 1716192001000,
"meta": {
"model": "glm-5.1",
"tokens": 150
}
}
Error Responses
| Code | Description |
|---|---|
| 404 | Message not found (Anthropic error envelope) |
Get Conversation Usage
GET /api/v1/conversations/:conv_id/usage
Returns token usage statistics for a conversation.
Response
{
"usage": {
"input_tokens": 450,
"output_tokens": 1500,
"total_tokens": 1950
}
}
Provider Switching
Conversations support switching providers mid-conversation. The system performs bidirectional message transformation between Anthropic and OpenAI formats:
curl -X POST http://127.0.0.1:21434/v1/chat/completions \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4",
"messages": [{"role": "user", "content": "Continue"}]
}'
The system automatically transforms the messages from the previous provider’s format to the new provider’s format.
Ownership
Conversations are owned by the user who created them. The ownership check uses sol_identity:check_resource_owner/3 which verifies the authenticated user’s UUID matches the conversation’s owner UUID. Admin users can access all conversations.
Compatiblity Endpoints
The Messages and Chat Completions endpoints are conversation-aware on the Anthropic leg:
| Endpoint | Provider Format | Description |
|---|---|---|
POST /v1/messages | Anthropic | Send message, get response (creates a conversation and stores the request messages) |
POST /v1/chat/completions | OpenAI | Send message, get response |
When stream is true, responses are delivered via SSE with incremental token events.