Class BetaContentBlockParam
-
- All Implemented Interfaces:
public final class BetaContentBlockParam
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceBetaContentBlockParam.VisitorAn interface that defines how to map each variant of BetaContentBlockParam to a value of type T.
public final classBetaContentBlockParam.Type
-
Method Summary
Modifier and Type Method Description final Optional<BetaTextBlockParam>text()Regular text content. final Optional<BetaImageBlockParam>image()Image content specified directly as base64 data or as a reference via a URL. final Optional<BetaRequestDocumentBlock>document()Document content, either specified directly as base64 data, as text, or as a reference via a URL. final Optional<BetaSearchResultBlockParam>searchResult()A search result block containing source, title, and content from search operations. final Optional<BetaThinkingBlockParam>thinking()A block specifying internal thinking by the model. final Optional<BetaRedactedThinkingBlockParam>redactedThinking()A block specifying internal, redacted thinking by the model. final Optional<BetaToolUseBlockParam>toolUse()A block indicating a tool use by the model. final Optional<BetaToolResultBlockParam>toolResult()A block specifying the results of a tool use by the model. final Optional<BetaServerToolUseBlockParam>serverToolUse()final Optional<BetaWebSearchToolResultBlockParam>webSearchToolResult()final Optional<BetaWebFetchToolResultBlockParam>webFetchToolResult()final Optional<BetaAdvisorToolResultBlockParam>advisorToolResult()final Optional<BetaCodeExecutionToolResultBlockParam>codeExecutionToolResult()final Optional<BetaBashCodeExecutionToolResultBlockParam>bashCodeExecutionToolResult()final Optional<BetaTextEditorCodeExecutionToolResultBlockParam>textEditorCodeExecutionToolResult()final Optional<BetaToolSearchToolResultBlockParam>toolSearchToolResult()final Optional<BetaMcpToolUseBlockParam>mcpToolUse()final Optional<BetaRequestMcpToolResultBlockParam>mcpToolResult()final Optional<BetaContainerUploadBlockParam>containerUpload()A content block that represents a file to be uploaded to the container Files uploaded via this block will be available in the container's input directory. final Optional<BetaCompactionBlockParam>compaction()A compaction block containing summary of previous context. final Optional<BetaRequestToolAdditionBlock>toolAddition()Mid-conversation directive to make a tool available. final Optional<BetaRequestToolRemovalBlock>toolRemoval()Mid-conversation directive to withdraw a tool. final Optional<BetaMcpToolListingBlockParam>mcpToolListing()The tool listing an MCP server returned while an earlier response was produced, as that response carried it. final Optional<BetaFallbackBlockParam>fallback()A fallbackblock echoed back from a prior response.final Optional<JsonValue>_json()final BetaContentBlockParam.Typetype()final Optional<BetaCacheControlEphemeral>cacheControl()final Optional<String>title()final Optional<String>signature()final Optional<String>id()final Optional<String>toolsetName()final Optional<String>toolUseId()final Optional<Boolean>isError()final BooleanisText()final BooleanisImage()final BooleanisDocument()final BooleanisSearchResult()final BooleanisThinking()final BooleanisRedactedThinking()final BooleanisToolUse()final BooleanisToolResult()final BooleanisServerToolUse()final BooleanisWebSearchToolResult()final BooleanisWebFetchToolResult()final BooleanisAdvisorToolResult()final BooleanisCodeExecutionToolResult()final BooleanisBashCodeExecutionToolResult()final BooleanisTextEditorCodeExecutionToolResult()final BooleanisToolSearchToolResult()final BooleanisMcpToolUse()final BooleanisMcpToolResult()final BooleanisContainerUpload()final BooleanisCompaction()final BooleanisToolAddition()final BooleanisToolRemoval()final BooleanisMcpToolListing()final BooleanisFallback()final BetaTextBlockParamasText()Regular text content. final BetaImageBlockParamasImage()Image content specified directly as base64 data or as a reference via a URL. final BetaRequestDocumentBlockasDocument()Document content, either specified directly as base64 data, as text, or as a reference via a URL. final BetaSearchResultBlockParamasSearchResult()A search result block containing source, title, and content from search operations. final BetaThinkingBlockParamasThinking()A block specifying internal thinking by the model. final BetaRedactedThinkingBlockParamasRedactedThinking()A block specifying internal, redacted thinking by the model. final BetaToolUseBlockParamasToolUse()A block indicating a tool use by the model. final BetaToolResultBlockParamasToolResult()A block specifying the results of a tool use by the model. final BetaServerToolUseBlockParamasServerToolUse()final BetaWebSearchToolResultBlockParamasWebSearchToolResult()final BetaWebFetchToolResultBlockParamasWebFetchToolResult()final BetaAdvisorToolResultBlockParamasAdvisorToolResult()final BetaCodeExecutionToolResultBlockParamasCodeExecutionToolResult()final BetaBashCodeExecutionToolResultBlockParamasBashCodeExecutionToolResult()final BetaTextEditorCodeExecutionToolResultBlockParamasTextEditorCodeExecutionToolResult()final BetaToolSearchToolResultBlockParamasToolSearchToolResult()final BetaMcpToolUseBlockParamasMcpToolUse()final BetaRequestMcpToolResultBlockParamasMcpToolResult()final BetaContainerUploadBlockParamasContainerUpload()A content block that represents a file to be uploaded to the container Files uploaded via this block will be available in the container's input directory. final BetaCompactionBlockParamasCompaction()A compaction block containing summary of previous context. final BetaRequestToolAdditionBlockasToolAddition()Mid-conversation directive to make a tool available. final BetaRequestToolRemovalBlockasToolRemoval()Mid-conversation directive to withdraw a tool. final BetaMcpToolListingBlockParamasMcpToolListing()The tool listing an MCP server returned while an earlier response was produced, as that response carried it. final BetaFallbackBlockParamasFallback()A fallbackblock echoed back from a prior response.final <T extends Any> Taccept(BetaContentBlockParam.Visitor<T> visitor)Maps this instance's current variant to a value of type T using the given visitor. final BetaContentBlockParamvalidate()Validates that the types of all values in this object match their expected types recursively. final BooleanisValid()Booleanequals(Object other)IntegerhashCode()StringtoString()final static BetaContentBlockParamofText(BetaTextBlockParam text)Regular text content. final static BetaContentBlockParamofText(String text)Returns an immutable instance of BetaContentBlockParam whose ofText variant is built from the given required text. final static BetaContentBlockParamofImage(BetaImageBlockParam image)Image content specified directly as base64 data or as a reference via a URL. final static BetaContentBlockParamofImage(BetaImageBlockParam.Source source)Returns an immutable instance of BetaContentBlockParam whose ofImage variant is built from the given required source. final static BetaContentBlockParamofImage(BetaBase64ImageSource base64)Alias for calling ofImage with BetaImageBlockParam.Source.ofBase64(base64).final static BetaContentBlockParamofImage(BetaUrlImageSource url)Alias for calling ofImage with BetaImageBlockParam.Source.ofUrl(url).final static BetaContentBlockParamofImage(BetaFileImageSource file)Alias for calling ofImage with BetaImageBlockParam.Source.ofFile(file).final static BetaContentBlockParamofDocument(BetaRequestDocumentBlock document)Document content, either specified directly as base64 data, as text, or as a reference via a URL. final static BetaContentBlockParamofDocument(BetaRequestDocumentBlock.Source source)Returns an immutable instance of BetaContentBlockParam whose ofDocument variant is built from the given required source. final static BetaContentBlockParamofDocument(BetaBase64PdfSource base64)Alias for calling ofDocument with BetaRequestDocumentBlock.Source.ofBase64(base64).final static BetaContentBlockParamofDocument(BetaPlainTextSource text)Alias for calling ofDocument with BetaRequestDocumentBlock.Source.ofText(text).final static BetaContentBlockParamofDocument(BetaContentBlockSource content)Alias for calling ofDocument with BetaRequestDocumentBlock.Source.ofContent(content).final static BetaContentBlockParamofDocument(BetaUrlPdfSource url)Alias for calling ofDocument with BetaRequestDocumentBlock.Source.ofUrl(url).final static BetaContentBlockParamofDocument(BetaFileDocumentSource file)Alias for calling ofDocument with BetaRequestDocumentBlock.Source.ofFile(file).final static BetaContentBlockParamofSearchResult(BetaSearchResultBlockParam searchResult)A search result block containing source, title, and content from search operations. final static BetaContentBlockParamofThinking(BetaThinkingBlockParam thinking)A block specifying internal thinking by the model. final static BetaContentBlockParamofRedactedThinking(BetaRedactedThinkingBlockParam redactedThinking)A block specifying internal, redacted thinking by the model. final static BetaContentBlockParamofRedactedThinking(String data)Returns an immutable instance of BetaContentBlockParam whose ofRedactedThinking variant is built from the given required data. final static BetaContentBlockParamofToolUse(BetaToolUseBlockParam toolUse)A block indicating a tool use by the model. final static BetaContentBlockParamofToolResult(BetaToolResultBlockParam toolResult)A block specifying the results of a tool use by the model. final static BetaContentBlockParamofToolResult(String toolUseId)Returns an immutable instance of BetaContentBlockParam whose ofToolResult variant is built from the given required toolUseId. final static BetaContentBlockParamofServerToolUse(BetaServerToolUseBlockParam serverToolUse)final static BetaContentBlockParamofWebSearchToolResult(BetaWebSearchToolResultBlockParam webSearchToolResult)final static BetaContentBlockParamofWebFetchToolResult(BetaWebFetchToolResultBlockParam webFetchToolResult)final static BetaContentBlockParamofAdvisorToolResult(BetaAdvisorToolResultBlockParam advisorToolResult)final static BetaContentBlockParamofCodeExecutionToolResult(BetaCodeExecutionToolResultBlockParam codeExecutionToolResult)final static BetaContentBlockParamofBashCodeExecutionToolResult(BetaBashCodeExecutionToolResultBlockParam bashCodeExecutionToolResult)final static BetaContentBlockParamofTextEditorCodeExecutionToolResult(BetaTextEditorCodeExecutionToolResultBlockParam textEditorCodeExecutionToolResult)final static BetaContentBlockParamofToolSearchToolResult(BetaToolSearchToolResultBlockParam toolSearchToolResult)final static BetaContentBlockParamofMcpToolUse(BetaMcpToolUseBlockParam mcpToolUse)final static BetaContentBlockParamofMcpToolResult(BetaRequestMcpToolResultBlockParam mcpToolResult)final static BetaContentBlockParamofMcpToolResult(String toolUseId)Returns an immutable instance of BetaContentBlockParam whose ofMcpToolResult variant is built from the given required toolUseId. final static BetaContentBlockParamofContainerUpload(BetaContainerUploadBlockParam containerUpload)A content block that represents a file to be uploaded to the container Files uploaded via this block will be available in the container's input directory. final static BetaContentBlockParamofContainerUpload(String fileId)Returns an immutable instance of BetaContentBlockParam whose ofContainerUpload variant is built from the given required fileId. final static BetaContentBlockParamofCompaction(BetaCompactionBlockParam compaction)A compaction block containing summary of previous context. final static BetaContentBlockParamofToolAddition(BetaRequestToolAdditionBlock toolAddition)Mid-conversation directive to make a tool available. final static BetaContentBlockParamofToolAddition(BetaRequestToolAdditionBlock.Tool tool)Returns an immutable instance of BetaContentBlockParam whose ofToolAddition variant is built from the given required tool. final static BetaContentBlockParamofToolAddition(BetaToolChangeToolReference reference)Alias for calling ofToolAddition with BetaRequestToolAdditionBlock.Tool.ofReference(reference).final static BetaContentBlockParamofToolAddition(BetaResponseToolChangeToolReference reference)Alias for calling ofToolAddition with reference.toParam().final static BetaContentBlockParamofToolAddition(BetaToolChangeMcpToolReference mcpToolReference)Alias for calling ofToolAddition with BetaRequestToolAdditionBlock.Tool.ofMcpToolReference(mcpToolReference).final static BetaContentBlockParamofToolAddition(BetaResponseToolChangeMcpToolReference mcpToolReference)Alias for calling ofToolAddition with mcpToolReference.toParam().final static BetaContentBlockParamofToolAddition(BetaToolChangeMcpToolsetReference mcpToolsetReference)Alias for calling ofToolAddition with BetaRequestToolAdditionBlock.Tool.ofMcpToolsetReference(mcpToolsetReference).final static BetaContentBlockParamofToolAddition(BetaResponseToolChangeMcpToolsetReference mcpToolsetReference)Alias for calling ofToolAddition with mcpToolsetReference.toParam().final static BetaContentBlockParamofToolAddition(BetaToolChangeToolDefinitionParam definition)Alias for calling ofToolAddition with BetaRequestToolAdditionBlock.Tool.ofDefinition(definition).final static BetaContentBlockParamofToolAddition(BetaToolChangeToolDefinition definition)Alias for calling ofToolAddition with definition.toParam().final static BetaContentBlockParamofToolRemoval(BetaRequestToolRemovalBlock toolRemoval)Mid-conversation directive to withdraw a tool. final static BetaContentBlockParamofToolRemoval(BetaRequestToolRemovalBlock.Tool tool)Returns an immutable instance of BetaContentBlockParam whose ofToolRemoval variant is built from the given required tool. final static BetaContentBlockParamofToolRemoval(BetaToolChangeToolReference reference)Alias for calling ofToolRemoval with BetaRequestToolRemovalBlock.Tool.ofReference(reference).final static BetaContentBlockParamofToolRemoval(BetaResponseToolChangeToolReference reference)Alias for calling ofToolRemoval with reference.toParam().final static BetaContentBlockParamofToolRemoval(BetaToolChangeMcpToolReference mcpToolReference)Alias for calling ofToolRemoval with BetaRequestToolRemovalBlock.Tool.ofMcpToolReference(mcpToolReference).final static BetaContentBlockParamofToolRemoval(BetaResponseToolChangeMcpToolReference mcpToolReference)Alias for calling ofToolRemoval with mcpToolReference.toParam().final static BetaContentBlockParamofToolRemoval(BetaToolChangeMcpToolsetReference mcpToolsetReference)Alias for calling ofToolRemoval with BetaRequestToolRemovalBlock.Tool.ofMcpToolsetReference(mcpToolsetReference).final static BetaContentBlockParamofToolRemoval(BetaResponseToolChangeMcpToolsetReference mcpToolsetReference)Alias for calling ofToolRemoval with mcpToolsetReference.toParam().final static BetaContentBlockParamofMcpToolListing(BetaMcpToolListingBlockParam mcpToolListing)The tool listing an MCP server returned while an earlier response was produced, as that response carried it. final static BetaContentBlockParamofFallback(BetaFallbackBlockParam fallback)A fallbackblock echoed back from a prior response.-
-
Method Detail
-
text
final Optional<BetaTextBlockParam> text()
Regular text content.
-
image
final Optional<BetaImageBlockParam> image()
Image content specified directly as base64 data or as a reference via a URL.
-
document
final Optional<BetaRequestDocumentBlock> document()
Document content, either specified directly as base64 data, as text, or as a reference via a URL.
-
searchResult
final Optional<BetaSearchResultBlockParam> searchResult()
A search result block containing source, title, and content from search operations.
-
thinking
final Optional<BetaThinkingBlockParam> thinking()
A block specifying internal thinking by the model.
-
redactedThinking
final Optional<BetaRedactedThinkingBlockParam> redactedThinking()
A block specifying internal, redacted thinking by the model.
-
toolUse
final Optional<BetaToolUseBlockParam> toolUse()
A block indicating a tool use by the model.
-
toolResult
final Optional<BetaToolResultBlockParam> toolResult()
A block specifying the results of a tool use by the model.
-
serverToolUse
final Optional<BetaServerToolUseBlockParam> serverToolUse()
-
webSearchToolResult
final Optional<BetaWebSearchToolResultBlockParam> webSearchToolResult()
-
webFetchToolResult
final Optional<BetaWebFetchToolResultBlockParam> webFetchToolResult()
-
advisorToolResult
final Optional<BetaAdvisorToolResultBlockParam> advisorToolResult()
-
codeExecutionToolResult
final Optional<BetaCodeExecutionToolResultBlockParam> codeExecutionToolResult()
-
bashCodeExecutionToolResult
final Optional<BetaBashCodeExecutionToolResultBlockParam> bashCodeExecutionToolResult()
-
textEditorCodeExecutionToolResult
final Optional<BetaTextEditorCodeExecutionToolResultBlockParam> textEditorCodeExecutionToolResult()
-
toolSearchToolResult
final Optional<BetaToolSearchToolResultBlockParam> toolSearchToolResult()
-
mcpToolUse
final Optional<BetaMcpToolUseBlockParam> mcpToolUse()
-
mcpToolResult
final Optional<BetaRequestMcpToolResultBlockParam> mcpToolResult()
-
containerUpload
final Optional<BetaContainerUploadBlockParam> containerUpload()
A content block that represents a file to be uploaded to the container Files uploaded via this block will be available in the container's input directory.
-
compaction
final Optional<BetaCompactionBlockParam> compaction()
A compaction block containing summary of previous context.
Users should round-trip these blocks from responses to subsequent requests to maintain context across compaction boundaries.
When content is None, the block represents a failed compaction. The server treats these as no-ops. Empty string content is not allowed.
-
toolAddition
final Optional<BetaRequestToolAdditionBlock> toolAddition()
Mid-conversation directive to make a tool available.
`tool`is a reference to a tool (or MCP toolset) declared in the request's`tools`. Under the`inline-tools-2026-09-15`beta it may instead be a reference to a tool defined earlier in`messages`, or a`tool_definition`object that carries an inline tool definition in`definition`(the same object a`tools`entry holds). An`mcp_toolset`definition also requires the`mcp-client-2026-09-15`beta. The tool is offered to the model from this point in the conversation onward.
-
toolRemoval
final Optional<BetaRequestToolRemovalBlock> toolRemoval()
Mid-conversation directive to withdraw a tool.
`tool`references a tool (or MCP toolset) by name: one declared in the request's`tools`or defined earlier in`messages`. It is no longer offered to the model from this point in the conversation onward.
-
mcpToolListing
final Optional<BetaMcpToolListingBlockParam> mcpToolListing()
The tool listing an MCP server returned while an earlier response was produced, as that response carried it. Send the assistant message back unchanged, this block included, and the server uses this listing for the matching
mcp_toolsetinstead of asking the MCP server again.
-
fallback
final Optional<BetaFallbackBlockParam> fallback()
A
fallbackblock echoed back from a prior response.Accepted in
messages[].contentand not rendered into the prompt; not validated against the request'sfallbackschain or top-levelmodel.When you send the assistant turn back, keep this block in its original position. The block marks the boundary between content produced before and after a fallback hop, and the server relies on that boundary to validate the turn: when thinking runs flank the boundary, omitting the block merges them into one span the server cannot validate (the request is rejected), and moving it into the middle of a single run is likewise rejected; between non-thinking blocks the block's placement has no effect on thinking validation.
Some blocks from before the turn's final
fallbackblock must be left out when you send the turn back, and notool_resultis sent for atool_useblock you left out.See the refusals and fallback guide to learn which blocks to keep.
-
type
final BetaContentBlockParam.Type type()
-
cacheControl
final Optional<BetaCacheControlEphemeral> cacheControl()
-
toolsetName
final Optional<String> toolsetName()
-
isDocument
final Boolean isDocument()
-
isSearchResult
final Boolean isSearchResult()
-
isThinking
final Boolean isThinking()
-
isRedactedThinking
final Boolean isRedactedThinking()
-
isToolResult
final Boolean isToolResult()
-
isServerToolUse
final Boolean isServerToolUse()
-
isWebSearchToolResult
final Boolean isWebSearchToolResult()
-
isWebFetchToolResult
final Boolean isWebFetchToolResult()
-
isAdvisorToolResult
final Boolean isAdvisorToolResult()
-
isCodeExecutionToolResult
final Boolean isCodeExecutionToolResult()
-
isBashCodeExecutionToolResult
final Boolean isBashCodeExecutionToolResult()
-
isTextEditorCodeExecutionToolResult
final Boolean isTextEditorCodeExecutionToolResult()
-
isToolSearchToolResult
final Boolean isToolSearchToolResult()
-
isMcpToolUse
final Boolean isMcpToolUse()
-
isMcpToolResult
final Boolean isMcpToolResult()
-
isContainerUpload
final Boolean isContainerUpload()
-
isCompaction
final Boolean isCompaction()
-
isToolAddition
final Boolean isToolAddition()
-
isToolRemoval
final Boolean isToolRemoval()
-
isMcpToolListing
final Boolean isMcpToolListing()
-
isFallback
final Boolean isFallback()
-
asText
final BetaTextBlockParam asText()
Regular text content.
-
asImage
final BetaImageBlockParam asImage()
Image content specified directly as base64 data or as a reference via a URL.
-
asDocument
final BetaRequestDocumentBlock asDocument()
Document content, either specified directly as base64 data, as text, or as a reference via a URL.
-
asSearchResult
final BetaSearchResultBlockParam asSearchResult()
A search result block containing source, title, and content from search operations.
-
asThinking
final BetaThinkingBlockParam asThinking()
A block specifying internal thinking by the model.
-
asRedactedThinking
final BetaRedactedThinkingBlockParam asRedactedThinking()
A block specifying internal, redacted thinking by the model.
-
asToolUse
final BetaToolUseBlockParam asToolUse()
A block indicating a tool use by the model.
-
asToolResult
final BetaToolResultBlockParam asToolResult()
A block specifying the results of a tool use by the model.
-
asServerToolUse
final BetaServerToolUseBlockParam asServerToolUse()
-
asWebSearchToolResult
final BetaWebSearchToolResultBlockParam asWebSearchToolResult()
-
asWebFetchToolResult
final BetaWebFetchToolResultBlockParam asWebFetchToolResult()
-
asAdvisorToolResult
final BetaAdvisorToolResultBlockParam asAdvisorToolResult()
-
asCodeExecutionToolResult
final BetaCodeExecutionToolResultBlockParam asCodeExecutionToolResult()
-
asBashCodeExecutionToolResult
final BetaBashCodeExecutionToolResultBlockParam asBashCodeExecutionToolResult()
-
asTextEditorCodeExecutionToolResult
final BetaTextEditorCodeExecutionToolResultBlockParam asTextEditorCodeExecutionToolResult()
-
asToolSearchToolResult
final BetaToolSearchToolResultBlockParam asToolSearchToolResult()
-
asMcpToolUse
final BetaMcpToolUseBlockParam asMcpToolUse()
-
asMcpToolResult
final BetaRequestMcpToolResultBlockParam asMcpToolResult()
-
asContainerUpload
final BetaContainerUploadBlockParam asContainerUpload()
A content block that represents a file to be uploaded to the container Files uploaded via this block will be available in the container's input directory.
-
asCompaction
final BetaCompactionBlockParam asCompaction()
A compaction block containing summary of previous context.
Users should round-trip these blocks from responses to subsequent requests to maintain context across compaction boundaries.
When content is None, the block represents a failed compaction. The server treats these as no-ops. Empty string content is not allowed.
-
asToolAddition
final BetaRequestToolAdditionBlock asToolAddition()
Mid-conversation directive to make a tool available.
`tool`is a reference to a tool (or MCP toolset) declared in the request's`tools`. Under the`inline-tools-2026-09-15`beta it may instead be a reference to a tool defined earlier in`messages`, or a`tool_definition`object that carries an inline tool definition in`definition`(the same object a`tools`entry holds). An`mcp_toolset`definition also requires the`mcp-client-2026-09-15`beta. The tool is offered to the model from this point in the conversation onward.
-
asToolRemoval
final BetaRequestToolRemovalBlock asToolRemoval()
Mid-conversation directive to withdraw a tool.
`tool`references a tool (or MCP toolset) by name: one declared in the request's`tools`or defined earlier in`messages`. It is no longer offered to the model from this point in the conversation onward.
-
asMcpToolListing
final BetaMcpToolListingBlockParam asMcpToolListing()
The tool listing an MCP server returned while an earlier response was produced, as that response carried it. Send the assistant message back unchanged, this block included, and the server uses this listing for the matching
mcp_toolsetinstead of asking the MCP server again.
-
asFallback
final BetaFallbackBlockParam asFallback()
A
fallbackblock echoed back from a prior response.Accepted in
messages[].contentand not rendered into the prompt; not validated against the request'sfallbackschain or top-levelmodel.When you send the assistant turn back, keep this block in its original position. The block marks the boundary between content produced before and after a fallback hop, and the server relies on that boundary to validate the turn: when thinking runs flank the boundary, omitting the block merges them into one span the server cannot validate (the request is rejected), and moving it into the middle of a single run is likewise rejected; between non-thinking blocks the block's placement has no effect on thinking validation.
Some blocks from before the turn's final
fallbackblock must be left out when you send the turn back, and notool_resultis sent for atool_useblock you left out.See the refusals and fallback guide to learn which blocks to keep.
-
accept
final <T extends Any> T accept(BetaContentBlockParam.Visitor<T> visitor)
Maps this instance's current variant to a value of type T using the given visitor.
Note that this method is not forwards compatible with new variants from the API, unless visitor overrides Visitor.unknown. To handle variants not known to this version of the SDK gracefully, consider overriding Visitor.unknown:
import com.anthropic.core.JsonValue; import java.util.Optional; Optional<String> result = betaContentBlockParam.accept(new BetaContentBlockParam.Visitor<Optional<String>>() { @Override public Optional<String> visitText(BetaTextBlockParam text) { return Optional.of(text.toString()); } // ... @Override public Optional<String> unknown(JsonValue json) { // Or inspect the `json`. return Optional.empty(); } });
-
validate
final BetaContentBlockParam validate()
Validates that the types of all values in this object match their expected types recursively.
This method is not forwards compatible with new types from the API for existing fields.
-
ofText
final static BetaContentBlockParam ofText(BetaTextBlockParam text)
Regular text content.
-
ofText
final static BetaContentBlockParam ofText(String text)
Returns an immutable instance of BetaContentBlockParam whose ofText variant is built from the given required text.
-
ofImage
final static BetaContentBlockParam ofImage(BetaImageBlockParam image)
Image content specified directly as base64 data or as a reference via a URL.
-
ofImage
final static BetaContentBlockParam ofImage(BetaImageBlockParam.Source source)
Returns an immutable instance of BetaContentBlockParam whose ofImage variant is built from the given required source.
-
ofImage
final static BetaContentBlockParam ofImage(BetaBase64ImageSource base64)
Alias for calling ofImage with
BetaImageBlockParam.Source.ofBase64(base64).
-
ofImage
final static BetaContentBlockParam ofImage(BetaUrlImageSource url)
Alias for calling ofImage with
BetaImageBlockParam.Source.ofUrl(url).
-
ofImage
final static BetaContentBlockParam ofImage(BetaFileImageSource file)
Alias for calling ofImage with
BetaImageBlockParam.Source.ofFile(file).
-
ofDocument
final static BetaContentBlockParam ofDocument(BetaRequestDocumentBlock document)
Document content, either specified directly as base64 data, as text, or as a reference via a URL.
-
ofDocument
final static BetaContentBlockParam ofDocument(BetaRequestDocumentBlock.Source source)
Returns an immutable instance of BetaContentBlockParam whose ofDocument variant is built from the given required source.
-
ofDocument
final static BetaContentBlockParam ofDocument(BetaBase64PdfSource base64)
Alias for calling ofDocument with
BetaRequestDocumentBlock.Source.ofBase64(base64).
-
ofDocument
final static BetaContentBlockParam ofDocument(BetaPlainTextSource text)
Alias for calling ofDocument with
BetaRequestDocumentBlock.Source.ofText(text).
-
ofDocument
final static BetaContentBlockParam ofDocument(BetaContentBlockSource content)
Alias for calling ofDocument with
BetaRequestDocumentBlock.Source.ofContent(content).
-
ofDocument
final static BetaContentBlockParam ofDocument(BetaUrlPdfSource url)
Alias for calling ofDocument with
BetaRequestDocumentBlock.Source.ofUrl(url).
-
ofDocument
final static BetaContentBlockParam ofDocument(BetaFileDocumentSource file)
Alias for calling ofDocument with
BetaRequestDocumentBlock.Source.ofFile(file).
-
ofSearchResult
final static BetaContentBlockParam ofSearchResult(BetaSearchResultBlockParam searchResult)
A search result block containing source, title, and content from search operations.
-
ofThinking
final static BetaContentBlockParam ofThinking(BetaThinkingBlockParam thinking)
A block specifying internal thinking by the model.
-
ofRedactedThinking
final static BetaContentBlockParam ofRedactedThinking(BetaRedactedThinkingBlockParam redactedThinking)
A block specifying internal, redacted thinking by the model.
-
ofRedactedThinking
final static BetaContentBlockParam ofRedactedThinking(String data)
Returns an immutable instance of BetaContentBlockParam whose ofRedactedThinking variant is built from the given required data.
-
ofToolUse
final static BetaContentBlockParam ofToolUse(BetaToolUseBlockParam toolUse)
A block indicating a tool use by the model.
-
ofToolResult
final static BetaContentBlockParam ofToolResult(BetaToolResultBlockParam toolResult)
A block specifying the results of a tool use by the model.
-
ofToolResult
final static BetaContentBlockParam ofToolResult(String toolUseId)
Returns an immutable instance of BetaContentBlockParam whose ofToolResult variant is built from the given required toolUseId.
-
ofServerToolUse
final static BetaContentBlockParam ofServerToolUse(BetaServerToolUseBlockParam serverToolUse)
-
ofWebSearchToolResult
final static BetaContentBlockParam ofWebSearchToolResult(BetaWebSearchToolResultBlockParam webSearchToolResult)
-
ofWebFetchToolResult
final static BetaContentBlockParam ofWebFetchToolResult(BetaWebFetchToolResultBlockParam webFetchToolResult)
-
ofAdvisorToolResult
final static BetaContentBlockParam ofAdvisorToolResult(BetaAdvisorToolResultBlockParam advisorToolResult)
-
ofCodeExecutionToolResult
final static BetaContentBlockParam ofCodeExecutionToolResult(BetaCodeExecutionToolResultBlockParam codeExecutionToolResult)
-
ofBashCodeExecutionToolResult
final static BetaContentBlockParam ofBashCodeExecutionToolResult(BetaBashCodeExecutionToolResultBlockParam bashCodeExecutionToolResult)
-
ofTextEditorCodeExecutionToolResult
final static BetaContentBlockParam ofTextEditorCodeExecutionToolResult(BetaTextEditorCodeExecutionToolResultBlockParam textEditorCodeExecutionToolResult)
-
ofToolSearchToolResult
final static BetaContentBlockParam ofToolSearchToolResult(BetaToolSearchToolResultBlockParam toolSearchToolResult)
-
ofMcpToolUse
final static BetaContentBlockParam ofMcpToolUse(BetaMcpToolUseBlockParam mcpToolUse)
-
ofMcpToolResult
final static BetaContentBlockParam ofMcpToolResult(BetaRequestMcpToolResultBlockParam mcpToolResult)
-
ofMcpToolResult
final static BetaContentBlockParam ofMcpToolResult(String toolUseId)
Returns an immutable instance of BetaContentBlockParam whose ofMcpToolResult variant is built from the given required toolUseId.
-
ofContainerUpload
final static BetaContentBlockParam ofContainerUpload(BetaContainerUploadBlockParam containerUpload)
A content block that represents a file to be uploaded to the container Files uploaded via this block will be available in the container's input directory.
-
ofContainerUpload
final static BetaContentBlockParam ofContainerUpload(String fileId)
Returns an immutable instance of BetaContentBlockParam whose ofContainerUpload variant is built from the given required fileId.
-
ofCompaction
final static BetaContentBlockParam ofCompaction(BetaCompactionBlockParam compaction)
A compaction block containing summary of previous context.
Users should round-trip these blocks from responses to subsequent requests to maintain context across compaction boundaries.
When content is None, the block represents a failed compaction. The server treats these as no-ops. Empty string content is not allowed.
-
ofToolAddition
final static BetaContentBlockParam ofToolAddition(BetaRequestToolAdditionBlock toolAddition)
Mid-conversation directive to make a tool available.
`tool`is a reference to a tool (or MCP toolset) declared in the request's`tools`. Under the`inline-tools-2026-09-15`beta it may instead be a reference to a tool defined earlier in`messages`, or a`tool_definition`object that carries an inline tool definition in`definition`(the same object a`tools`entry holds). An`mcp_toolset`definition also requires the`mcp-client-2026-09-15`beta. The tool is offered to the model from this point in the conversation onward.
-
ofToolAddition
final static BetaContentBlockParam ofToolAddition(BetaRequestToolAdditionBlock.Tool tool)
Returns an immutable instance of BetaContentBlockParam whose ofToolAddition variant is built from the given required tool.
-
ofToolAddition
final static BetaContentBlockParam ofToolAddition(BetaToolChangeToolReference reference)
Alias for calling ofToolAddition with
BetaRequestToolAdditionBlock.Tool.ofReference(reference).
-
ofToolAddition
final static BetaContentBlockParam ofToolAddition(BetaResponseToolChangeToolReference reference)
Alias for calling ofToolAddition with
reference.toParam().
-
ofToolAddition
final static BetaContentBlockParam ofToolAddition(BetaToolChangeMcpToolReference mcpToolReference)
Alias for calling ofToolAddition with
BetaRequestToolAdditionBlock.Tool.ofMcpToolReference(mcpToolReference).
-
ofToolAddition
final static BetaContentBlockParam ofToolAddition(BetaResponseToolChangeMcpToolReference mcpToolReference)
Alias for calling ofToolAddition with
mcpToolReference.toParam().
-
ofToolAddition
final static BetaContentBlockParam ofToolAddition(BetaToolChangeMcpToolsetReference mcpToolsetReference)
Alias for calling ofToolAddition with
BetaRequestToolAdditionBlock.Tool.ofMcpToolsetReference(mcpToolsetReference).
-
ofToolAddition
final static BetaContentBlockParam ofToolAddition(BetaResponseToolChangeMcpToolsetReference mcpToolsetReference)
Alias for calling ofToolAddition with
mcpToolsetReference.toParam().
-
ofToolAddition
final static BetaContentBlockParam ofToolAddition(BetaToolChangeToolDefinitionParam definition)
Alias for calling ofToolAddition with
BetaRequestToolAdditionBlock.Tool.ofDefinition(definition).
-
ofToolAddition
final static BetaContentBlockParam ofToolAddition(BetaToolChangeToolDefinition definition)
Alias for calling ofToolAddition with
definition.toParam().
-
ofToolRemoval
final static BetaContentBlockParam ofToolRemoval(BetaRequestToolRemovalBlock toolRemoval)
Mid-conversation directive to withdraw a tool.
`tool`references a tool (or MCP toolset) by name: one declared in the request's`tools`or defined earlier in`messages`. It is no longer offered to the model from this point in the conversation onward.
-
ofToolRemoval
final static BetaContentBlockParam ofToolRemoval(BetaRequestToolRemovalBlock.Tool tool)
Returns an immutable instance of BetaContentBlockParam whose ofToolRemoval variant is built from the given required tool.
-
ofToolRemoval
final static BetaContentBlockParam ofToolRemoval(BetaToolChangeToolReference reference)
Alias for calling ofToolRemoval with
BetaRequestToolRemovalBlock.Tool.ofReference(reference).
-
ofToolRemoval
final static BetaContentBlockParam ofToolRemoval(BetaResponseToolChangeToolReference reference)
Alias for calling ofToolRemoval with
reference.toParam().
-
ofToolRemoval
final static BetaContentBlockParam ofToolRemoval(BetaToolChangeMcpToolReference mcpToolReference)
Alias for calling ofToolRemoval with
BetaRequestToolRemovalBlock.Tool.ofMcpToolReference(mcpToolReference).
-
ofToolRemoval
final static BetaContentBlockParam ofToolRemoval(BetaResponseToolChangeMcpToolReference mcpToolReference)
Alias for calling ofToolRemoval with
mcpToolReference.toParam().
-
ofToolRemoval
final static BetaContentBlockParam ofToolRemoval(BetaToolChangeMcpToolsetReference mcpToolsetReference)
Alias for calling ofToolRemoval with
BetaRequestToolRemovalBlock.Tool.ofMcpToolsetReference(mcpToolsetReference).
-
ofToolRemoval
final static BetaContentBlockParam ofToolRemoval(BetaResponseToolChangeMcpToolsetReference mcpToolsetReference)
Alias for calling ofToolRemoval with
mcpToolsetReference.toParam().
-
ofMcpToolListing
final static BetaContentBlockParam ofMcpToolListing(BetaMcpToolListingBlockParam mcpToolListing)
The tool listing an MCP server returned while an earlier response was produced, as that response carried it. Send the assistant message back unchanged, this block included, and the server uses this listing for the matching
mcp_toolsetinstead of asking the MCP server again.
-
ofFallback
final static BetaContentBlockParam ofFallback(BetaFallbackBlockParam fallback)
A
fallbackblock echoed back from a prior response.Accepted in
messages[].contentand not rendered into the prompt; not validated against the request'sfallbackschain or top-levelmodel.When you send the assistant turn back, keep this block in its original position. The block marks the boundary between content produced before and after a fallback hop, and the server relies on that boundary to validate the turn: when thinking runs flank the boundary, omitting the block merges them into one span the server cannot validate (the request is rejected), and moving it into the middle of a single run is likewise rejected; between non-thinking blocks the block's placement has no effect on thinking validation.
Some blocks from before the turn's final
fallbackblock must be left out when you send the turn back, and notool_resultis sent for atool_useblock you left out.See the refusals and fallback guide to learn which blocks to keep.
-
-
-
-