#Chat API
Chat with Agents, supporting both streaming and non-streaming modes, with automatic conversation history management.
Base Path: /v1/agents/:agentId/chat
#Send Message
POST /v1/agents/:agentId/chat
Required Permission: agent:chat
The Chat API supports two request formats:
#New Format (Recommended)
The backend automatically manages conversation history with session persistence support.
json{
"message": "Hello, please help me analyze this problem",
"sessionId": "sess_abc123",
"stream": true,
"options": {
"model": "zhipu/glm-4"
},
"hint": {
"planning": "auto",
"onStepFailure": "continue"
}
}
| Field | Type | Required | Description | |
|---|---|---|---|---|
message | string \ | ContentBlock[] | Yes | User message content (string for text, array for multimodal) |
sessionId | string | No | Session ID. Omit to automatically create a new session | |
stream | boolean | No | Whether to enable streaming response, default false | |
options.model | string | No | Override the Agent's default model | |
hint.planning | string | No | Planning mode: force, auto, none | |
hint.onStepFailure | string | No | Step failure strategy: stop, continue, auto |
#Image Messages (Multimodal)
To send images along with text, use the OpenAI-standard ContentBlock[] format for the message field:
json{
"message": [
{ "type": "text", "text": "What is in this image?" },
{ "type": "image_url", "image_url": { "url": "https://example.com/photo.jpg" } },
{ "type": "image_url", "image_url": { "url": "https://example.com/photo2.jpg" } }
],
"sessionId": "sess_abc123",
"stream": true
}
| Field | Type | Description |
|---|---|---|
type | "text" | Text content block |
text | string | The text content |
type | "image_url" | Image content block |
image_url.url | string | Image URL (supports https:// URLs and data:image/...;base64,... format) |
Constraints:
- Maximum 9 images per message
- At least one text block is required
- The Agent's model must support vision (e.g.
qwen3-max,qwen3.5-plus). If the model does not support vision, a400error is returned:"The current model does not support image understanding." - Images are stored in
metadata.imageUrlsand displayed in chat history
#Legacy Format (Backward Compatible)
The frontend manages the message list with no history persistence.
json{
"messages": [
{ "role": "system", "content": "You are an AI assistant" },
{ "role": "user", "content": "Hello" }
],
"stream": true
}
| Field | Type | Required | Description |
|---|---|---|---|
messages | array | Yes | Message list |
stream | boolean | No | Whether to enable streaming response |
The system automatically distinguishes between the new and legacy formats by checking whether the request body contains amessagefield (string type) and does not contain amessagesfield.
#Non-Streaming Response
When stream: false or not specified:
json{
"sessionId": "sess_abc123",
"id": "chatcmpl-xxx",
"agentId": "agent_abc123",
"message": {
"role": "assistant",
"content": "Hello! I'm your AI assistant. How can I help you?"
},
"usage": {
"inputTokens": 50,
"outputTokens": 30,
"totalTokens": 80
},
"sources": [
{
"documentId": "doc_xxx",
"title": "Product Manual",
"chunk": "Relevant document excerpt...",
"score": 0.92
}
],
"toolsCalled": [
{
"name": "web-search",
"arguments": { "query": "latest news" }
}
],
"skillsUsed": ["customer-service"],
"latency": 1250,
"createdAt": "2026-02-20T10:00:00Z"
}
#Streaming Response
When stream: true, the response uses SSE (Server-Sent Events) format:
Content-Type: text/event-stream
#SSE Event Format
Each event starts with the data: prefix and ends with \n\n:
data: {"sessionId":"sess_xxx","delta":{"content":"Hello"}}
data: {"sessionId":"sess_xxx","delta":{"content":"!"}}
data: {"sessionId":"sess_xxx","done":true,"usage":{...},"sources":[...]}
data: [DONE]
#Event Field Description
| Field | Description |
|---|---|
sessionId | Session ID |
delta.content | Incremental text content |
toolCall | Tool call event (see Agentic Streaming) |
toolResult | Tool execution result (see Agentic Streaming) |
thinking | Thinking chain event (see Agentic Streaming) |
plan | Planning event (see Agentic Streaming) |
done | Stream end marker |
usage | Token usage statistics |
sources | RAG citation sources |
error | Error message |
#Chat Session Management
When using the new format, the system automatically manages chat sessions. You can also manage sessions directly through the following endpoints.
#List Sessions
GET /v1/agents/:agentId/chat-sessions
Required Permission: session:read
#Query Parameters
| Parameter | Type | Description |
|---|---|---|
page | number | Page number, default 1 |
limit | number | Items per page, default 20 |
status | string | Filter by status |
#Response
json{
"data": [
{
"id": "sess_abc123",
"agentId": "agent_xxx",
"title": "Discussion about product features",
"status": "active",
"messageCount": 12,
"totalTokens": 3500,
"summary": "The user asked about the main product features...",
"createdAt": "2026-02-20T08:00:00Z",
"updatedAt": "2026-02-20T10:00:00Z"
}
],
"meta": {
"total": 5,
"page": 1,
"limit": 20,
"totalPages": 1
}
}
#Get Session Details
GET /v1/agents/:agentId/chat-sessions/:sessionId
Required Permission: session:read
#Update Session
PATCH /v1/agents/:agentId/chat-sessions/:sessionId
Required Permission: session:update
#Request Body
json{
"title": "New session title",
"status": "archived"
}
#Delete Session
DELETE /v1/agents/:agentId/chat-sessions/:sessionId
Required Permission: session:delete
#Response
json{
"id": "sess_abc123",
"deleted": true
}
#Get Session Messages
GET /v1/agents/:agentId/chat-sessions/:sessionId/messages
Required Permission: messages:read
#Query Parameters
| Parameter | Type | Description |
|---|---|---|
page | number | Page number, default 1 |
limit | number | Items per page, default 50, max 100 |
#Response
json{
"data": [
{
"id": "msg_xxx",
"sessionId": "sess_abc123",
"role": "user",
"content": "Hello",
"createdAt": "2026-02-20T08:00:00Z"
},
{
"id": "msg_yyy",
"sessionId": "sess_abc123",
"role": "assistant",
"content": "Hello! How can I help you?",
"metadata": {
"thinking": "The user sent a greeting...",
"plan": { "steps": [...] },
"toolCalls": [...]
},
"inputTokens": 50,
"outputTokens": 30,
"totalTokens": 80,
"createdAt": "2026-02-20T08:00:05Z"
}
],
"meta": {
"total": 2,
"page": 1,
"limit": 50,
"totalPages": 1
}
}
#Legacy Sessions
The following endpoints use the legacy Storage module and are primarily for backward compatibility. New integrations should use the Chat Sessions API above.
#Create Session
POST /v1/agents/:agentId/sessions
Required Permission: session:create
#Request Body
json{
"title": "New Session",
"metadata": {}
}
#Get Message History
GET /v1/agents/:agentId/sessions/:sessionId/messages
Required Permission: messages:read
#Query Parameters
| Parameter | Type | Description |
|---|---|---|
limit | number | Number of items to return |
offset | number | Offset |
#Response
json{
"sessionId": "sess_xxx",
"messages": [...],
"totalMessages": 24
}