struct

Anthropic::TokenCountResponse

Inherits JSON::Serializable < Struct < Value < Object

Response from the token counting API

count = client.messages.count_tokens(
  model: Anthropic::Model::CLAUDE_SONNET_4_6,
  messages: [{role: "user", content: "Hello, Claude!"}]
)
puts "This message would use #{count.input_tokens} input tokens"

Constructors

new(input_tokens : Int32, cache_creation_input_tokens : Int32 | Nil = nil, cache_read_input_tokens : Int32 | Nil = nil)
Source
new(*, __pull_for_json_serializable pull : JSON::PullParser)
Source

Instance methods

cache_creation_input_tokens

Number of tokens that would be written to cache (if using prompt caching)

Source
cache_read_input_tokens

Number of tokens that would be read from cache (if using prompt caching)

Source
input_tokens

Number of input tokens the request would consume

Source
total_billable_tokens

Total billable tokens (considering cache pricing)

Source