Retrieve Message Batch results
$ ant beta:messages:batches resultsStreams the results of a Message Batch as a .jsonl file.
Each line in the file is a JSON object containing the result of a single request in the Message Batch. Results are not guaranteed to be in the same order as requests. Use the custom_id field to match results to requests.
Learn more about the Message Batches API in our user guide
Returns
result: BetaMessageBatchSucceededResult { message, type } or BetaMessageBatchErroredResult { error, type } or BetaMessageBatchCanceledResult { type } or BetaMessageBatchExpiredResult { type }Processing result for this request.
Processing result for this request.
Contains a Message output if processing was successful, an error response if processing failed, or the reason why processing was not attempted, such as cancellation or expiration.
Content generated by the model.
Content generated by the model.
This is an array of content blocks, each of which has a type that determines its shape.
Example:
[{"type": "text", "text": "Hi, I'm Claude."}]If the request input messages ended with an assistant turn, then the response content will continue directly from that last turn. You can use this to constrain the model's output.
For example, if the input messages were:
[
{"role": "user", "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"},
{"role": "assistant", "content": "The best answer is ("}
]Then the response content might be:
[{"type": "text", "text": "B)"}]
Citations supporting the text block.
Citations supporting the text block.
The type of citation returned will depend on the type of document being cited. Citing a PDF results in page_location, plain text results in char_location, and content document results in content_block_location.
Always equals the contents of content[start_block_index:end_block_index] joined together. The text block is the minimal citable unit; this field is never a substring of a single block. Not counted toward output tokens, and not counted toward input tokens when sent back in subsequent turns.
Always greater than start_block_index; a single-block citation has end_block_index = start_block_index + 1.
Always equals the contents of content[start_block_index:end_block_index] joined together. The text block is the minimal citable unit; this field is never a substring of a single block. Not counted toward output tokens, and not counted toward input tokens when sent back in subsequent turns.
Always greater than start_block_index; a single-block citation has end_block_index = start_block_index + 1.
Counted separately from document_index; server-side web search results are not included in this count.
This is an opaque field and should not be interpreted or parsed. When passing thinking blocks back to the API (required when using tools with extended thinking), pass them back exactly as received, with this field intact.
See extended thinking for details.
Pass redacted_thinking blocks back to the API unchanged when continuing a multi-turn conversation.
See extended thinking for details.
caller: optional BetaDirectCaller { type } or BetaServerToolCaller { tool_id, type } or BetaServerToolCaller20260120 { tool_id, type }Tool invocation directly from the model.
Tool invocation directly from the model.
caller: optional BetaDirectCaller { type } or BetaServerToolCaller { tool_id, type } or BetaServerToolCaller20260120 { tool_id, type }Tool invocation directly from the model.
Tool invocation directly from the model.
content: BetaWebSearchToolResultError { error_code, type } or array of BetaWebSearchResultBlock { encrypted_content, page_age, title, 2 more }
caller: optional BetaDirectCaller { type } or BetaServerToolCaller { tool_id, type } or BetaServerToolCaller20260120 { tool_id, type }Tool invocation directly from the model.
Tool invocation directly from the model.
content: BetaWebFetchToolResultErrorBlock { error_code, type } or BetaWebFetchBlock { content, retrieved_at, type, url }
caller: optional BetaDirectCaller { type } or BetaServerToolCaller { tool_id, type } or BetaServerToolCaller20260120 { tool_id, type }Tool invocation directly from the model.
Tool invocation directly from the model.
content: BetaAdvisorToolResultError { error_code, type } or BetaAdvisorResultBlock { stop_reason, text, type } or BetaAdvisorRedactedResultBlock { encrypted_content, stop_reason, type }
content: BetaCodeExecutionToolResultError { error_code, type } or BetaCodeExecutionResultBlock { content, return_code, stderr, 2 more } or BetaEncryptedCodeExecutionResultBlock { content, encrypted_stdout, return_code, 2 more }Code execution result with encrypted stdout for PFC + web_search results.
Code execution result with encrypted stdout for PFC + web_search results.
content: BetaBashCodeExecutionToolResultError { error_code, type } or BetaBashCodeExecutionResultBlock { content, return_code, stderr, 2 more }
content: BetaTextEditorCodeExecutionToolResultError { error_code, error_message, type } or BetaTextEditorCodeExecutionViewResultBlock { content, file_type, num_lines, 3 more } or BetaTextEditorCodeExecutionCreateResultBlock { is_file_update, type } or BetaTextEditorCodeExecutionStrReplaceResultBlock { lines, new_lines, new_start, 3 more }
content: BetaToolSearchToolResultError { error_code, error_message, type } or BetaToolSearchToolSearchResultBlock { tool_references, type }
Citations supporting the text block.
Citations supporting the text block.
The type of citation returned will depend on the type of document being cited. Citing a PDF results in page_location, plain text results in char_location, and content document results in content_block_location.
Always equals the contents of content[start_block_index:end_block_index] joined together. The text block is the minimal citable unit; this field is never a substring of a single block. Not counted toward output tokens, and not counted toward input tokens when sent back in subsequent turns.
Always greater than start_block_index; a single-block citation has end_block_index = start_block_index + 1.
Always equals the contents of content[start_block_index:end_block_index] joined together. The text block is the minimal citable unit; this field is never a substring of a single block. Not counted toward output tokens, and not counted toward input tokens when sent back in subsequent turns.
Always greater than start_block_index; a single-block citation has end_block_index = start_block_index + 1.
Counted separately from document_index; server-side web search results are not included in this count.
When content is None, it indicates the compaction failed to produce a valid summary (e.g., malformed output from the model). Clients may round-trip compaction blocks with null content; the server treats them as no-ops.
One block appears per hop where a preceding model actually ran this turn and
declined. A turn where no preceding model ran and declined has no such
boundary and carries no block — the signal for whether a fallback model
served the response is the presence of a fallback_message entry in
usage.iterations, not this block.
The block is treated like a server-tool content block for streaming: it
arrives via the standard content_block_start / content_block_stop
pair and carries no deltas.
The model whose output ends at this point — the model that declined at this hop. When the declining hop is the requested model, its model echoes the top-level model string the caller sent (alias or canonical); when the declining hop is a fallback model, its model is that model's canonical id.
The model whose output ends at this point — the model that declined at this hop. When the declining hop is the requested model, its model echoes the top-level model string the caller sent (alias or canonical); when the declining hop is a fallback model, its model is that model's canonical id.
The request could enable cyber harm, such as malware or exploit development. Benign cybersecurity work can also trigger this category.
The request could enable biological harm, such as dangerous lab methods. Beneficial life sciences work can also trigger this category.
The request could assist the development of competing AI models, which is restricted under Anthropic's commercial terms. Benign machine learning work can also trigger this category.
The request asks the model to reproduce its internal reasoning in the response text. To get reasoning in a structured form instead, use adaptive thinking.
Information about context management strategies applied during the request.
applied_edits: array of BetaClearToolUses20250919EditResponse { cleared_input_tokens, cleared_tool_uses, type } or BetaClearThinking20251015EditResponse { cleared_input_tokens, cleared_thinking_turns, type }List of context management edits that were applied.
List of context management edits that were applied.
cache_miss_reason: BetaCacheMissModelChanged { cache_missed_input_tokens, type } or BetaCacheMissSystemChanged { cache_missed_input_tokens, type } or BetaCacheMissToolsChanged { cache_missed_input_tokens, type } or 3 moreExplains why the prompt cache could not fully reuse the prefix from the request identified by diagnostics.previous_message_id. null means diagnosis is still pending — the response was serialized before the background comparison completed.
Explains why the prompt cache could not fully reuse the prefix from the request identified by diagnostics.previous_message_id. null means diagnosis is still pending — the response was serialized before the background comparison completed.
The request could enable cyber harm, such as malware or exploit development. Benign cybersecurity work can also trigger this category.
The request could enable biological harm, such as dangerous lab methods. Beneficial life sciences work can also trigger this category.
The request could assist the development of competing AI models, which is restricted under Anthropic's commercial terms. Benign machine learning work can also trigger this category.
The request asks the model to reproduce its internal reasoning in the response text. To get reasoning in a structured form instead, use adaptive thinking.
The retry is sent either with the same request body (system, messages,
tools, and other render-shaping fields), or with the same body plus one
appended assistant message whose content is the partial text (with any
trailing whitespace stripped from the final text block) and paired
server-tool blocks from this refusal — which also authorizes that
appended turn as an assistant-prefill continuation on models that otherwise
disallow prefill. A token minted mid-server-tool-loop whose partial content
was continuable may only be redeemed the second way — if a same-body retry
is rejected with a 400 saying the token must be redeemed by continuing the
partial response, retry the second way instead. Either way: same workspace,
same platform; a mismatch is a 400. Resending a token for an already-warm
prefix is permitted but yields no additional credit.
null when the refused model isn't eligible for a fallback credit.
true: retry by resending the same request body plus one appended
assistant message whose content is this response's content with any
trailing whitespace stripped from the final text block and unpaired
tool_use blocks omitted (the same appended-turn shape described on
fallback_credit_token), with the token attached. false: retry by
resending the original request body unchanged, with the token attached —
the appended-assistant form is not available for this refusal (no
continuable partial content, or the request uses output_format or a
tool_choice that forces tool use). One exception: when the request used
output_format or a forced tool_choice and the refusal arrived after
server tools (including MCP connector tools) had already executed, the
token may not be redeemable by either retry form; if the exact-body retry
is then rejected with a 400 saying the token must be redeemed by
continuing the partial response, discard the token and retry without it.
Advisory: if an appended-assistant retry is rejected with a 400 despite
true, fall back to resending the original request body with the token.
This may be one the following values:
"end_turn": the model reached a natural stopping point"max_tokens": we exceeded the requestedmax_tokensor the model's maximum"stop_sequence": one of your provided customstop_sequenceswas generated"tool_use": the model invoked one or more tools"pause_turn": we paused a long-running turn. You may provide the response back as-is in a subsequent request to let the model continue."refusal": when streaming classifiers intervene to handle potential policy violations"model_context_window_exceeded": we exceeded the model's context window
In non-streaming mode this value is always non-null. In streaming mode, it is null in the message_start event and non-null otherwise.
Anthropic's API bills and rate-limits by token counts, as tokens represent the underlying cost to our systems.
Under the hood, the API transforms requests into a format suitable for the model. The model's output then goes through a parsing stage before becoming an API response. As a result, the token counts in usage will not match one-to-one with the exact visible content of an API request or response.
For example, output_tokens will be non-zero, even for an empty string response from Claude.
Total input tokens in a request is the summation of input_tokens, cache_creation_input_tokens, and cache_read_input_tokens.
status: BetaFallbackCreditRedeemed { type } or BetaFallbackCreditNotApplied { reason, type, remove_to_redeem }Whether the fallback-credit reprice was applied to this response's billing.
Whether the fallback-credit reprice was applied to this response's billing.
A union discriminated on type. redeemed: the retry is billed as if
the conversation had been on the retry model all along — including when the
resulting shift is zero because there was nothing to move. not_applied:
no reprice was applied; the arm's reason says why.
A closed enum; additions to the redemption-check vocabulary arrive as deliberate schema updates.
Present exactly when reason is variant_fields_present — never null,
never an empty array; absent otherwise. Fields are named only from your own request, and only after
the sealed variant hash matched. A served best-effort retry has already
been billed at normal price; nothing redeems retroactively, but a corrected
re-send inside the token's five-minute window can still redeem.
iterations: array of BetaMessageIterationUsage { cache_creation, cache_creation_input_tokens, cache_read_input_tokens, 4 more } or BetaCompactionIterationUsage { cache_creation, cache_creation_input_tokens, cache_read_input_tokens, 3 more } or BetaAdvisorMessageIterationUsage { cache_creation, cache_creation_input_tokens, cache_read_input_tokens, 4 more } or BetaFallbackMessageIterationUsage { cache_creation, cache_creation_input_tokens, cache_read_input_tokens, 4 more }Per-iteration token usage breakdown.
Per-iteration token usage breakdown.
Each entry represents one sampling iteration, with its own input/output token counts and cache statistics, discriminated by type. For message entries (model sampling iterations, such as the turns of a server-side tool use loop), this allows you to:
- Determine which iterations exceeded long context thresholds (>=200k tokens)
- Calculate the context window size from the last
messageentry - Understand token accumulation across server-side tool use loops
A compaction entry reports the token usage of the compaction operation itself — the server-side request that summarizes the context being closed — NOT the size of the context that was compacted away, and its token counts can be much smaller than that closed context (for example, a compaction that closes a ~200k-token context can report only a few thousand tokens). Do not derive the context window size from a compaction entry, even when it is the last entry. A compaction entry's tokens are not included in the top-level usage fields. When an input-token trigger is in effect (the default — 150,000 tokens unless configured otherwise), each compaction entry closes a context that had reached at least that threshold, though the context can exceed it by the final iteration's output and tool results.
output_tokens remains the inclusive, authoritative total used for billing.
This object provides a read-only decomposition for observability — for example,
how many of the billed output tokens were spent on internal reasoning that may
have been summarized before being returned to you.
Reflects the raw reasoning the model produced, not the (possibly shorter)
summarized thinking text returned in the response body. Computed by
re-tokenizing the raw reasoning text, so it may differ from the model's exact
generation count by a small number of tokens. Always ≤ output_tokens;
output_tokens - thinking_tokens approximates the non-reasoning output.
error: BetaInvalidRequestError { message, type } or BetaAuthenticationError { message, type } or BetaBillingError { message, type } or 6 more
Retrieve Message Batch results
ant beta:messages:batches results \
--api-key my-anthropic-api-key \
--message-batch-id message_batch_id