Class: Anthropic::Models::Beta::BetaMessageDeltaUsage

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

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

#initialize ⇒ BetaMessageDeltaUsage

Returns a new instance of BetaMessageDeltaUsage.

Parameters:

  • cache_creation_input_tokens: (Integer, nil)
  • cache_read_input_tokens: (Integer, nil)
  • fallback_credit: (Anthropic::Beta::BetaFallbackCreditUsage, nil)
  • input_tokens: (Integer, nil)
  • iterations: (Anthropic::Models::Beta::beta_iterations_usage, nil)
  • output_tokens: (Integer)
  • output_tokens_details: (Anthropic::Beta::BetaOutputTokensDetails, nil)
  • server_tool_use: (Anthropic::Beta::BetaServerToolUsage, nil)


35
36
37
38
39
40
41
42
43
44
# File 'sig/anthropic/models/beta/beta_message_delta_usage.rbs', line 35

def initialize: (
  cache_creation_input_tokens: Integer?,
  cache_read_input_tokens: Integer?,
  fallback_credit: Anthropic::Beta::BetaFallbackCreditUsage?,
  input_tokens: Integer?,
  iterations: Anthropic::Models::Beta::beta_iterations_usage?,
  output_tokens: Integer,
  output_tokens_details: Anthropic::Beta::BetaOutputTokensDetails?,
  server_tool_use: Anthropic::Beta::BetaServerToolUsage?
) -> void

Instance Attribute Details

#cache_creation_input_tokens ⇒ Integer?

The cumulative number of input tokens used to create the cache entry.

Parameters:

  • value (Integer, nil)

Returns:

  • (Integer, nil)


11
# File 'lib/anthropic/models/beta/beta_message_delta_usage.rb', line 11

required :cache_creation_input_tokens, Integer, nil?: true

#cache_read_input_tokens ⇒ Integer?

The cumulative number of input tokens read from the cache.

Parameters:

  • value (Integer, nil)

Returns:

  • (Integer, nil)


17
# File 'lib/anthropic/models/beta/beta_message_delta_usage.rb', line 17

required :cache_read_input_tokens, Integer, nil?: true

#fallback_credit ⇒ Anthropic::Models::Beta::BetaFallbackCreditUsage?

Outcome of the fallback_credit_token presented on this request.

Present on every response to a non-batch request that carried a fallback_credit_token, in either redemption mode; absent otherwise (batch items accept and ignore the token and carry no outcome object).

Parameters:

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

Returns:



27
# File 'lib/anthropic/models/beta/beta_message_delta_usage.rb', line 27

required :fallback_credit, -> { Anthropic::Beta::BetaFallbackCreditUsage }, nil?: true

#input_tokens ⇒ Integer?

The cumulative number of input tokens which were used.

Parameters:

  • value (Integer, nil)

Returns:

  • (Integer, nil)


33
# File 'lib/anthropic/models/beta/beta_message_delta_usage.rb', line 33

required :input_tokens, Integer, nil?: true

#iterations ⇒ Array<Anthropic::Models::Beta::BetaMessageIterationUsage, Anthropic::Models::Beta::BetaCompactionIterationUsage, Anthropic::Models::Beta::BetaAdvisorMessageIterationUsage, Anthropic::Models::Beta::BetaFallbackMessageIterationUsage>?

Per-iteration token usage breakdown.

Each entry represents one sampling iteration, with its own input/output token counts and cache statistics, discriminated by type. For message entries (model sampling iterations, such as the turns of a server-side tool use loop), this allows you to:

  • Calculate the context window size from the last message entry
  • Understand token accumulation across server-side tool use loops

A compaction entry reports the token usage of the compaction operation itself — the server-side request that summarizes the context being closed — NOT the size of the context that was compacted away, and its token counts can be much smaller than that closed context (for example, a compaction that closes a ~200k-token context can report only a few thousand tokens). Do not derive the context window size from a compaction entry, even when it is the last entry. A compaction entry's tokens are not included in the top-level usage fields. When an input-token trigger is in effect (the default — 150,000 tokens unless configured otherwise), each compaction entry closes a context that had reached at least that threshold, though the context can exceed it by the final iteration's output and tool results.



59
60
61
# File 'lib/anthropic/models/beta/beta_message_delta_usage.rb', line 59

required :iterations,
-> { Anthropic::Internal::Type::ArrayOf[union: Anthropic::Beta::BetaIterationsUsageItem] },
nil?: true

#output_tokens ⇒ Integer

The cumulative number of output tokens which were used.

Parameters:

  • value (Integer)

Returns:

  • (Integer)


67
# File 'lib/anthropic/models/beta/beta_message_delta_usage.rb', line 67

required :output_tokens, Integer

#output_tokens_details ⇒ Anthropic::Models::Beta::BetaOutputTokensDetails?

Breakdown of output tokens by category.

output_tokens remains the inclusive, authoritative total used for billing. This object provides a read-only decomposition for observability — for example, how many of the billed output tokens were spent on internal reasoning that may have been summarized before being returned to you.

Parameters:

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

Returns:



78
# File 'lib/anthropic/models/beta/beta_message_delta_usage.rb', line 78

required :output_tokens_details, -> { Anthropic::Beta::BetaOutputTokensDetails }, nil?: true

#server_tool_use ⇒ Anthropic::Models::Beta::BetaServerToolUsage?

The number of server tool requests.

Parameters:

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

Returns:



84
# File 'lib/anthropic/models/beta/beta_message_delta_usage.rb', line 84

required :server_tool_use, -> { Anthropic::Beta::BetaServerToolUsage }, nil?: true

Instance Method Details

#to_hash ⇒ { cache_creation_input_tokens: Integer?, cache_read_input_tokens: Integer?, fallback_credit: Anthropic::Beta::BetaFallbackCreditUsage?, input_tokens: Integer?, iterations: Anthropic::Models::Beta::beta_iterations_usage?, output_tokens: Integer, output_tokens_details: Anthropic::Beta::BetaOutputTokensDetails?, server_tool_use: Anthropic::Beta::BetaServerToolUsage? }

Returns:

  • ({ cache_creation_input_tokens: Integer?, cache_read_input_tokens: Integer?, fallback_credit: Anthropic::Beta::BetaFallbackCreditUsage?, input_tokens: Integer?, iterations: Anthropic::Models::Beta::beta_iterations_usage?, output_tokens: Integer, output_tokens_details: Anthropic::Beta::BetaOutputTokensDetails?, server_tool_use: Anthropic::Beta::BetaServerToolUsage? })


46
47
48
49
50
51
52
53
54
55
# File 'sig/anthropic/models/beta/beta_message_delta_usage.rbs', line 46

def to_hash: -> {
  cache_creation_input_tokens: Integer?,
  cache_read_input_tokens: Integer?,
  fallback_credit: Anthropic::Beta::BetaFallbackCreditUsage?,
  input_tokens: Integer?,
  iterations: Anthropic::Models::Beta::beta_iterations_usage?,
  output_tokens: Integer,
  output_tokens_details: Anthropic::Beta::BetaOutputTokensDetails?,
  server_tool_use: Anthropic::Beta::BetaServerToolUsage?
}