Class BetaMessage.Builder
-
- All Implemented Interfaces:
public final class BetaMessage.BuilderA builder for BetaMessage.
-
-
Method Summary
Modifier and Type Method Description final BetaMessage.Builderid(String id)Unique object identifier. final BetaMessage.Builderid(JsonField<String> id)Sets Builder.id to an arbitrary JSON value. final BetaMessage.Buildercontainer(BetaContainer container)Information about the container used in the request (for the code execution tool) final BetaMessage.Buildercontainer(Optional<BetaContainer> container)Alias for calling Builder.container with container.orElse(null).final BetaMessage.Buildercontainer(JsonField<BetaContainer> container)Sets Builder.container to an arbitrary JSON value. final BetaMessage.Buildercontent(List<BetaContentBlock> content)Content generated by the model. final BetaMessage.Buildercontent(JsonField<List<BetaContentBlock>> content)Sets Builder.content to an arbitrary JSON value. final BetaMessage.BuilderaddContent(BetaContentBlock content)Adds a single BetaContentBlock to Builder.content. final BetaMessage.BuilderaddContent(BetaTextBlock text)Alias for calling addContent with BetaContentBlock.ofText(text).final BetaMessage.BuilderaddContent(BetaThinkingBlock thinking)Alias for calling addContent with BetaContentBlock.ofThinking(thinking).final BetaMessage.BuilderaddContent(BetaRedactedThinkingBlock redactedThinking)Alias for calling addContent with BetaContentBlock.ofRedactedThinking(redactedThinking).final BetaMessage.BuilderaddContent(BetaToolUseBlock toolUse)Alias for calling addContent with BetaContentBlock.ofToolUse(toolUse).final BetaMessage.BuilderaddContent(BetaServerToolUseBlock serverToolUse)Alias for calling addContent with BetaContentBlock.ofServerToolUse(serverToolUse).final BetaMessage.BuilderaddContent(BetaWebSearchToolResultBlock webSearchToolResult)Alias for calling addContent with BetaContentBlock.ofWebSearchToolResult(webSearchToolResult).final BetaMessage.BuilderaddContent(BetaWebFetchToolResultBlock webFetchToolResult)Alias for calling addContent with BetaContentBlock.ofWebFetchToolResult(webFetchToolResult).final BetaMessage.BuilderaddContent(BetaAdvisorToolResultBlock advisorToolResult)Alias for calling addContent with BetaContentBlock.ofAdvisorToolResult(advisorToolResult).final BetaMessage.BuilderaddContent(BetaCodeExecutionToolResultBlock codeExecutionToolResult)Alias for calling addContent with BetaContentBlock.ofCodeExecutionToolResult(codeExecutionToolResult).final BetaMessage.BuilderaddContent(BetaBashCodeExecutionToolResultBlock bashCodeExecutionToolResult)Alias for calling addContent with BetaContentBlock.ofBashCodeExecutionToolResult(bashCodeExecutionToolResult).final BetaMessage.BuilderaddContent(BetaTextEditorCodeExecutionToolResultBlock textEditorCodeExecutionToolResult)Alias for calling addContent with BetaContentBlock.ofTextEditorCodeExecutionToolResult(textEditorCodeExecutionToolResult).final BetaMessage.BuilderaddContent(BetaToolSearchToolResultBlock toolSearchToolResult)Alias for calling addContent with BetaContentBlock.ofToolSearchToolResult(toolSearchToolResult).final BetaMessage.BuilderaddContent(BetaMcpToolUseBlock mcpToolUse)Alias for calling addContent with BetaContentBlock.ofMcpToolUse(mcpToolUse).final BetaMessage.BuilderaddContent(BetaMcpToolResultBlock mcpToolResult)Alias for calling addContent with BetaContentBlock.ofMcpToolResult(mcpToolResult).final BetaMessage.BuilderaddContent(BetaContainerUploadBlock containerUpload)Alias for calling addContent with BetaContentBlock.ofContainerUpload(containerUpload).final BetaMessage.BuilderaddContent(BetaCompactionBlock compaction)Alias for calling addContent with BetaContentBlock.ofCompaction(compaction).final BetaMessage.BuilderaddContent(BetaFallbackBlock fallback)Alias for calling addContent with BetaContentBlock.ofFallback(fallback).final BetaMessage.BuilderaddRedactedThinkingContent(String data)Alias for calling addContent with the following: BetaRedactedThinkingBlock.builder() .data(data) .build()final BetaMessage.BuilderaddContainerUploadContent(String fileId)Alias for calling addContent with the following: BetaContainerUploadBlock.builder() .fileId(fileId) .build()final BetaMessage.BuildercontextManagement(BetaContextManagementResponse contextManagement)Context management response. final BetaMessage.BuildercontextManagement(Optional<BetaContextManagementResponse> contextManagement)Alias for calling Builder.contextManagement with contextManagement.orElse(null).final BetaMessage.BuildercontextManagement(JsonField<BetaContextManagementResponse> contextManagement)Sets Builder.contextManagement to an arbitrary JSON value. final BetaMessage.Builderdiagnostics(BetaDiagnostics diagnostics)Response envelope for request-level diagnostics. final BetaMessage.Builderdiagnostics(Optional<BetaDiagnostics> diagnostics)Alias for calling Builder.diagnostics with diagnostics.orElse(null).final BetaMessage.Builderdiagnostics(JsonField<BetaDiagnostics> diagnostics)Sets Builder.diagnostics to an arbitrary JSON value. final BetaMessage.Buildermodel(Model model)The model that will complete your prompt. final BetaMessage.Buildermodel(JsonField<Model> model)Sets Builder.model to an arbitrary JSON value. final BetaMessage.Buildermodel(String value)Sets model to an arbitrary String. final BetaMessage.Builderrole(JsonValue role)Sets the field to an arbitrary JSON value. final BetaMessage.BuilderstopDetails(BetaRefusalStopDetails stopDetails)Structured information about a refusal. final BetaMessage.BuilderstopDetails(Optional<BetaRefusalStopDetails> stopDetails)Alias for calling Builder.stopDetails with stopDetails.orElse(null).final BetaMessage.BuilderstopDetails(JsonField<BetaRefusalStopDetails> stopDetails)Sets Builder.stopDetails to an arbitrary JSON value. final BetaMessage.BuilderstopReason(BetaStopReason stopReason)The reason that we stopped. final BetaMessage.BuilderstopReason(Optional<BetaStopReason> stopReason)Alias for calling Builder.stopReason with stopReason.orElse(null).final BetaMessage.BuilderstopReason(JsonField<BetaStopReason> stopReason)Sets Builder.stopReason to an arbitrary JSON value. final BetaMessage.BuilderstopSequence(String stopSequence)Which custom stop sequence was generated, if any. final BetaMessage.BuilderstopSequence(Optional<String> stopSequence)Alias for calling Builder.stopSequence with stopSequence.orElse(null).final BetaMessage.BuilderstopSequence(JsonField<String> stopSequence)Sets Builder.stopSequence to an arbitrary JSON value. final BetaMessage.Buildertype(JsonValue type)Sets the field to an arbitrary JSON value. final BetaMessage.Builderusage(BetaUsage usage)Billing and rate-limit usage. final BetaMessage.Builderusage(JsonField<BetaUsage> usage)Sets Builder.usage to an arbitrary JSON value. final BetaMessage.BuilderadditionalProperties(Map<String, JsonValue> additionalProperties)final BetaMessage.BuilderputAdditionalProperty(String key, JsonValue value)final BetaMessage.BuilderputAllAdditionalProperties(Map<String, JsonValue> additionalProperties)final BetaMessage.BuilderremoveAdditionalProperty(String key)final BetaMessage.BuilderremoveAllAdditionalProperties(Set<String> keys)final BetaMessagebuild()Returns an immutable instance of BetaMessage. -
-
Method Detail
-
id
final BetaMessage.Builder id(String id)
Unique object identifier.
The format and length of IDs may change over time.
-
id
final BetaMessage.Builder id(JsonField<String> id)
Sets Builder.id to an arbitrary JSON value.
You should usually call Builder.id with a well-typed String value instead. This method is primarily for setting the field to an undocumented or not yet supported value.
-
container
final BetaMessage.Builder container(BetaContainer container)
Information about the container used in the request (for the code execution tool)
-
container
final BetaMessage.Builder container(Optional<BetaContainer> container)
Alias for calling Builder.container with
container.orElse(null).
-
container
final BetaMessage.Builder container(JsonField<BetaContainer> container)
Sets Builder.container to an arbitrary JSON value.
You should usually call Builder.container with a well-typed BetaContainer value instead. This method is primarily for setting the field to an undocumented or not yet supported value.
-
content
final BetaMessage.Builder content(List<BetaContentBlock> content)
Content generated by the model.
This is an array of content blocks, each of which has a
typethat determines its shape.Example:
[{"type": "text", "text": "Hi, I'm Claude."}]If the request input
messagesended with anassistantturn, then the responsecontentwill continue directly from that last turn. You can use this to constrain the model's output.For example, if the input
messageswere:[ {"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
contentmight be:[{"type": "text", "text": "B)"}]
-
content
final BetaMessage.Builder content(JsonField<List<BetaContentBlock>> content)
Sets Builder.content to an arbitrary JSON value.
You should usually call Builder.content with a well-typed
List<BetaContentBlock>value instead. This method is primarily for setting the field to an undocumented or not yet supported value.
-
addContent
final BetaMessage.Builder addContent(BetaContentBlock content)
Adds a single BetaContentBlock to Builder.content.
-
addContent
final BetaMessage.Builder addContent(BetaTextBlock text)
Alias for calling addContent with
BetaContentBlock.ofText(text).
-
addContent
final BetaMessage.Builder addContent(BetaThinkingBlock thinking)
Alias for calling addContent with
BetaContentBlock.ofThinking(thinking).
-
addContent
final BetaMessage.Builder addContent(BetaRedactedThinkingBlock redactedThinking)
Alias for calling addContent with
BetaContentBlock.ofRedactedThinking(redactedThinking).
-
addContent
final BetaMessage.Builder addContent(BetaToolUseBlock toolUse)
Alias for calling addContent with
BetaContentBlock.ofToolUse(toolUse).
-
addContent
final BetaMessage.Builder addContent(BetaServerToolUseBlock serverToolUse)
Alias for calling addContent with
BetaContentBlock.ofServerToolUse(serverToolUse).
-
addContent
final BetaMessage.Builder addContent(BetaWebSearchToolResultBlock webSearchToolResult)
Alias for calling addContent with
BetaContentBlock.ofWebSearchToolResult(webSearchToolResult).
-
addContent
final BetaMessage.Builder addContent(BetaWebFetchToolResultBlock webFetchToolResult)
Alias for calling addContent with
BetaContentBlock.ofWebFetchToolResult(webFetchToolResult).
-
addContent
final BetaMessage.Builder addContent(BetaAdvisorToolResultBlock advisorToolResult)
Alias for calling addContent with
BetaContentBlock.ofAdvisorToolResult(advisorToolResult).
-
addContent
final BetaMessage.Builder addContent(BetaCodeExecutionToolResultBlock codeExecutionToolResult)
Alias for calling addContent with
BetaContentBlock.ofCodeExecutionToolResult(codeExecutionToolResult).
-
addContent
final BetaMessage.Builder addContent(BetaBashCodeExecutionToolResultBlock bashCodeExecutionToolResult)
Alias for calling addContent with
BetaContentBlock.ofBashCodeExecutionToolResult(bashCodeExecutionToolResult).
-
addContent
final BetaMessage.Builder addContent(BetaTextEditorCodeExecutionToolResultBlock textEditorCodeExecutionToolResult)
Alias for calling addContent with
BetaContentBlock.ofTextEditorCodeExecutionToolResult(textEditorCodeExecutionToolResult).
-
addContent
final BetaMessage.Builder addContent(BetaToolSearchToolResultBlock toolSearchToolResult)
Alias for calling addContent with
BetaContentBlock.ofToolSearchToolResult(toolSearchToolResult).
-
addContent
final BetaMessage.Builder addContent(BetaMcpToolUseBlock mcpToolUse)
Alias for calling addContent with
BetaContentBlock.ofMcpToolUse(mcpToolUse).
-
addContent
final BetaMessage.Builder addContent(BetaMcpToolResultBlock mcpToolResult)
Alias for calling addContent with
BetaContentBlock.ofMcpToolResult(mcpToolResult).
-
addContent
final BetaMessage.Builder addContent(BetaContainerUploadBlock containerUpload)
Alias for calling addContent with
BetaContentBlock.ofContainerUpload(containerUpload).
-
addContent
final BetaMessage.Builder addContent(BetaCompactionBlock compaction)
Alias for calling addContent with
BetaContentBlock.ofCompaction(compaction).
-
addContent
final BetaMessage.Builder addContent(BetaFallbackBlock fallback)
Alias for calling addContent with
BetaContentBlock.ofFallback(fallback).
-
addRedactedThinkingContent
final BetaMessage.Builder addRedactedThinkingContent(String data)
Alias for calling addContent with the following:
BetaRedactedThinkingBlock.builder() .data(data) .build()
-
addContainerUploadContent
final BetaMessage.Builder addContainerUploadContent(String fileId)
Alias for calling addContent with the following:
BetaContainerUploadBlock.builder() .fileId(fileId) .build()
-
contextManagement
final BetaMessage.Builder contextManagement(BetaContextManagementResponse contextManagement)
Context management response.
Information about context management strategies applied during the request.
-
contextManagement
final BetaMessage.Builder contextManagement(Optional<BetaContextManagementResponse> contextManagement)
Alias for calling Builder.contextManagement with
contextManagement.orElse(null).
-
contextManagement
final BetaMessage.Builder contextManagement(JsonField<BetaContextManagementResponse> contextManagement)
Sets Builder.contextManagement to an arbitrary JSON value.
You should usually call Builder.contextManagement with a well-typed BetaContextManagementResponse value instead. This method is primarily for setting the field to an undocumented or not yet supported value.
-
diagnostics
final BetaMessage.Builder diagnostics(BetaDiagnostics diagnostics)
Response envelope for request-level diagnostics. Present (possibly null) whenever the caller supplied
diagnosticson the request.
-
diagnostics
final BetaMessage.Builder diagnostics(Optional<BetaDiagnostics> diagnostics)
Alias for calling Builder.diagnostics with
diagnostics.orElse(null).
-
diagnostics
final BetaMessage.Builder diagnostics(JsonField<BetaDiagnostics> diagnostics)
Sets Builder.diagnostics to an arbitrary JSON value.
You should usually call Builder.diagnostics with a well-typed BetaDiagnostics value instead. This method is primarily for setting the field to an undocumented or not yet supported value.
-
model
final BetaMessage.Builder model(Model model)
The model that will complete your prompt.
See models for additional details and options.
-
model
final BetaMessage.Builder model(JsonField<Model> model)
Sets Builder.model to an arbitrary JSON value.
You should usually call Builder.model with a well-typed Model value instead. This method is primarily for setting the field to an undocumented or not yet supported value.
-
model
final BetaMessage.Builder model(String value)
Sets model to an arbitrary String.
You should usually call model with a well-typed Model constant instead. This method is primarily for setting the field to an undocumented or not yet supported value.
-
role
final BetaMessage.Builder role(JsonValue role)
Sets the field to an arbitrary JSON value.
It is usually unnecessary to call this method because the field defaults to the following:
JsonValue.from("assistant")This method is primarily for setting the field to an undocumented or not yet supported value.
-
stopDetails
final BetaMessage.Builder stopDetails(BetaRefusalStopDetails stopDetails)
Structured information about a refusal.
-
stopDetails
final BetaMessage.Builder stopDetails(Optional<BetaRefusalStopDetails> stopDetails)
Alias for calling Builder.stopDetails with
stopDetails.orElse(null).
-
stopDetails
final BetaMessage.Builder stopDetails(JsonField<BetaRefusalStopDetails> stopDetails)
Sets Builder.stopDetails to an arbitrary JSON value.
You should usually call Builder.stopDetails with a well-typed BetaRefusalStopDetails value instead. This method is primarily for setting the field to an undocumented or not yet supported value.
-
stopReason
final BetaMessage.Builder stopReason(BetaStopReason stopReason)
The reason that we stopped.
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
In non-streaming mode this value is always non-null. In streaming mode, it is null in the
message_startevent and non-null otherwise.
-
stopReason
final BetaMessage.Builder stopReason(Optional<BetaStopReason> stopReason)
Alias for calling Builder.stopReason with
stopReason.orElse(null).
-
stopReason
final BetaMessage.Builder stopReason(JsonField<BetaStopReason> stopReason)
Sets Builder.stopReason to an arbitrary JSON value.
You should usually call Builder.stopReason with a well-typed BetaStopReason value instead. This method is primarily for setting the field to an undocumented or not yet supported value.
-
stopSequence
final BetaMessage.Builder stopSequence(String stopSequence)
Which custom stop sequence was generated, if any.
This value will be a non-null string if one of your custom stop sequences was generated.
-
stopSequence
final BetaMessage.Builder stopSequence(Optional<String> stopSequence)
Alias for calling Builder.stopSequence with
stopSequence.orElse(null).
-
stopSequence
final BetaMessage.Builder stopSequence(JsonField<String> stopSequence)
Sets Builder.stopSequence to an arbitrary JSON value.
You should usually call Builder.stopSequence with a well-typed String value instead. This method is primarily for setting the field to an undocumented or not yet supported value.
-
type
final BetaMessage.Builder type(JsonValue type)
Sets the field to an arbitrary JSON value.
It is usually unnecessary to call this method because the field defaults to the following:
JsonValue.from("message")This method is primarily for setting the field to an undocumented or not yet supported value.
-
usage
final BetaMessage.Builder usage(BetaUsage usage)
Billing and rate-limit usage.
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
usagewill not match one-to-one with the exact visible content of an API request or response.For example,
output_tokenswill 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, andcache_read_input_tokens.
-
usage
final BetaMessage.Builder usage(JsonField<BetaUsage> usage)
Sets Builder.usage to an arbitrary JSON value.
You should usually call Builder.usage with a well-typed BetaUsage value instead. This method is primarily for setting the field to an undocumented or not yet supported value.
-
additionalProperties
final BetaMessage.Builder additionalProperties(Map<String, JsonValue> additionalProperties)
-
putAdditionalProperty
final BetaMessage.Builder putAdditionalProperty(String key, JsonValue value)
-
putAllAdditionalProperties
final BetaMessage.Builder putAllAdditionalProperties(Map<String, JsonValue> additionalProperties)
-
removeAdditionalProperty
final BetaMessage.Builder removeAdditionalProperty(String key)
-
removeAllAdditionalProperties
final BetaMessage.Builder removeAllAdditionalProperties(Set<String> keys)
-
build
final BetaMessage build()
Returns an immutable instance of BetaMessage.
Further updates to this Builder will not mutate the returned instance.
The following fields are required:
.id() .container() .content() .contextManagement() .diagnostics() .model() .stopDetails() .stopReason() .stopSequence() .usage()
-
-
-
-