Class: Anthropic::Models::Beta::BetaMessage

Inherits:
Internal::Type::BaseModel show all
Defined in:
lib/anthropic/models/beta/beta_message.rb,
sig/anthropic/models/beta/beta_message.rbs

Overview

See Also:

  • Anthropic::Resources::Beta::Messages#create
  • Anthropic::Resources::Beta::Messages#stream_raw

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Internal::Type::BaseModel

==, #==, #[], coerce, #deconstruct_keys, #deep_to_h, dump, fields, hash, #hash, inherited, inspect, #inspect, known_fields, optional, recursively_to_h, required, #to_h, #to_json, #to_s, to_sorbet_type, #to_yaml

Methods included from Internal::Type::Converter

#coerce, coerce, #dump, dump, inspect, #inspect, meta_info, new_coerce_state, type_info

Methods included from Internal::Util::SorbetRuntimeSupport

#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type

Constructor Details

#initializeObject



52
# File 'sig/anthropic/models/beta/beta_message.rbs', line 52

def initialize: (

Instance Attribute Details

#containerAnthropic::Models::Beta::BetaContainer?

Information about the container used in the request (for the code execution tool)

Parameters:

  • value (Anthropic::Beta::BetaContainer, nil)

Returns:



23
# File 'lib/anthropic/models/beta/beta_message.rb', line 23

required :container, -> { Anthropic::Beta::BetaContainer }, nil?: true

#contentArray<Anthropic::Models::Beta::BetaTextBlock, Anthropic::Models::Beta::BetaThinkingBlock, Anthropic::Models::Beta::BetaRedactedThinkingBlock, Anthropic::Models::Beta::BetaToolUseBlock, Anthropic::Models::Beta::BetaServerToolUseBlock, Anthropic::Models::Beta::BetaWebSearchToolResultBlock, Anthropic::Models::Beta::BetaWebFetchToolResultBlock, Anthropic::Models::Beta::BetaAdvisorToolResultBlock, Anthropic::Models::Beta::BetaCodeExecutionToolResultBlock, Anthropic::Models::Beta::BetaBashCodeExecutionToolResultBlock, Anthropic::Models::Beta::BetaTextEditorCodeExecutionToolResultBlock, Anthropic::Models::Beta::BetaToolSearchToolResultBlock, Anthropic::Models::Beta::BetaMCPToolUseBlock, Anthropic::Models::Beta::BetaMCPToolResultBlock, Anthropic::Models::Beta::BetaContainerUploadBlock, Anthropic::Models::Beta::BetaCompactionBlock, Anthropic::Models::Beta::BetaFallbackBlock>

Content generated by the model.

This is an array of content blocks, each of which has a type that determines its shape.

Example:

[{ "type": "text", "text": "Hi, I'm Claude." }]

If the request input messages ended with an assistant turn, then the response content will continue directly from that last turn. You can use this to constrain the model's output.

For example, if the input messages were:

[
  {
    "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 content might be:

[{ "type": "text", "text": "B)" }]


60
# File 'lib/anthropic/models/beta/beta_message.rb', line 60

required :content, -> { Anthropic::Internal::Type::ArrayOf[union: Anthropic::Beta::BetaContentBlock] }

#context_managementAnthropic::Models::Beta::BetaContextManagementResponse?

Context management response.

Information about context management strategies applied during the request.

Parameters:

  • value (Anthropic::Beta::BetaContextManagementResponse, nil)

Returns:



80
# File 'lib/anthropic/models/beta/beta_message.rb', line 80

required :context_management, -> { Anthropic::Beta::BetaContextManagementResponse }, nil?: true

#diagnosticsAnthropic::Models::Beta::BetaDiagnostics?

Response envelope for request-level diagnostics. Present (possibly null) whenever the caller supplied diagnostics on the request.

Parameters:

  • value (Anthropic::Beta::BetaDiagnostics, nil)

Returns:



87
# File 'lib/anthropic/models/beta/beta_message.rb', line 87

required :diagnostics, -> { Anthropic::Beta::BetaDiagnostics }, nil?: true

#idString

Unique object identifier.

The format and length of IDs may change over time.

Parameters:

  • value (String)

Returns:

  • (String)


16
# File 'lib/anthropic/models/beta/beta_message.rb', line 16

required :id, String

#input_transformationsArray<Anthropic::Models::Beta::BetaThinkingDroppedInputTransformation>?

Changes the API made to the request's input before showing it to the model: one entry per change, in request order. Today the only entry type is thinking_dropped — a thinking, redacted_thinking or connector_text block from the request's messages that was removed from the prompt instead of being shown to the model because it failed a binding check. 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 nothing was changed; without the beta, blocks are removed all the same but nothing is reported. Removed blocks contribute nothing to usage.input_tokens. When streaming, the array is final in message_start; the final message_delta event 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 in message_start.

Parameters:

  • value (::Array[Anthropic::Beta::BetaThinkingDroppedInputTransformation], nil)

Returns:



188
189
190
191
192
# File 'lib/anthropic/models/beta/beta_message.rb', line 188

optional :input_transformations,
-> {
  Anthropic::Internal::Type::ArrayOf[Anthropic::Beta::BetaThinkingDroppedInputTransformation]
},
nil?: true

#modelSymbol, ...

The model that will complete your prompt.

See models for additional details and options.

Parameters:

  • value (Anthropic::Models::model)

Returns:



96
# File 'lib/anthropic/models/beta/beta_message.rb', line 96

required :model, union: -> { Anthropic::Model }

#roleSymbol, :assistant

Conversational role of the generated message.

This will always be "assistant".

Parameters:

  • value (:assistant)

Returns:

  • (Symbol, :assistant)


104
# File 'lib/anthropic/models/beta/beta_message.rb', line 104

required :role, const: :assistant

#stop_detailsAnthropic::Models::Beta::BetaRefusalStopDetails?

Structured information about a refusal.

Parameters:

  • value (Anthropic::Beta::BetaRefusalStopDetails, nil)

Returns:



110
# File 'lib/anthropic/models/beta/beta_message.rb', line 110

required :stop_details, -> { Anthropic::Beta::BetaRefusalStopDetails }, nil?: true

#stop_reasonSymbol, ...

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 requested max_tokens or the model's maximum
  • "stop_sequence": one of your provided custom stop_sequences was 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_start event and non-null otherwise.

Parameters:

  • value (Anthropic::Models::Beta::beta_stop_reason, nil)

Returns:



131
# File 'lib/anthropic/models/beta/beta_message.rb', line 131

required :stop_reason, enum: -> { Anthropic::Beta::BetaStopReason }, nil?: true

#stop_sequenceString?

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.

Parameters:

  • value (String, nil)

Returns:

  • (String, nil)


140
# File 'lib/anthropic/models/beta/beta_message.rb', line 140

required :stop_sequence, String, nil?: true

#typeSymbol, :message

Object type.

For Messages, this is always "message".

Parameters:

  • value (:message)

Returns:

  • (Symbol, :message)


148
# File 'lib/anthropic/models/beta/beta_message.rb', line 148

required :type, const: :message

#usageAnthropic::Models::Beta::BetaUsage

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 usage will not match one-to-one with the exact visible content of an API request or response.

For example, output_tokens will 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, and cache_read_input_tokens.

Parameters:

  • value (Anthropic::Beta::BetaUsage)

Returns:



168
# File 'lib/anthropic/models/beta/beta_message.rb', line 168

required :usage, -> { Anthropic::Beta::BetaUsage }

Instance Method Details

#output_formattop

Returns:

  • (top)


30
# File 'sig/anthropic/models/beta/beta_message.rbs', line 30

def output_format: -> top

#parsed_outputObject?

parsed value of response when a JSON output schema object has been specified via :output_format

Returns:

  • (Object, nil)


65
66
67
68
69
70
71
72
# File 'lib/anthropic/models/beta/beta_message.rb', line 65

def parsed_output
  case content
  in [*, {parsed:}]
    parsed
  else
    nil
  end
end

#to_hash{

Returns:

  • ({)


68
# File 'sig/anthropic/models/beta/beta_message.rbs', line 68

def to_hash: -> {