Class Message.Builder
-
- All Implemented Interfaces:
public final class Message.BuilderA builder for Message.
-
-
Method Summary
Modifier and Type Method Description final Message.Builderid(String id)Unique object identifier. final Message.Builderid(JsonField<String> id)Sets Builder.id to an arbitrary JSON value. final Message.Buildercontent(List<ContentBlock> content)Content generated by the model. final Message.Buildercontent(JsonField<List<ContentBlock>> content)Sets Builder.content to an arbitrary JSON value. final Message.BuilderaddContent(ContentBlock content)Adds a single ContentBlock to Builder.content. final Message.BuilderaddContent(TextBlock text)Alias for calling addContent with ContentBlock.ofText(text).final Message.BuilderaddContent(ToolUseBlock toolUse)Alias for calling addContent with ContentBlock.ofToolUse(toolUse).final Message.BuilderaddContent(ServerToolUseBlock serverToolUse)Alias for calling addContent with ContentBlock.ofServerToolUse(serverToolUse).final Message.BuilderaddContent(WebSearchToolResultBlock webSearchToolResult)Alias for calling addContent with ContentBlock.ofWebSearchToolResult(webSearchToolResult).final Message.BuilderaddContent(ThinkingBlock thinking)Alias for calling addContent with ContentBlock.ofThinking(thinking).final Message.BuilderaddContent(RedactedThinkingBlock redactedThinking)Alias for calling addContent with ContentBlock.ofRedactedThinking(redactedThinking).final Message.BuilderaddRedactedThinkingContent(String data)Alias for calling addContent with the following: RedactedThinkingBlock.builder() .data(data) .build()final Message.Buildermodel(Model model)The model that will complete your prompt. final Message.Buildermodel(JsonField<Model> model)Sets Builder.model to an arbitrary JSON value. final Message.Buildermodel(String value)Sets model to an arbitrary String. final Message.Builderrole(JsonValue role)Sets the field to an arbitrary JSON value. final Message.BuilderstopReason(StopReason stopReason)The reason that we stopped. final Message.BuilderstopReason(Optional<StopReason> stopReason)Alias for calling Builder.stopReason with stopReason.orElse(null).final Message.BuilderstopReason(JsonField<StopReason> stopReason)Sets Builder.stopReason to an arbitrary JSON value. final Message.BuilderstopSequence(String stopSequence)Which custom stop sequence was generated, if any. final Message.BuilderstopSequence(Optional<String> stopSequence)Alias for calling Builder.stopSequence with stopSequence.orElse(null).final Message.BuilderstopSequence(JsonField<String> stopSequence)Sets Builder.stopSequence to an arbitrary JSON value. final Message.Buildertype(JsonValue type)Sets the field to an arbitrary JSON value. final Message.Builderusage(Usage usage)Billing and rate-limit usage. final Message.Builderusage(JsonField<Usage> usage)Sets Builder.usage to an arbitrary JSON value. final Message.BuilderadditionalProperties(Map<String, JsonValue> additionalProperties)final Message.BuilderputAdditionalProperty(String key, JsonValue value)final Message.BuilderputAllAdditionalProperties(Map<String, JsonValue> additionalProperties)final Message.BuilderremoveAdditionalProperty(String key)final Message.BuilderremoveAllAdditionalProperties(Set<String> keys)final Messagebuild()Returns an immutable instance of Message. -
-
Method Detail
-
id
final Message.Builder id(String id)
Unique object identifier.
The format and length of IDs may change over time.
-
id
final Message.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.
-
content
final Message.Builder content(List<ContentBlock> 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 Message.Builder content(JsonField<List<ContentBlock>> content)
Sets Builder.content to an arbitrary JSON value.
You should usually call Builder.content with a well-typed
List<ContentBlock>value instead. This method is primarily for setting the field to an undocumented or not yet supported value.
-
addContent
final Message.Builder addContent(ContentBlock content)
Adds a single ContentBlock to Builder.content.
-
addContent
final Message.Builder addContent(TextBlock text)
Alias for calling addContent with
ContentBlock.ofText(text).
-
addContent
final Message.Builder addContent(ToolUseBlock toolUse)
Alias for calling addContent with
ContentBlock.ofToolUse(toolUse).
-
addContent
final Message.Builder addContent(ServerToolUseBlock serverToolUse)
Alias for calling addContent with
ContentBlock.ofServerToolUse(serverToolUse).
-
addContent
final Message.Builder addContent(WebSearchToolResultBlock webSearchToolResult)
Alias for calling addContent with
ContentBlock.ofWebSearchToolResult(webSearchToolResult).
-
addContent
final Message.Builder addContent(ThinkingBlock thinking)
Alias for calling addContent with
ContentBlock.ofThinking(thinking).
-
addContent
final Message.Builder addContent(RedactedThinkingBlock redactedThinking)
Alias for calling addContent with
ContentBlock.ofRedactedThinking(redactedThinking).
-
addRedactedThinkingContent
final Message.Builder addRedactedThinkingContent(String data)
Alias for calling addContent with the following:
RedactedThinkingBlock.builder() .data(data) .build()
-
model
final Message.Builder model(Model model)
The model that will complete your prompt.\n\nSee models for additional details and options.
-
model
final Message.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 Message.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 Message.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.
-
stopReason
final Message.Builder stopReason(StopReason 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
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 Message.Builder stopReason(Optional<StopReason> stopReason)
Alias for calling Builder.stopReason with
stopReason.orElse(null).
-
stopReason
final Message.Builder stopReason(JsonField<StopReason> stopReason)
Sets Builder.stopReason to an arbitrary JSON value.
You should usually call Builder.stopReason with a well-typed StopReason value instead. This method is primarily for setting the field to an undocumented or not yet supported value.
-
stopSequence
final Message.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 Message.Builder stopSequence(Optional<String> stopSequence)
Alias for calling Builder.stopSequence with
stopSequence.orElse(null).
-
stopSequence
final Message.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 Message.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 Message.Builder usage(Usage 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 Message.Builder usage(JsonField<Usage> usage)
Sets Builder.usage to an arbitrary JSON value.
You should usually call Builder.usage with a well-typed Usage value instead. This method is primarily for setting the field to an undocumented or not yet supported value.
-
additionalProperties
final Message.Builder additionalProperties(Map<String, JsonValue> additionalProperties)
-
putAdditionalProperty
final Message.Builder putAdditionalProperty(String key, JsonValue value)
-
putAllAdditionalProperties
final Message.Builder putAllAdditionalProperties(Map<String, JsonValue> additionalProperties)
-
removeAdditionalProperty
final Message.Builder removeAdditionalProperty(String key)
-
removeAllAdditionalProperties
final Message.Builder removeAllAdditionalProperties(Set<String> keys)
-
-
-
-