向 Session 发送事件(通常是用户消息),触发 Agent 开始处理。
请求头
头部 | 必选 | 说明 |
| 是 |
|
| 是 |
|
路径参数
参数 | 类型 | 必选 | 说明 |
| string | 是 | Session ID( |
请求体
字段 | 类型 | 必选 | 说明 |
| array | 是 | 事件对象数组 |
| string | 是 | 事件类型 |
| string \ | array | 视类型 |
| string | 是 | 内容块类型,如 |
| string | 是 | 文本内容 |
content 支持两种格式:
简写:纯字符串
"content": "文本内容"完整:内容块数组
"content": [{"type": "text", "text": "文本内容"}]
纯文本消息建议使用简写格式;需要发送多媒体内容(如图片)时使用完整格式。
支持的事件类型
type | 说明 | 必填字段 |
| 用户发送消息 |
|
| 用户中断 Agent 执行 | - |
| 对 Agent 的工具调用进行授权 |
|
| 返回自定义工具的执行结果 |
|
| 用户定义预期结果 |
|
示例请求
curl -X POST "https://api.qoder.com.cn/api/v1/cloud/sessions/sess_019e392c0d1e74e095d21ea4c6b41def/events" \
-H "Authorization: Bearer $QODER_PAT" \
-H "Content-Type: application/json" \
-d '{
"events": [
{
"type": "user.message",
"content": [
{"type": "text", "text": "请帮我分析这段代码的性能问题"}
]
}
]
}'示例响应
HTTP 202 Accepted
返回已创建的事件列表。HTTP 202 表示消息已被接受并进入处理队列。
{
"data": [
{
"id": "evt_019e3bb2c153764da54e4d3acbef52b6",
"type": "user.message",
"content": [
{"type": "text", "text": "请帮我分析这段代码的性能问题"}
],
"session_id": "sess_019e392c0d1e74e095d21ea4c6b41def",
"turn_id": "turn_019e3bb2c15376429b88e1f7976c1907",
"schema_version": "1.0",
"created_at": "2026-05-18T15:27:11.187413896Z",
"processed_at": "2026-05-18T15:27:11.187413896Z"
}
]
}响应字段
字段 | 类型 | 说明 |
| string | 事件唯一标识( |
| string | 事件类型 |
| array | 内容块数组 |
| string | 所属 Session ID |
| string | 所属 Turn ID( |
| string | Schema 版本号 |
| string | 创建时间(ISO 8601) |
| string | 处理时间(ISO 8601) |
发送消息后,Agent 会异步开始处理。可通过 GET /v1/sessions/{session_id}/events/stream 实时监听 Agent 的响应事件。
错误码
HTTP | type | 触发条件 |
400 |
| 缺少 |
401 |
| PAT 无效或过期 |
404 |
| Session 不存在 |
409 |
| 向 |
400 错误响应示例:
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "Field 'content' is required."
}
}409 错误响应示例:
{
"type": "error",
"error": {
"type": "conflict_error",
"message": "Session is currently processing a turn. Cancel the current turn or wait for completion."
}
}完整错误信封说明详见 错误参考。