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)Unique object identifier. final BetaMessage.Buildercontent(List<BetaContentBlock> content)Content generated by the model. final BetaMessage.Buildercontent(JsonField<List<BetaContentBlock>> content)Content generated by the model. final BetaMessage.BuilderaddContent(BetaContentBlock content)Content generated by the model. final BetaMessage.BuilderaddContent(BetaTextBlock text)Content generated by the model. final BetaMessage.BuilderaddContent(BetaToolUseBlock toolUse)Content generated by the model. final BetaMessage.Buildermodel(Model model)The model that will complete your prompt. final BetaMessage.Buildermodel(JsonField<Model> model)The model that will complete your prompt. final BetaMessage.Buildermodel(String value)The model that will complete your prompt. final BetaMessage.Builderrole(BetaMessage.Role role)Conversational role of the generated message. final BetaMessage.Builderrole(JsonField<BetaMessage.Role> role)Conversational role of the generated message. final BetaMessage.BuilderstopReason(BetaMessage.StopReason stopReason)The reason that we stopped. final BetaMessage.BuilderstopReason(Optional<BetaMessage.StopReason> stopReason)The reason that we stopped. final BetaMessage.BuilderstopReason(JsonField<BetaMessage.StopReason> stopReason)The reason that we stopped. final BetaMessage.BuilderstopSequence(String stopSequence)Which custom stop sequence was generated, if any. final BetaMessage.BuilderstopSequence(Optional<String> stopSequence)Which custom stop sequence was generated, if any. final BetaMessage.BuilderstopSequence(JsonField<String> stopSequence)Which custom stop sequence was generated, if any. final BetaMessage.Buildertype(BetaMessage.Type type)Object type. final BetaMessage.Buildertype(JsonField<BetaMessage.Type> type)Object type. final BetaMessage.Builderusage(BetaUsage usage)Billing and rate-limit usage. final BetaMessage.Builderusage(JsonField<BetaUsage> usage)Billing and rate-limit usage. 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()-
-
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)
Unique object identifier.
The format and length of IDs may change over time.
-
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)
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)" }]
-
addContent
final BetaMessage.Builder addContent(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)" }]
-
addContent
final BetaMessage.Builder addContent(BetaTextBlock text)
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)" }]
-
addContent
final BetaMessage.Builder addContent(BetaToolUseBlock toolUse)
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)" }]
-
model
final BetaMessage.Builder model(Model model)
The model that will complete your prompt.\n\nSee models for additional details and options.
-
model
final BetaMessage.Builder model(JsonField<Model> model)
The model that will complete your prompt.\n\nSee models for additional details and options.
-
model
final BetaMessage.Builder model(String value)
The model that will complete your prompt.\n\nSee models for additional details and options.
-
role
final BetaMessage.Builder role(BetaMessage.Role role)
Conversational role of the generated message.
This will always be
"assistant".
-
role
final BetaMessage.Builder role(JsonField<BetaMessage.Role> role)
Conversational role of the generated message.
This will always be
"assistant".
-
stopReason
final BetaMessage.Builder stopReason(BetaMessage.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 BetaMessage.Builder stopReason(Optional<BetaMessage.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 BetaMessage.Builder stopReason(JsonField<BetaMessage.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.
-
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)
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(JsonField<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.
-
type
final BetaMessage.Builder type(BetaMessage.Type type)
Object type.
For Messages, this is always
"message".
-
type
final BetaMessage.Builder type(JsonField<BetaMessage.Type> type)
Object type.
For Messages, this is always
"message".
-
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.
-
usage
final BetaMessage.Builder usage(JsonField<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.
-
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()
-
-
-
-