发送事件
post /v1/sessions/{session_id}/events
发送事件
路径参数
session_id: string
请求头参数
-
"anthropic-beta": optional array of AnthropicBeta可选的请求头,用于指定要使用的 beta 版本。
-
string -
"message-batches-2024-09-24" or "prompt-caching-2024-07-31" or "computer-use-2024-10-22" or 22 more-
"message-batches-2024-09-24" -
"prompt-caching-2024-07-31" -
"computer-use-2024-10-22" -
"computer-use-2025-01-24" -
"pdfs-2024-09-25" -
"token-counting-2024-11-01" -
"token-efficient-tools-2025-02-19" -
"output-128k-2025-02-19" -
"files-api-2025-04-14" -
"mcp-client-2025-04-04" -
"mcp-client-2025-11-20" -
"dev-full-thinking-2025-05-14" -
"interleaved-thinking-2025-05-14" -
"code-execution-2025-05-22" -
"extended-cache-ttl-2025-04-11" -
"context-1m-2025-08-07" -
"context-management-2025-06-27" -
"model-context-window-exceeded-2025-08-26" -
"skills-2025-10-02" -
"fast-mode-2026-02-01" -
"output-300k-2026-03-24" -
"user-profiles-2026-03-24" -
"advisor-tool-2026-03-01" -
"managed-agents-2026-04-01" -
"cache-diagnosis-2026-04-07"
-
-
请求体参数
-
events: array of BetaManagedAgentsEventParams要发送到
session的事件。-
BetaManagedAgentsUserMessageEventParams object { content, type }向会话发送用户消息的参数。
-
content: array of BetaManagedAgentsTextBlock or BetaManagedAgentsImageBlock or BetaManagedAgentsDocumentBlock用户消息的内容块数组。
-
BetaManagedAgentsTextBlock object { text, type }常规文本内容。
-
text: string文本内容。
-
type: "text""text"
-
-
BetaManagedAgentsImageBlock object { source, type }直接指定为 base64 数据或通过 URL 引用的图像内容。
-
source: BetaManagedAgentsBase64ImageSource or BetaManagedAgentsURLImageSource or BetaManagedAgentsFileImageSource图像源变体的联合类型。
-
BetaManagedAgentsBase64ImageSource object { data, media_type, type }Base64 编码的图像数据。
-
data: stringBase64 编码的图像数据。
-
media_type: string图像的 MIME 类型(例如 "image/png"、"image/jpeg"、"image/gif"、"image/webp")。
-
type: "base64""base64"
-
-
BetaManagedAgentsURLImageSource object { type, url }通过 URL 引用的图像。
-
type: "url""url"
-
url: string要获取的图像的 URL。
-
-
BetaManagedAgentsFileImageSource object { file_id, type }通过文件 ID 引用的图像。
-
file_id: string先前上传的文件的 ID。
-
type: "file""file"
-
-
-
type: "image""image"
-
-
BetaManagedAgentsDocumentBlock object { source, type, context, title }文档内容,直接指定为 base64 数据、文本或通过 URL 引用。
-
source: BetaManagedAgentsBase64DocumentSource or BetaManagedAgentsPlainTextDocumentSource or BetaManagedAgentsURLDocumentSource or BetaManagedAgentsFileDocumentSource文档源变体的联合类型。
-
BetaManagedAgentsBase64DocumentSource object { data, media_type, type }Base64 编码的文档数据。
-
data: stringBase64 编码的文档数据。
-
media_type: string文档的 MIME 类型(例如 "application/pdf")。
-
type: "base64""base64"
-
-
BetaManagedAgentsPlainTextDocumentSource object { data, media_type, type }纯文本文档内容。
-
data: string纯文本内容。
-
media_type: "text/plain"文本内容的 MIME 类型。必须为 "text/plain"。
"text/plain"
-
type: "text""text"
-
-
BetaManagedAgentsURLDocumentSource object { type, url }通过 URL 引用的文档。
-
type: "url""url"
-
url: string要获取的文档的 URL。
-
-
BetaManagedAgentsFileDocumentSource object { file_id, type }通过文件 ID 引用的文档。
-
file_id: string先前上传的文件的 ID。
-
type: "file""file"
-
-
-
type: "document""document"
-
context: optional string关于文档的附加上下文,供模型使用。
-
title: optional string文档的标题。
-
-
-
type: "user.message""user.message"
-
-
BetaManagedAgentsUserInterruptEventParams object { type, session_thread_id }发送中断以暂停代理的参数。
-
type: "user.interrupt""user.interrupt"
-
session_thread_id: optional string如果缺失,中断多代理会话中每个未归档的线程(或单代理会话中仅中断主线程)。如果存在,仅中断指定的线程。
-
-
BetaManagedAgentsUserToolConfirmationEventParams object { result, tool_use_id, type, deny_message }确认或拒绝工具执行请求的参数。
-
result: "allow" or "deny"UserToolConfirmationResult enum
-
"allow" -
"deny"
-
-
tool_use_id: string此结果对应的
agent.tool_use或agent.mcp_tool_use事件的 ID,可以在最后一个session.status_idle事件的stop_reason.event_ids字段中找到。 -
type: "user.tool_confirmation""user.tool_confirmation"
-
deny_message: optional string可选消息,为 'deny' 决策提供上下文。仅在结果为 'deny' 时允许。
-
-
BetaManagedAgentsUserCustomToolResultEventParams object { custom_tool_use_id, type, content, is_error }提供自定义工具执行结果的参数。
-
custom_tool_use_id: string此结果对应的
agent.custom_tool_use事件的 ID,可以在最后一个session.status_idle事件的stop_reason.event_ids字段中找到。 -
type: "user.custom_tool_result""user.custom_tool_result"
-
content: optional array of BetaManagedAgentsTextBlock or BetaManagedAgentsImageBlock or BetaManagedAgentsDocumentBlock or BetaManagedAgentsSearchResultBlock工具返回的结果内容。
-
BetaManagedAgentsTextBlock object { text, type }常规文本内容。
-
BetaManagedAgentsImageBlock object { source, type }直接指定为 base64 数据或通过 URL 引用的图像内容。
-
BetaManagedAgentsDocumentBlock object { source, type, context, title }文档内容,直接指定为 base64 数据、文本或通过 URL 引用。
-
BetaManagedAgentsSearchResultBlock object { citations, content, source, 2 more }包含网络搜索结果的块。
-
citations: BetaManagedAgentsSearchResultCitations搜索结果的引用设置。
-
enabled: boolean此搜索结果是否启用引用。
-
-
content: array of BetaManagedAgentsSearchResultContent搜索结果中的文本内容块数组。
-
text: string文本内容。
-
type: "text""text"
-
-
source: stringThe URL source of the search result.
-
title: string搜索结果的标题。
-
type: "search_result""search_result"
-
-
-
is_error: optional boolean工具执行是否导致错误。
-
-
BetaManagedAgentsUserDefineOutcomeEventParams object { description, rubric, type, max_iterations }定义代理应努力实现的结果的参数。代理在收到后开始工作。
-
description: string代理应产出的内容。 This is the task specification.
-
rubric: BetaManagedAgentsFileRubricParams or BetaManagedAgentsTextRubricParams用于评估结果质量的评分标准。
-
BetaManagedAgentsFileRubricParams object { file_id, type }通过 Files API 上传的文件引用的评估标准。
-
file_id: stringID of the rubric file.
-
type: "file""file"
-
-
BetaManagedAgentsTextRubricParams object { content, type }以内联文本形式提供的评估标准内容。
-
content: string评分标准内容。纯文本或 markdown — 评分器将其视为自由格式文本。 Maximum 262144 characters.
-
type: "text""text"
-
-
-
type: "user.define_outcome""user.define_outcome"
-
max_iterations: optional numberEval→revision cycles before giving up. Default 3, max 20.
-
-
BetaManagedAgentsUserToolResultEventParams object { tool_use_id, type, content, is_error }提供代理工具集工具执行结果的参数。仅在
self_hosted环境中有效,其中沙箱路由的工具由客户端而非服务器执行。-
tool_use_id: string此结果对应的
agent.tool_use事件的 ID,可以在最后一个session.status_idle事件的stop_reason.event_ids字段中找到。 -
type: "user.tool_result""user.tool_result"
-
content: optional array of BetaManagedAgentsTextBlock or BetaManagedAgentsImageBlock or BetaManagedAgentsDocumentBlock or BetaManagedAgentsSearchResultBlock工具返回的结果内容。
-
BetaManagedAgentsTextBlock object { text, type }常规文本内容。
-
BetaManagedAgentsImageBlock object { source, type }直接指定为 base64 数据或通过 URL 引用的图像内容。
-
BetaManagedAgentsDocumentBlock object { source, type, context, title }文档内容,直接指定为 base64 数据、文本或通过 URL 引用。
-
BetaManagedAgentsSearchResultBlock object { citations, content, source, 2 more }包含网络搜索结果的块。
-
-
is_error: optional boolean工具执行是否导致错误。
-
-
返回值
-
BetaManagedAgentsSendSessionEvents object { data }成功发送到会话的事件。
-
data: optional array of BetaManagedAgentsUserMessageEvent or BetaManagedAgentsUserInterruptEvent or BetaManagedAgentsUserToolConfirmationEvent or 3 more已发送的事件
-
BetaManagedAgentsUserMessageEvent object { id, content, type, processed_at }会话对话中的用户消息事件。
-
id: string此事件的唯一标识符。
-
content: array of BetaManagedAgentsTextBlock or BetaManagedAgentsImageBlock or BetaManagedAgentsDocumentBlock构成用户消息的内容块数组。
-
BetaManagedAgentsTextBlock object { text, type }常规文本内容。
-
text: string文本内容。
-
type: "text""text"
-
-
BetaManagedAgentsImageBlock object { source, type }直接指定为 base64 数据或通过 URL 引用的图像内容。
-
source: BetaManagedAgentsBase64ImageSource or BetaManagedAgentsURLImageSource or BetaManagedAgentsFileImageSource图像源变体的联合类型。
-
BetaManagedAgentsBase64ImageSource object { data, media_type, type }Base64 编码的图像数据。
-
data: stringBase64 编码的图像数据。
-
media_type: string图像的 MIME 类型(例如 "image/png"、"image/jpeg"、"image/gif"、"image/webp")。
-
type: "base64""base64"
-
-
BetaManagedAgentsURLImageSource object { type, url }通过 URL 引用的图像。
-
type: "url""url"
-
url: string要获取的图像的 URL。
-
-
BetaManagedAgentsFileImageSource object { file_id, type }通过文件 ID 引用的图像。
-
file_id: string先前上传的文件的 ID。
-
type: "file""file"
-
-
-
type: "image""image"
-
-
BetaManagedAgentsDocumentBlock object { source, type, context, title }文档内容,直接指定为 base64 数据、文本或通过 URL 引用。
-
source: BetaManagedAgentsBase64DocumentSource or BetaManagedAgentsPlainTextDocumentSource or BetaManagedAgentsURLDocumentSource or BetaManagedAgentsFileDocumentSource文档源变体的联合类型。
-
BetaManagedAgentsBase64DocumentSource object { data, media_type, type }Base64 编码的文档数据。
-
data: stringBase64 编码的文档数据。
-
media_type: string文档的 MIME 类型(例如 "application/pdf")。
-
type: "base64""base64"
-
-
BetaManagedAgentsPlainTextDocumentSource object { data, media_type, type }纯文本文档内容。
-
data: string纯文本内容。
-
media_type: "text/plain"文本内容的 MIME 类型。必须为 "text/plain"。
"text/plain"
-
type: "text""text"
-
-
BetaManagedAgentsURLDocumentSource object { type, url }通过 URL 引用的文档。
-
type: "url""url"
-
url: string要获取的文档的 URL。
-
-
BetaManagedAgentsFileDocumentSource object { file_id, type }通过文件 ID 引用的文档。
-
file_id: string先前上传的文件的 ID。
-
type: "file""file"
-
-
-
type: "document""document"
-
context: optional string关于文档的附加上下文,供模型使用。
-
title: optional string文档的标题。
-
-
-
type: "user.message""user.message"
-
processed_at: optional stringRFC 3339 格式的时间戳
-
-
BetaManagedAgentsUserInterruptEvent object { id, type, processed_at, session_thread_id }暂停代理执行并将控制权返回给用户的中断事件。
-
id: string此事件的唯一标识符。
-
type: "user.interrupt""user.interrupt"
-
processed_at: optional stringRFC 3339 格式的时间戳
-
session_thread_id: optional string如果缺失,中断多代理会话中每个未归档的线程(或单代理会话中仅中断主线程)。如果存在,仅中断指定的线程。
-
-
BetaManagedAgentsUserToolConfirmationEvent object { id, result, tool_use_id, 4 more }批准或拒绝待处理工具执行的工具确认事件。
-
id: string此事件的唯一标识符。
-
result: "allow" or "deny"UserToolConfirmationResult enum
-
"allow" -
"deny"
-
-
tool_use_id: string此结果对应的
agent.tool_use或agent.mcp_tool_use事件的 ID,可以在最后一个session.status_idle事件的stop_reason.event_ids字段中找到。 -
type: "user.tool_confirmation""user.tool_confirmation"
-
deny_message: optional string可选消息,为 'deny' 决策提供上下文。仅在结果为 'deny' 时允许。
-
processed_at: optional stringRFC 3339 格式的时间戳
-
session_thread_id: optional string设置后,确认将路由到此子代理的线程而非主线程。从触发批准的
agent.tool_use或agent.mcp_tool_use事件的session_thread_id回显此值。
-
-
BetaManagedAgentsUserCustomToolResultEvent object { id, custom_tool_use_id, type, 4 more }客户端发送的事件,提供自定义工具执行的结果。
-
id: string此事件的唯一标识符。
-
custom_tool_use_id: string此结果对应的
agent.custom_tool_use事件的 ID,可以在最后一个session.status_idle事件的stop_reason.event_ids字段中找到。 -
type: "user.custom_tool_result""user.custom_tool_result"
-
content: optional array of BetaManagedAgentsTextBlock or BetaManagedAgentsImageBlock or BetaManagedAgentsDocumentBlock or BetaManagedAgentsSearchResultBlock工具返回的结果内容。
-
BetaManagedAgentsTextBlock object { text, type }常规文本内容。
-
BetaManagedAgentsImageBlock object { source, type }直接指定为 base64 数据或通过 URL 引用的图像内容。
-
BetaManagedAgentsDocumentBlock object { source, type, context, title }文档内容,直接指定为 base64 数据、文本或通过 URL 引用。
-
BetaManagedAgentsSearchResultBlock object { citations, content, source, 2 more }包含网络搜索结果的块。
-
citations: BetaManagedAgentsSearchResultCitations搜索结果的引用设置。
-
enabled: boolean此搜索结果是否启用引用。
-
-
content: array of BetaManagedAgentsSearchResultContent搜索结果中的文本内容块数组。
-
text: string文本内容。
-
type: "text""text"
-
-
source: stringThe URL source of the search result.
-
title: string搜索结果的标题。
-
type: "search_result""search_result"
-
-
-
is_error: optional boolean工具执行是否导致错误。
-
processed_at: optional stringRFC 3339 格式的时间戳
-
session_thread_id: optional string将此结果路由到子代理线程。从
agent.custom_tool_use事件的session_thread_id复制。
-
-
BetaManagedAgentsUserDefineOutcomeEvent object { id, description, max_iterations, 4 more }user.define_outcome输入事件的回显。携带后续span.outcome_evaluation_*事件引用的服务器生成的outcome_id。-
id: string此事件的唯一标识符。
-
description: string代理应产出的内容。从输入事件复制。
-
max_iterations: number放弃前的评估然后修订循环。默认 3,最大 20。
-
outcome_id: string此结果的服务器生成的
outc_ID。由span.outcome_evaluation_*事件和会话的outcome_evaluations列表引用。 -
processed_at: stringRFC 3339 格式的时间戳
-
rubric: BetaManagedAgentsFileRubric or BetaManagedAgentsTextRubric用于评估结果质量的评分标准。
-
BetaManagedAgentsFileRubric object { file_id, type }通过 Files API 上传的文件引用的评估标准。
-
file_id: stringID of the rubric file.
-
type: "file""file"
-
-
BetaManagedAgentsTextRubric object { content, type }以内联文本形式提供的评估标准内容。
-
content: string评分标准内容。纯文本或 markdown — 评分器将其视为自由格式文本。
-
type: "text""text"
-
-
-
type: "user.define_outcome""user.define_outcome"
-
-
BetaManagedAgentsUserToolResultEvent object { id, tool_use_id, type, 4 more }客户端发送的事件,提供代理工具集工具执行的结果。仅在
self_hosted环境中有效,其中沙箱路由的工具由客户端而非服务器执行。-
id: string此事件的唯一标识符。
-
tool_use_id: string此结果对应的
agent.tool_use事件的 ID,可以在最后一个session.status_idle事件的stop_reason.event_ids字段中找到。 -
type: "user.tool_result""user.tool_result"
-
content: optional array of BetaManagedAgentsTextBlock or BetaManagedAgentsImageBlock or BetaManagedAgentsDocumentBlock or BetaManagedAgentsSearchResultBlock工具返回的结果内容。
-
BetaManagedAgentsTextBlock object { text, type }常规文本内容。
-
BetaManagedAgentsImageBlock object { source, type }直接指定为 base64 数据或通过 URL 引用的图像内容。
-
BetaManagedAgentsDocumentBlock object { source, type, context, title }文档内容,直接指定为 base64 数据、文本或通过 URL 引用。
-
BetaManagedAgentsSearchResultBlock object { citations, content, source, 2 more }包含网络搜索结果的块。
-
-
is_error: optional boolean工具执行是否导致错误。
-
processed_at: optional stringRFC 3339 格式的时间戳
-
session_thread_id: optional string将此结果路由到子代理线程。从
agent.tool_use事件的session_thread_id复制。
-
-
-
示例
curl https://api.anthropic.com/v1/sessions/$SESSION_ID/events \
-H 'Content-Type: application/json' \
-H 'anthropic-version: 2023-06-01' \
-H 'anthropic-beta: managed-agents-2026-04-01' \
-H "X-Api-Key: $ANTHROPIC_API_KEY" \
-d '{
"events": [
{
"content": [
{
"text": "Where is my order #1234?",
"type": "text"
}
],
"type": "user.message"
}
]
}'
响应
{
"data": [
{
"id": "sevt_011CZkZGOp0iBcp4kaQSihUmy",
"content": [
{
"text": "Where is my order #1234?",
"type": "text"
}
],
"type": "user.message",
"processed_at": "2026-03-15T10:00:00Z"
}
]
}