获取消息批处理结果
get /v1/messages/batches/{message_batch_id}/results
以 .jsonl 文件流式传输消息批处理的结果。
文件中的每一行都是一个 JSON 对象,包含消息批处理中单个请求的结果。结果不保证与请求的顺序相同。使用 custom_id 字段将结果与请求进行匹配。
在我们的用户指南中了解更多关于 Message Batches API 的信息
路径参数
-
message_batch_id: string消息批处理的 ID。
返回值
-
MessageBatchIndividualResponse object { custom_id, result }这是响应
.jsonl文件中的单行,并不代表整个响应。-
custom_id: string开发者为消息批处理中每个请求创建的 ID。用于将结果与请求进行匹配,因为结果可能不按请求顺序给出。
在消息批处理中,每个请求必须唯一。
-
result: MessageBatchResult此请求的处理结果。
如果处理成功则包含消息输出,如果处理失败则包含错误响应,或未尝试处理的原因(如取消或过期)。
-
MessageBatchSucceededResult object { message, type }-
message: Message-
id: string唯一对象标识符。
ID 的格式和长度可能会随时间变化。
-
container: Container请求中使用的容器信息(用于代码执行工具)
-
id: string此请求中使用的容器标识符
-
expires_at: string容器将过期的时间。
-
-
content: array of ContentBlock模型生成的内容。
这是一个内容块数组,每个块都有一个
type来决定其形状。Example:
[{"type": "text", "text": "Hi, I'm Claude."}]如果请求输入
messages以assistant轮次结束,则响应content将直接从该轮次继续。您可以使用此来约束模型的输出。例如,如果输入
messages为:[ {"role": "user", "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"}, {"role": "assistant", "content": "The best answer is ("} ]则响应
content可能为:[{"type": "text", "text": "B)"}]-
TextBlock object { citations, text, type }-
citations: array of TextCitation支持文本块的引用。
返回的引用类型取决于被引用文档的类型。引用 PDF 会产生
page_location, plain text results inchar_location, and content document results incontent_block_location.-
CitationCharLocation object { cited_text, document_index, document_title, 4 more }-
cited_text: string -
document_index: number -
document_title: string -
end_char_index: number -
file_id: string -
start_char_index: number -
type: "char_location""char_location"
-
-
CitationPageLocation object { cited_text, document_index, document_title, 4 more }-
cited_text: string -
document_index: number -
document_title: string -
end_page_number: number -
file_id: string -
start_page_number: number -
type: "page_location""page_location"
-
-
CitationContentBlockLocation object { cited_text, document_index, document_title, 4 more }-
cited_text: string引用块范围的完整文本,已连接。
始终等于
content[start_block_index:end_block_index]内容的连接。文本块是最小可引用单元;此字段永远不会是单个块的子字符串。不计入输出 token,在后续轮次中发回时也不计入输入 token。 -
document_index: number -
document_title: string -
end_block_index: number源
content数组中引用块范围的排他性 0 基结束索引。始终大于
start_block_index;单块引用的end_block_index = start_block_index + 1。 -
file_id: string -
start_block_index: number源
content数组中第一个引用块的 0 基索引。 -
type: "content_block_location""content_block_location"
-
-
CitationsWebSearchResultLocation object { cited_text, encrypted_index, title, 2 more }-
cited_text: string -
encrypted_index: string -
title: string -
type: "web_search_result_location""web_search_result_location"
-
url: string
-
-
CitationsSearchResultLocation object { cited_text, end_block_index, search_result_index, 4 more }-
cited_text: string引用块范围的完整文本,已连接。
始终等于
content[start_block_index:end_block_index]内容的连接。文本块是最小可引用单元;此字段永远不会是单个块的子字符串。不计入输出 token,在后续轮次中发回时也不计入输入 token。 -
end_block_index: number源
content数组中引用块范围的排他性 0 基结束索引。始终大于
start_block_index;单块引用的end_block_index = start_block_index + 1。 -
search_result_index: number在请求中所有
search_result内容块中引用搜索结果的 0 基索引,按其在消息和工具结果中出现的顺序排列。与
document_index分开计数;服务器端 Web 搜索结果不包含在此计数中。 -
source: string -
start_block_index: number源
content数组中第一个引用块的 0 基索引。 -
title: string -
type: "search_result_location""search_result_location"
-
-
-
text: string -
type: "text""text"
-
-
ThinkingBlock object { signature, thinking, type }-
signature: string -
thinking: string -
type: "thinking""thinking"
-
-
RedactedThinkingBlock object { data, type }-
data: string -
type: "redacted_thinking""redacted_thinking"
-
-
ToolUseBlock object { id, caller, input, 2 more }-
id: string -
caller: DirectCaller or ServerToolCaller or ServerToolCaller20260120直接来自模型的工具调用。
-
DirectCaller object { type }直接来自模型的工具调用。
-
type: "direct""direct"
-
-
ServerToolCaller object { tool_id, type }由服务器端工具生成的工具调用。
-
tool_id: string -
type: "code_execution_20250825""code_execution_20250825"
-
-
ServerToolCaller20260120 object { tool_id, type }-
tool_id: string -
type: "code_execution_20260120""code_execution_20260120"
-
-
-
input: map[unknown] -
name: string -
type: "tool_use""tool_use"
-
-
ServerToolUseBlock object { id, caller, input, 2 more }-
id: string -
caller: DirectCaller or ServerToolCaller or ServerToolCaller20260120直接来自模型的工具调用。
-
DirectCaller object { type }直接来自模型的工具调用。
-
ServerToolCaller object { tool_id, type }由服务器端工具生成的工具调用。
-
ServerToolCaller20260120 object { tool_id, type }
-
-
input: map[unknown] -
name: "web_search" or "web_fetch" or "code_execution" or 4 more-
"web_search" -
"web_fetch" -
"code_execution" -
"bash_code_execution" -
"text_editor_code_execution" -
"tool_search_tool_regex" -
"tool_search_tool_bm25"
-
-
type: "server_tool_use""server_tool_use"
-
-
WebSearchToolResultBlock object { caller, content, tool_use_id, type }-
caller: DirectCaller or ServerToolCaller or ServerToolCaller20260120直接来自模型的工具调用。
-
DirectCaller object { type }直接来自模型的工具调用。
-
ServerToolCaller object { tool_id, type }由服务器端工具生成的工具调用。
-
ServerToolCaller20260120 object { tool_id, type }
-
-
content: WebSearchToolResultBlockContent-
WebSearchToolResultError object { error_code, type }-
error_code: WebSearchToolResultErrorCode-
"invalid_tool_input" -
"unavailable" -
"max_uses_exceeded" -
"too_many_requests" -
"query_too_long" -
"request_too_large"
-
-
type: "web_search_tool_result_error""web_search_tool_result_error"
-
-
array of WebSearchResultBlock-
encrypted_content: string -
page_age: string -
title: string -
type: "web_search_result""web_search_result"
-
url: string
-
-
-
tool_use_id: string -
type: "web_search_tool_result""web_search_tool_result"
-
-
WebFetchToolResultBlock object { caller, content, tool_use_id, type }-
caller: DirectCaller or ServerToolCaller or ServerToolCaller20260120直接来自模型的工具调用。
-
DirectCaller object { type }直接来自模型的工具调用。
-
ServerToolCaller object { tool_id, type }由服务器端工具生成的工具调用。
-
ServerToolCaller20260120 object { tool_id, type }
-
-
content: WebFetchToolResultErrorBlock or WebFetchBlock-
WebFetchToolResultErrorBlock object { error_code, type }-
error_code: WebFetchToolResultErrorCode-
"invalid_tool_input" -
"url_too_long" -
"url_not_allowed" -
"url_not_accessible" -
"unsupported_content_type" -
"too_many_requests" -
"max_uses_exceeded" -
"unavailable"
-
-
type: "web_fetch_tool_result_error""web_fetch_tool_result_error"
-
-
WebFetchBlock object { content, retrieved_at, type, url }-
content: DocumentBlock-
citations: CitationsConfig文档的引用配置
enabled: boolean
-
source: Base64PDFSource or PlainTextSource-
Base64PDFSource object { data, media_type, type }-
data: string -
media_type: "application/pdf""application/pdf"
-
type: "base64""base64"
-
-
PlainTextSource object { data, media_type, type }-
data: string -
media_type: "text/plain""text/plain"
-
type: "text""text"
-
-
-
title: string文档标题
-
type: "document""document"
-
-
retrieved_at: string获取内容时的 ISO 8601 时间戳
-
type: "web_fetch_result""web_fetch_result"
-
url: string获取的内容 URL
-
-
-
tool_use_id: string -
type: "web_fetch_tool_result""web_fetch_tool_result"
-
-
CodeExecutionToolResultBlock object { content, tool_use_id, type }-
content: CodeExecutionToolResultBlockContentPFC + web_search 结果的带加密标准输出的代码执行结果。
-
CodeExecutionToolResultError object { error_code, type }-
error_code: CodeExecutionToolResultErrorCode-
"invalid_tool_input" -
"unavailable" -
"too_many_requests" -
"execution_time_exceeded"
-
-
type: "code_execution_tool_result_error""code_execution_tool_result_error"
-
-
CodeExecutionResultBlock object { content, return_code, stderr, 2 more }-
content: array of CodeExecutionOutputBlock-
file_id: string -
type: "code_execution_output""code_execution_output"
-
-
return_code: number -
stderr: string -
stdout: string -
type: "code_execution_result""code_execution_result"
-
-
EncryptedCodeExecutionResultBlock object { content, encrypted_stdout, return_code, 2 more }PFC + web_search 结果的带加密标准输出的代码执行结果。
-
content: array of CodeExecutionOutputBlock-
file_id: string -
type: "code_execution_output"
-
-
encrypted_stdout: string -
return_code: number -
stderr: string -
type: "encrypted_code_execution_result""encrypted_code_execution_result"
-
-
-
tool_use_id: string -
type: "code_execution_tool_result""code_execution_tool_result"
-
-
BashCodeExecutionToolResultBlock object { content, tool_use_id, type }-
content: BashCodeExecutionToolResultError or BashCodeExecutionResultBlock-
BashCodeExecutionToolResultError object { error_code, type }-
error_code: BashCodeExecutionToolResultErrorCode-
"invalid_tool_input" -
"unavailable" -
"too_many_requests" -
"execution_time_exceeded" -
"output_file_too_large"
-
-
type: "bash_code_execution_tool_result_error""bash_code_execution_tool_result_error"
-
-
BashCodeExecutionResultBlock object { content, return_code, stderr, 2 more }-
content: array of BashCodeExecutionOutputBlock-
file_id: string -
type: "bash_code_execution_output""bash_code_execution_output"
-
-
return_code: number -
stderr: string -
stdout: string -
type: "bash_code_execution_result""bash_code_execution_result"
-
-
-
tool_use_id: string -
type: "bash_code_execution_tool_result""bash_code_execution_tool_result"
-
-
TextEditorCodeExecutionToolResultBlock object { content, tool_use_id, type }-
content: TextEditorCodeExecutionToolResultError or TextEditorCodeExecutionViewResultBlock or TextEditorCodeExecutionCreateResultBlock or TextEditorCodeExecutionStrReplaceResultBlock-
TextEditorCodeExecutionToolResultError object { error_code, error_message, type }-
error_code: TextEditorCodeExecutionToolResultErrorCode-
"invalid_tool_input" -
"unavailable" -
"too_many_requests" -
"execution_time_exceeded" -
"file_not_found"
-
-
error_message: string -
type: "text_editor_code_execution_tool_result_error""text_editor_code_execution_tool_result_error"
-
-
TextEditorCodeExecutionViewResultBlock object { content, file_type, num_lines, 3 more }-
content: string -
file_type: "text" or "image" or "pdf"-
"text" -
"image" -
"pdf"
-
-
num_lines: number -
start_line: number -
total_lines: number -
type: "text_editor_code_execution_view_result""text_editor_code_execution_view_result"
-
-
TextEditorCodeExecutionCreateResultBlock object { is_file_update, type }-
is_file_update: boolean -
type: "text_editor_code_execution_create_result""text_editor_code_execution_create_result"
-
-
TextEditorCodeExecutionStrReplaceResultBlock object { lines, new_lines, new_start, 3 more }-
lines: array of string -
new_lines: number -
new_start: number -
old_lines: number -
old_start: number -
type: "text_editor_code_execution_str_replace_result""text_editor_code_execution_str_replace_result"
-
-
-
tool_use_id: string -
type: "text_editor_code_execution_tool_result""text_editor_code_execution_tool_result"
-
-
ToolSearchToolResultBlock object { content, tool_use_id, type }-
content: ToolSearchToolResultError or ToolSearchToolSearchResultBlock-
ToolSearchToolResultError object { error_code, error_message, type }-
error_code: ToolSearchToolResultErrorCode-
"invalid_tool_input" -
"unavailable" -
"too_many_requests" -
"execution_time_exceeded"
-
-
error_message: string -
type: "tool_search_tool_result_error""tool_search_tool_result_error"
-
-
ToolSearchToolSearchResultBlock object { tool_references, type }-
tool_references: array of ToolReferenceBlock-
tool_name: string -
type: "tool_reference""tool_reference"
-
-
type: "tool_search_tool_search_result""tool_search_tool_search_result"
-
-
-
tool_use_id: string -
type: "tool_search_tool_result""tool_search_tool_result"
-
-
ContainerUploadBlock object { file_id, type }上传到容器的文件的响应模型。
-
file_id: string -
type: "container_upload""container_upload"
-
-
-
model: Model将完成您的提示的模型。
详见模型了解更多信息和选项。
-
"claude-opus-4-7" or "claude-mythos-preview" or "claude-opus-4-6" or 14 more将完成您的提示的模型。
详见模型了解更多信息和选项。
-
"claude-opus-4-7"用于长时间运行的智能体和编程的前沿智能
-
"claude-mythos-preview"新一代智能,在编程和网络安全方面最强
-
"claude-opus-4-6"用于长时间运行的智能体和编程的前沿智能
-
"claude-sonnet-4-6"速度与智能的最佳组合
-
"claude-haiku-4-5"具有接近前沿智能的最快模型
-
"claude-haiku-4-5-20251001"具有接近前沿智能的最快模型
-
"claude-opus-4-5"结合最高智能与实用性能的高级模型
-
"claude-opus-4-5-20251101"结合最高智能与实用性能的高级模型
-
"claude-sonnet-4-5"用于智能体和编程的高性能模型
-
"claude-sonnet-4-5-20250929"用于智能体和编程的高性能模型
-
"claude-opus-4-1"用于专业复杂任务的卓越模型
-
"claude-opus-4-1-20250805"用于专业复杂任务的卓越模型
-
"claude-opus-4-0"用于复杂任务的强大模型
-
"claude-opus-4-20250514"用于复杂任务的强大模型
-
"claude-sonnet-4-0"具有扩展思考能力的高性能模型
-
"claude-sonnet-4-20250514"具有扩展思考能力的高性能模型
-
"claude-3-haiku-20240307"快速且经济高效的模型
-
-
string
-
-
role: "assistant"生成消息的对话角色。
这将始终为
"assistant"。"assistant"
-
stop_details: RefusalStopDetails关于拒绝的结构化信息。
-
category: "cyber" or "bio"触发拒绝的策略类别。
当拒绝未映射到命名类别时为
null。-
"cyber" -
"bio"
-
-
explanation: string拒绝的人类可读解释。
此文本不保证稳定。当该类别没有可用解释时为
null。 -
type: "refusal""refusal"
-
-
stop_reason: StopReason停止的原因。
这可能是以下值之一:
"end_turn": 模型到达自然停止点"max_tokens": 我们超过了请求的max_tokens或模型的最大值"stop_sequence": 生成了您提供的自定义stop_sequences之一"tool_use": 模型调用了一个或多个工具"pause_turn": 我们暂停了一个长时间运行的轮次。您可以在后续请求中原样提供响应,让模型继续。"refusal": 当流式分类器介入处理潜在策略违规时
在非流式模式下,此值始终非空。在流式模式下,
message_start事件中为 null,其他情况下非空。-
"end_turn" -
"max_tokens" -
"stop_sequence" -
"tool_use" -
"pause_turn" -
"refusal"
-
stop_sequence: string生成了哪个自定义停止序列(如果有)。
如果生成了您的自定义停止序列之一,此值将为非空字符串。
-
type: "message"对象类型。
对于消息,始终为
"message"。"message"
-
usage: Usage计费和速率限制使用情况。
Anthropic 的 API 按 token 计数计费和限制速率,因为 token 代表了我们系统的底层成本。
在底层,API 将请求转换为适合模型的格式。然后模型的输出经过解析阶段,成为 API 响应。因此,
usage中的 token 计数不会与 API 请求或响应的确切可见内容一一对应。例如,即使 Claude 返回空字符串响应,
output_tokens也不会为零。请求中的总输入 token 数是
input_tokens、cache_creation_input_tokens和cache_read_input_tokens的总和。-
cache_creation: CacheCreation按 TTL 分解的缓存 token
-
ephemeral_1h_input_tokens: number用于创建 1 小时缓存条目的输入 token 数量。
-
ephemeral_5m_input_tokens: number用于创建 5 分钟缓存条目的输入 token 数量。
-
-
cache_creation_input_tokens: number用于创建缓存条目的输入 token 数量。
-
cache_read_input_tokens: number从缓存中读取的输入 token 数量。
-
inference_geo: string此请求执行推理的地理区域。
-
input_tokens: number使用的输入 token 数量。
-
output_tokens: number使用的输出 token 数量。
-
server_tool_use: ServerToolUsage服务器工具请求数量。
-
web_fetch_requests: numberWeb 获取工具请求数量。
-
web_search_requests: numberWeb 搜索工具请求数量。
-
-
service_tier: "standard" or "priority" or "batch"请求是否使用了优先级、标准或批处理层级。
-
"standard" -
"priority" -
"batch"
-
-
-
-
type: "succeeded""succeeded"
-
-
MessageBatchErroredResult object { error, type }-
error: ErrorResponse-
error: ErrorObject-
InvalidRequestError object { message, type }-
message: string -
type: "invalid_request_error""invalid_request_error"
-
-
AuthenticationError object { message, type }-
message: string -
type: "authentication_error""authentication_error"
-
-
BillingError object { message, type }-
message: string -
type: "billing_error""billing_error"
-
-
PermissionError object { message, type }-
message: string -
type: "permission_error""permission_error"
-
-
NotFoundError object { message, type }-
message: string -
type: "not_found_error""not_found_error"
-
-
RateLimitError object { message, type }-
message: string -
type: "rate_limit_error""rate_limit_error"
-
-
GatewayTimeoutError object { message, type }-
message: string -
type: "timeout_error""timeout_error"
-
-
APIErrorObject object { message, type }-
message: string -
type: "api_error""api_error"
-
-
OverloadedError object { message, type }-
message: string -
type: "overloaded_error""overloaded_error"
-
-
-
request_id: string -
type: "error""error"
-
-
type: "errored""errored"
-
-
MessageBatchCanceledResult object { type }-
type: "canceled""canceled"
-
-
MessageBatchExpiredResult object { type }-
type: "expired""expired"
-
-
-
Example
curl https://api.anthropic.com/v1/messages/batches/$MESSAGE_BATCH_ID/results \
-H 'anthropic-version: 2023-06-01' \
-H "X-Api-Key: $ANTHROPIC_API_KEY"