English ← MyDocs

发送事件

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

                Base64 编码的图像数据。

              • 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: string

                Base64 编码的文档数据。

              • 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_useagent.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: string

            The 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: string

            ID 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 number

        Eval→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: string

                  Base64 编码的图像数据。

                • 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: string

                  Base64 编码的文档数据。

                • 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 string

          RFC 3339 格式的时间戳

      • BetaManagedAgentsUserInterruptEvent object { id, type, processed_at, session_thread_id }

        暂停代理执行并将控制权返回给用户的中断事件。

        • id: string

          此事件的唯一标识符。

        • type: "user.interrupt"

          • "user.interrupt"
        • processed_at: optional string

          RFC 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_useagent.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 string

          RFC 3339 格式的时间戳

        • session_thread_id: optional string

          设置后,确认将路由到此子代理的线程而非主线程。从触发批准的 agent.tool_useagent.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: string

              The URL source of the search result.

            • title: string

              搜索结果的标题。

            • type: "search_result"

              • "search_result"
        • is_error: optional boolean

          工具执行是否导致错误。

        • processed_at: optional string

          RFC 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: string

          RFC 3339 格式的时间戳

        • rubric: BetaManagedAgentsFileRubric or BetaManagedAgentsTextRubric

          用于评估结果质量的评分标准。

          • BetaManagedAgentsFileRubric object { file_id, type }

            通过 Files API 上传的文件引用的评估标准。

            • file_id: string

              ID 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 string

          RFC 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"
    }
  ]
}