Class BetaMessage
-
- All Implemented Interfaces:
public final class BetaMessage
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classBetaMessage.BuilderA builder for BetaMessage.
-
Method Summary
Modifier and Type Method Description final Stringid()Unique object identifier. final Optional<BetaContainer>container()Information about the container used in this request. final List<BetaContentBlock>content()Content generated by the model. final Optional<BetaContextManagementResponse>contextManagement()Context management response. final Optional<BetaDiagnostics>diagnostics()Request-level diagnostics. final Modelmodel()The model that will complete your prompt. final Optional<BetaRefusalStopDetails>stopDetails()Structured information about why model output stopped. final Optional<BetaStopReason>stopReason()The reason that we stopped. final Optional<String>stopSequence()Which custom stop sequence was generated, if any. final BetaUsageusage()Billing and rate-limit usage. final Optional<List<BetaInputTransformation>>inputTransformations()Changes the API made to the request's input before showing it to the model, and blocks that failed a binding check but were left unchanged: one entry per block, in request order. final BetaMessageParamtoParam()final JsonValue_role()Conversational role of the generated message. final JsonValue_type()Object type. final JsonField<String>_id()Returns the raw JSON value of id. final JsonField<BetaContainer>_container()Returns the raw JSON value of container. final JsonField<List<BetaContentBlock>>_content()Returns the raw JSON value of content. final JsonField<BetaContextManagementResponse>_contextManagement()Returns the raw JSON value of contextManagement. final JsonField<BetaDiagnostics>_diagnostics()Returns the raw JSON value of diagnostics. final JsonField<Model>_model()Returns the raw JSON value of model. final JsonField<BetaRefusalStopDetails>_stopDetails()Returns the raw JSON value of stopDetails. final JsonField<BetaStopReason>_stopReason()Returns the raw JSON value of stopReason. final JsonField<String>_stopSequence()Returns the raw JSON value of stopSequence. final JsonField<BetaUsage>_usage()Returns the raw JSON value of usage. final JsonField<List<BetaInputTransformation>>_inputTransformations()Returns the raw JSON value of inputTransformations. final Map<String, JsonValue>_additionalProperties()final BetaMessage.BuildertoBuilder()final BetaMessagevalidate()Validates that the types of all values in this object match their expected types recursively. final BooleanisValid()Booleanequals(Object other)IntegerhashCode()StringtoString()final static BetaMessage.Builderbuilder()Returns a mutable builder for constructing an instance of BetaMessage. -
-
Method Detail
-
container
final Optional<BetaContainer> container()
Information about the container used in this request.
This will be non-null if a container tool (e.g. code execution) was used.
-
content
final 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)"}]
-
contextManagement
final Optional<BetaContextManagementResponse> contextManagement()
Context management response.
Information about context management strategies applied during the request.
-
diagnostics
final Optional<BetaDiagnostics> diagnostics()
Request-level diagnostics.
nullwhen the request did not supplydiagnostics, or when it did and no prompt-cache divergence was detected.
-
model
final Model model()
The model that will complete your prompt.
See models for additional details and options.
-
stopDetails
final Optional<BetaRefusalStopDetails> stopDetails()
Structured information about why model output stopped.
This is
nullwhen thestop_reasonhas no additional detail to report.
-
stopReason
final Optional<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"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_startevent and non-null otherwise.
-
stopSequence
final 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.
-
usage
final 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.
-
inputTransformations
final Optional<List<BetaInputTransformation>> inputTransformations()
Changes the API made to the request's input before showing it to the model, and blocks that failed a binding check but were left unchanged: one entry per block, in request order. Two entry types today.
thinking_dropped— athinking,redacted_thinkingorconnector_textblock from the request'smessagesthat was removed from the prompt instead of being shown to the model because it failed a binding check.thinking_mismatch_allowed— athinkingorredacted_thinkingblock that failed the conversation check (the conversation before it differs from the one it was created in, or it carries no record of one on a model that requires it) and was shown to the model all the same, because that check is not enforced for this request. More entry types may be added over time; ignore types you do not recognize.Requires
anthropic-beta: thinking-binding-controls-2026-08-01. Present on every such response from a model that supports extended thinking, as[]when there is no entry to report; without the beta, blocks are removed or left in place all the same but nothing is reported. Removed blocks contribute nothing tousage.input_tokens; blocks left in place count as sent. When streaming, the array is final inmessage_start; the finalmessage_deltaevent carries it only when a server-side model fallback happened mid-stream, in which case it holds the serving model's entries and replaces the one inmessage_start.
-
toParam
final BetaMessageParam toParam()
-
_role
final JsonValue _role()
Conversational role of the generated message.
This will always be
"assistant".Expected to always return the following:
JsonValue.from("assistant")However, this method can be useful for debugging and logging (e.g. if the server responded with an unexpected value).
-
_type
final JsonValue _type()
Object type.
For Messages, this is always
"message".Expected to always return the following:
JsonValue.from("message")However, this method can be useful for debugging and logging (e.g. if the server responded with an unexpected value).
-
_id
final JsonField<String> _id()
Returns the raw JSON value of id.
Unlike id, this method doesn't throw if the JSON field has an unexpected type.
-
_container
final JsonField<BetaContainer> _container()
Returns the raw JSON value of container.
Unlike container, this method doesn't throw if the JSON field has an unexpected type.
-
_content
final JsonField<List<BetaContentBlock>> _content()
Returns the raw JSON value of content.
Unlike content, this method doesn't throw if the JSON field has an unexpected type.
-
_contextManagement
final JsonField<BetaContextManagementResponse> _contextManagement()
Returns the raw JSON value of contextManagement.
Unlike contextManagement, this method doesn't throw if the JSON field has an unexpected type.
-
_diagnostics
final JsonField<BetaDiagnostics> _diagnostics()
Returns the raw JSON value of diagnostics.
Unlike diagnostics, this method doesn't throw if the JSON field has an unexpected type.
-
_model
final JsonField<Model> _model()
Returns the raw JSON value of model.
Unlike model, this method doesn't throw if the JSON field has an unexpected type.
-
_stopDetails
final JsonField<BetaRefusalStopDetails> _stopDetails()
Returns the raw JSON value of stopDetails.
Unlike stopDetails, this method doesn't throw if the JSON field has an unexpected type.
-
_stopReason
final JsonField<BetaStopReason> _stopReason()
Returns the raw JSON value of stopReason.
Unlike stopReason, this method doesn't throw if the JSON field has an unexpected type.
-
_stopSequence
final JsonField<String> _stopSequence()
Returns the raw JSON value of stopSequence.
Unlike stopSequence, this method doesn't throw if the JSON field has an unexpected type.
-
_usage
final JsonField<BetaUsage> _usage()
Returns the raw JSON value of usage.
Unlike usage, this method doesn't throw if the JSON field has an unexpected type.
-
_inputTransformations
final JsonField<List<BetaInputTransformation>> _inputTransformations()
Returns the raw JSON value of inputTransformations.
Unlike inputTransformations, this method doesn't throw if the JSON field has an unexpected type.
-
_additionalProperties
final Map<String, JsonValue> _additionalProperties()
-
toBuilder
final BetaMessage.Builder toBuilder()
-
validate
final BetaMessage 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.
-
builder
final static BetaMessage.Builder builder()
Returns a mutable builder for constructing an instance of BetaMessage.
The following fields are required:
.id() .container() .content() .contextManagement() .diagnostics() .model() .stopDetails() .stopReason() .stopSequence() .usage()
-
-
-
-