Chat API
The Chat API manages conversations and message streaming. All endpoints are mounted under /api/chat (e.g., /api/chat/conversations).
Endpoints
Section titled “Endpoints”| Method | Path | Description |
|---|---|---|
GET | /api/chat/conversations | List conversations |
POST | /api/chat/conversations | Create a conversation |
GET | /api/chat/conversations/{id} | Get a conversation |
PUT | /api/chat/conversations/{id} | Update a conversation |
DELETE | /api/chat/conversations/{id} | Delete a conversation |
GET | /api/chat/conversations/{id}/mode | Get conversation mode |
PATCH | /api/chat/conversations/{id}/mode | Set conversation mode |
GET | /api/chat/conversations/{id}/execution-mode | Get execution mode |
PUT | /api/chat/conversations/{id}/execution-mode | Set execution mode |
POST | /api/chat/conversations/{id}/approval-response | Submit approval response |
POST | /api/chat/messages/stream | Send a message (streaming SSE) |
POST | /api/chat/messages/inject | Inject a message into a conversation |
POST | /api/chat/messages/truncate | Truncate messages |
POST | /api/chat/welcome | Generate a welcome message |
GET | /api/chat/sessions/{session_id}/stream | Remote session SSE stream |
List Conversations
Section titled “List Conversations”GET /api/chat/conversationsReturns all conversations.
Create Conversation
Section titled “Create Conversation”POST /api/chat/conversationsCreates a new conversation.
Get Conversation
Section titled “Get Conversation”GET /api/chat/conversations/{id}Returns a single conversation by ID.
Update Conversation
Section titled “Update Conversation”PUT /api/chat/conversations/{id}Updates a conversation (e.g., title).
Delete Conversation
Section titled “Delete Conversation”DELETE /api/chat/conversations/{id}Permanently deletes a conversation and its messages.
Send Message (Streaming)
Section titled “Send Message (Streaming)”POST /api/chat/messages/streamSends a message and returns the response as a stream of Server-Sent Events (SSE). The connection stays open until the full response is delivered.
SSE Event Format
Section titled “SSE Event Format”Each event in the stream uses standard SSE format. The following event types are emitted:
token — incremental text chunk
Section titled “token — incremental text chunk”event: tokendata: {"content": "def reverse_linked_list"}tool_use — agent is calling a tool
Section titled “tool_use — agent is calling a tool”event: tool_usedata: {"tool": "write_file", "input": {"path": "solution.py"}}tool_result — result of a tool call
Section titled “tool_result — result of a tool call”event: tool_resultdata: {"tool": "write_file", "output": {"success": true}}done — response complete
Section titled “done — response complete”event: donedata: {"message_id": "msg_01j9abc123", "input_tokens": 120, "output_tokens": 245, "total_tokens": 365}error — stream error
Section titled “error — stream error”event: errordata: {"code": "rate_limit", "message": "Provider rate limit reached. Retry in 30s."}Inject Message
Section titled “Inject Message”POST /api/chat/messages/injectInjects a message into a conversation without triggering an agent response. Useful for programmatically adding context or instructions.
Truncate Messages
Section titled “Truncate Messages”POST /api/chat/messages/truncateTruncates messages in a conversation.
Generate Welcome
Section titled “Generate Welcome”POST /api/chat/welcomeGenerates a welcome message for a new conversation.
Conversation Mode
Section titled “Conversation Mode”GET /api/chat/conversations/{id}/modePATCH /api/chat/conversations/{id}/modeGet or set the conversation mode for a specific conversation.
Execution Mode
Section titled “Execution Mode”GET /api/chat/conversations/{id}/execution-modePUT /api/chat/conversations/{id}/execution-modeGet or set the execution mode (e.g., autonomous vs. approval-required) for a conversation.
Approval Response
Section titled “Approval Response”POST /api/chat/conversations/{id}/approval-responseSubmit an approval or rejection for a pending action within a conversation.