Skip to main content

Chat API

Creatoria Agent API Documentation

#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:

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"
  }
}
FieldTypeRequiredDescription
messagestring \ContentBlock[]YesUser message content (string for text, array for multimodal)
sessionIdstringNoSession ID. Omit to automatically create a new session
streambooleanNoWhether to enable streaming response, default false
options.modelstringNoOverride the Agent's default model
hint.planningstringNoPlanning mode: force, auto, none
hint.onStepFailurestringNoStep 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
}
FieldTypeDescription
type"text"Text content block
textstringThe text content
type"image_url"Image content block
image_url.urlstringImage 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, a 400 error is returned: "The current model does not support image understanding."
  • Images are stored in metadata.imageUrls and 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
}
FieldTypeRequiredDescription
messagesarrayYesMessage list
streambooleanNoWhether to enable streaming response
The system automatically distinguishes between the new and legacy formats by checking whether the request body contains a message field (string type) and does not contain a messages field.

#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

FieldDescription
sessionIdSession ID
delta.contentIncremental text content
toolCallTool call event (see Agentic Streaming)
toolResultTool execution result (see Agentic Streaming)
thinkingThinking chain event (see Agentic Streaming)
planPlanning event (see Agentic Streaming)
doneStream end marker
usageToken usage statistics
sourcesRAG citation sources
errorError 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

ParameterTypeDescription
pagenumberPage number, default 1
limitnumberItems per page, default 20
statusstringFilter 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

ParameterTypeDescription
pagenumberPage number, default 1
limitnumberItems 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

ParameterTypeDescription
limitnumberNumber of items to return
offsetnumberOffset

#Response

json{
  "sessionId": "sess_xxx",
  "messages": [...],
  "totalMessages": 24
}