Class: Llmshim::Usage

Inherits:
Struct
  • Object
show all
Defined in:
lib/llmshim/types.rb

Overview

Token accounting returned with a chat response or a usage stream event.

Mirrors the Usage schema in api/openapi.yaml.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#input_tokensObject

Returns the value of attribute input_tokens

Returns:

  • (Object)

    the current value of input_tokens



7
8
9
# File 'lib/llmshim/types.rb', line 7

def input_tokens
  @input_tokens
end

#output_tokensObject

Returns the value of attribute output_tokens

Returns:

  • (Object)

    the current value of output_tokens



7
8
9
# File 'lib/llmshim/types.rb', line 7

def output_tokens
  @output_tokens
end

#reasoning_tokensObject

Returns the value of attribute reasoning_tokens

Returns:

  • (Object)

    the current value of reasoning_tokens



7
8
9
# File 'lib/llmshim/types.rb', line 7

def reasoning_tokens
  @reasoning_tokens
end

#total_tokensObject

Returns the value of attribute total_tokens

Returns:

  • (Object)

    the current value of total_tokens



7
8
9
# File 'lib/llmshim/types.rb', line 7

def total_tokens
  @total_tokens
end

Class Method Details

.from_hash(hash) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/llmshim/types.rb', line 11

def self.from_hash(hash)
  return nil if hash.nil?

  new(
    input_tokens: hash["input_tokens"],
    output_tokens: hash["output_tokens"],
    reasoning_tokens: hash["reasoning_tokens"],
    total_tokens: hash["total_tokens"]
  )
end