class LittleGhost::Usage
Usage makes token accounting consistent across model providers. It keeps input, output, cache, and reasoning counts separate so applications can aggregate them without double-counting.
Providers report uncached input, visible output, cache reads, cache writes, and reasoning separately. Invalid or negative values normalize to zero.
Public Class Methods
# File lib/little_ghost/usage.rb, line 16 def initialize(input_tokens: 0, output_tokens: 0, cache_read_tokens: 0, cache_write_tokens: 0, reasoning_tokens: 0) @input_tokens = integer(input_tokens) @output_tokens = integer(output_tokens) @cache_read_tokens = integer(cache_read_tokens) @cache_write_tokens = integer(cache_write_tokens) @reasoning_tokens = integer(reasoning_tokens) end
Normalizes provider token counts; invalid or negative values become zero.
Public Instance Methods
Source
# File lib/little_ghost/usage.rb, line 30 def +(other) self.class.new(**FIELDS.to_h { |field| [field, public_send(field) + other.public_send(field)] }) end
Adds two usage values field by field.
Source
# File lib/little_ghost/usage.rb, line 35 def to_h FIELDS.to_h { |field| [field, public_send(field)] }.merge(total_tokens: total_tokens) end
Exposes every field and total_tokens as a hash.
Source
# File lib/little_ghost/usage.rb, line 25 def total_tokens FIELDS.sum { |field| public_send(field) } end
Sums every normalized token field.