发送事件
先调用「创建会话」,用返回的会话 ID 替换示例 ID。
/anthropic/v1/sessions/{session_id}/events◐ 部分支持请求参数
session_idstring必填path: 会话 ID(路径或查询参数)。
eventsarray必填要发送给会话的事件列表。
返回
200
将 sesn_123 换成创建会话返回的 id。每条 user.message 只接受一个非空文本块。支持文本 user.message、user.interrupt、工具确认、user.custom_tool_result 和 system.message。system.message 的 content 为非空文本块数组;每个请求最多一条,必须是最后一条且紧跟 user.message、user.tool_result 或 user.custom_tool_result。user.custom_tool_result 的 custom_tool_use_id 来自 agent.custom_tool_use.id 或 requires_action 的 stop_reason.event_ids;content 可省略或为空,仅接受 text 块,其它块返回 400;is_error 可省略或为 null,均视为 false。无需传 session_thread_id,服务按调用 id 路由子会话;传入该字段返回 400。未知调用 id 返回 400;重复结果或调用已不再等待返回 409。/agent/v1 的 end_user 仅可提交自己会话的结果,他人会话返回 404。user.tool_result 仍不支持。initial_events 不接受 system.message;其它事件变体尚不支持。返回的是已接纳事件;模型回复从事件历史或订阅读取。会话等待工具授权时发送的 user.message 会排队:返回的事件 processed_at 为 null,授权处理完成后按发送顺序执行。
错误按 Claude Managed Agents 格式返回,参见 错误码
请求示例
curl
# 先调用「创建会话」,用返回的会话 ID 替换示例 ID。
curl https://api.deepraxis.com/anthropic/v1/sessions/sesn_123/events \
-H "x-api-key: $PRAXIS_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: managed-agents-2026-04-01" \
-H "Content-Type: application/json" \
-d '{"events":[{"type":"user.message","content":[{"type":"text","text":"你好"}]}]}'Python
# 先调用「创建会话」,用返回的会话 ID 替换示例 ID。
from anthropic import Anthropic
client = Anthropic(
base_url="https://api.deepraxis.com/anthropic",
api_key="$PRAXIS_API_KEY",
)
result = client.beta.sessions.events.send("sesn_123", events=[{"type": "user.message", "content": [{"type": "text", "text": "你好"}]}])
print(result)TypeScript
// 先调用「创建会话」,用返回的会话 ID 替换示例 ID。
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://api.deepraxis.com/anthropic",
apiKey: "$PRAXIS_API_KEY",
});
const result = await client.beta.sessions.events.send("sesn_123", {
"events": [
{
"type": "user.message",
"content": [
{
"type": "text",
"text": "你好"
}
]
}
]
});
console.log(result);响应示例 200
{
"data": [
{
"id": "fa9087de-7935-45fb-b675-4cc50fac7af0",
"type": "user.message",
"processed_at": null,
"content": [
{
"type": "text",
"text": "你好"
}
]
}
]
}响应
HTTP 200
Successful response
application/json
| 名称 | 类型 | 说明 |
|---|---|---|
| data | array<object> | Sent events |
| data[].id | string | Unique identifier for this event. |
| data[].content | array<object> | Array of content blocks comprising the user message. / The result content returned by the tool. / The result content returned by the tool. / System content blocks. Text-only. |
| data[].type | string | |
| data[].processed_at | null | string | string | null | string | null | string | A timestamp in RFC 3339 format |
| data[].session_thread_id | null | string | If absent, interrupts every non-archived thread in a multiagent session (or the primary alone in a single-agent session). If present, interrupts only the named thread. / Set by the server to the subagent thread this confirmation was routed to. Omitted when it was routed to the primary thread. / Set by the server to the subagent thread this result was routed to. Omitted when it was routed to the primary thread. / Set by the server to the subagent thread this result was routed to. Omitted when it was routed to the primary thread. |
| data[].result | string | UserToolConfirmationResult enum |
| data[].tool_use_id | string | The id of the agent.tool_use or agent.mcp_tool_use event this result corresponds to, which can be found in the last session.status_idle event's stop_reason.event_ids field. / The id of the agent.tool_use event this result corresponds to, which can be found in the last session.status_idle event's stop_reason.event_ids field. |
| data[].deny_message | null | string | Optional message providing context for a 'deny' decision. Only allowed when result is 'deny'. |
| data[].custom_tool_use_id | string | The id of the agent.custom_tool_use event this result corresponds to, which can be found in the last session.status_idle event's stop_reason.event_ids field. |
| data[].is_error | null | boolean | Whether the tool execution resulted in an error. |
| data[].description | string | What the agent should produce. Copied from the input event. |
| data[].max_iterations | null | number | Evaluate-then-revise cycles before giving up. Default 3, max 20. |
| data[].outcome_id | string | Server-generated outc_ ID for this outcome. Referenced by span.outcome_evaluation_* events and the session's outcome_evaluations list. |
| data[].rubric | object | Rubric for grading the quality of an outcome. |