Class: Legion::LLM::Usage
- Inherits:
-
Data
- Object
- Data
- Legion::LLM::Usage
- Defined in:
- lib/legion/llm/metering/usage.rb
Overview
Immutable value object representing token usage for a provider response.
input_tokens - Integer tokens consumed by the prompt output_tokens - Integer tokens in the generated response cache_read_tokens - Integer tokens served from prompt cache (e.g. Anthropic cache_read) cache_write_tokens - Integer tokens written to prompt cache total_tokens - Integer total; auto-calculated as input + output when not provided output_tokens_details - Optional breakdown (e.g. { reasoning_tokens: 48 }) from Responses API
Instance Attribute Summary collapse
-
#cache_read_tokens ⇒ Object
readonly
Returns the value of attribute cache_read_tokens.
-
#cache_write_tokens ⇒ Object
readonly
Returns the value of attribute cache_write_tokens.
-
#input_tokens ⇒ Object
readonly
Returns the value of attribute input_tokens.
-
#output_tokens ⇒ Object
readonly
Returns the value of attribute output_tokens.
-
#output_tokens_details ⇒ Object
readonly
Returns the value of attribute output_tokens_details.
-
#total_tokens ⇒ Object
readonly
Returns the value of attribute total_tokens.
Instance Method Summary collapse
-
#initialize(input_tokens: 0, output_tokens: 0, cache_read_tokens: 0, cache_write_tokens: 0, total_tokens: nil, output_tokens_details: {}) ⇒ Usage
constructor
A new instance of Usage.
Constructor Details
#initialize(input_tokens: 0, output_tokens: 0, cache_read_tokens: 0, cache_write_tokens: 0, total_tokens: nil, output_tokens_details: {}) ⇒ Usage
Returns a new instance of Usage.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/legion/llm/metering/usage.rb', line 21 def initialize(input_tokens: 0, output_tokens: 0, cache_read_tokens: 0, cache_write_tokens: 0, total_tokens: nil, output_tokens_details: {}) super( input_tokens:, output_tokens:, cache_read_tokens:, cache_write_tokens:, total_tokens: total_tokens || (input_tokens + output_tokens), output_tokens_details: output_tokens_details ) end |
Instance Attribute Details
#cache_read_tokens ⇒ Object (readonly)
Returns the value of attribute cache_read_tokens
13 14 15 |
# File 'lib/legion/llm/metering/usage.rb', line 13 def cache_read_tokens @cache_read_tokens end |
#cache_write_tokens ⇒ Object (readonly)
Returns the value of attribute cache_write_tokens
13 14 15 |
# File 'lib/legion/llm/metering/usage.rb', line 13 def cache_write_tokens @cache_write_tokens end |
#input_tokens ⇒ Object (readonly)
Returns the value of attribute input_tokens
13 14 15 |
# File 'lib/legion/llm/metering/usage.rb', line 13 def input_tokens @input_tokens end |
#output_tokens ⇒ Object (readonly)
Returns the value of attribute output_tokens
13 14 15 |
# File 'lib/legion/llm/metering/usage.rb', line 13 def output_tokens @output_tokens end |
#output_tokens_details ⇒ Object (readonly)
Returns the value of attribute output_tokens_details
13 14 15 |
# File 'lib/legion/llm/metering/usage.rb', line 13 def output_tokens_details @output_tokens_details end |
#total_tokens ⇒ Object (readonly)
Returns the value of attribute total_tokens
13 14 15 |
# File 'lib/legion/llm/metering/usage.rb', line 13 def total_tokens @total_tokens end |