Class: RubyLLM::Model::PricingTier
- Inherits:
-
Object
- Object
- RubyLLM::Model::PricingTier
- Defined in:
- lib/ruby_llm/model/pricing_tier.rb
Overview
A PricingTier holds the prices a model charges within one billing tier,
such as standard, batch, or long_context. Each price is in USD per one
million tokens. Prices missing from the registry read as nil. A zero
price means the usage is free.
Instances come from PricingCategory#standard, #batch, and #long_context:
model = RubyLLM.models.find "claude-sonnet-5"
tier = model.pricing.text_tokens.standard
tier.input_per_million # => 3
tier.output_per_million # => 15
Constant Summary collapse
- ATTRIBUTES =
The names of the price readers a tier responds to.
%i[ input_per_million output_per_million cache_read_input_per_million cache_write_input_per_million reasoning_output_per_million ].freeze
Instance Method Summary collapse
-
#attribute ⇒ Object
:method: reasoning_output_per_million.
-
#initialize(data = {}) ⇒ PricingTier
constructor
:nodoc:.
-
#to_h ⇒ Object
Returns a new Hash of the tier's prices with Symbol keys.
Constructor Details
#initialize(data = {}) ⇒ PricingTier
:nodoc:
27 28 29 30 31 32 33 34 35 |
# File 'lib/ruby_llm/model/pricing_tier.rb', line 27 def initialize(data = {}) # :nodoc: @values = {} data.each do |key, value| next if value.nil? @values[key.to_sym] = value end end |
Instance Method Details
#attribute ⇒ Object
:method: reasoning_output_per_million
Returns the USD price per million reasoning output tokens, or nil
if the price is missing.
67 68 69 70 71 |
# File 'lib/ruby_llm/model/pricing_tier.rb', line 67 ATTRIBUTES.each do |attribute| define_method(attribute) do @values[attribute] end end |
#to_h ⇒ Object
Returns a new Hash of the tier's prices with Symbol keys. Missing prices are omitted.
tier.to_h
# => {input_per_million: 3, output_per_million: 15, ...}
79 80 81 |
# File 'lib/ruby_llm/model/pricing_tier.rb', line 79 def to_h @values.dup end |