class RubyLLM::Tokens
Represents token usage for a response.
Attributes
Public Class Methods
Source
# File lib/ruby_llm/tokens.rb, line 19 def self.build(input: nil, output: nil, cached: nil, cache_creation: nil, thinking: nil, reasoning: nil) return nil if [input, output, cached, cache_creation, thinking, reasoning].all?(&:nil?) new( input: input, output: output, cached: cached, cache_creation: cache_creation, thinking: thinking, reasoning: reasoning ) end
rubocop:disable Metrics/ParameterLists
Source
# File lib/ruby_llm/tokens.rb, line 9 def initialize(input: nil, output: nil, cached: nil, cache_creation: nil, thinking: nil, reasoning: nil) @input = input @output = output @cached = cached @cache_creation = cache_creation @thinking = thinking || reasoning end
rubocop:disable Metrics/ParameterLists
Public Instance Methods
Source
# File lib/ruby_llm/tokens.rb, line 33 def to_h { input_tokens: input, output_tokens: output, cached_tokens: cached, cache_creation_tokens: cache_creation, thinking_tokens: thinking }.compact end
rubocop:enable Metrics/ParameterLists