Class: RubyLLM::Model::Pricing
- Inherits:
-
Object
- Object
- RubyLLM::Model::Pricing
- Defined in:
- lib/ruby_llm/model/pricing.rb
Overview
A Pricing groups a model's prices by usage category: text tokens, images, audio tokens, and embeddings. Each category is a PricingCategory. Prices are in USD per million tokens. Instances come from Model#pricing.
model = RubyLLM.models.find "claude-sonnet-5"
model.pricing.text_tokens.input # => 3
model.pricing.text_tokens.output # => 15
Constant Summary collapse
- CATEGORIES =
The pricing categories a model may define.
%i[text_tokens images audio_tokens embeddings].freeze
Instance Method Summary collapse
-
#audio_tokens ⇒ Object
Returns the PricingCategory for audio token prices, or an empty category if the model has none.
-
#embeddings ⇒ Object
Returns the PricingCategory for embedding prices, or an empty category if the model has none.
-
#images ⇒ Object
Returns the PricingCategory for image generation prices, or an empty category if the model has none.
-
#initialize(data) ⇒ Pricing
constructor
:nodoc:.
-
#text_tokens ⇒ Object
Returns the PricingCategory for text token prices, or an empty category if the model has none.
-
#to_h ⇒ Object
Returns the pricing data as a nested Hash keyed by category.
Constructor Details
#initialize(data) ⇒ Pricing
:nodoc:
18 19 20 21 22 23 24 |
# File 'lib/ruby_llm/model/pricing.rb', line 18 def initialize(data) # :nodoc: @data = {} CATEGORIES.each do |category| @data[category] = PricingCategory.new(data[category]) if data[category] && !empty_pricing?(data[category]) end end |
Instance Method Details
#audio_tokens ⇒ Object
Returns the PricingCategory for audio token prices, or an empty category if the model has none.
40 41 42 |
# File 'lib/ruby_llm/model/pricing.rb', line 40 def audio_tokens category(:audio_tokens) end |
#embeddings ⇒ Object
Returns the PricingCategory for embedding prices, or an empty category if the model has none.
46 47 48 |
# File 'lib/ruby_llm/model/pricing.rb', line 46 def category(:embeddings) end |
#images ⇒ Object
Returns the PricingCategory for image generation prices, or an empty category if the model has none.
34 35 36 |
# File 'lib/ruby_llm/model/pricing.rb', line 34 def images category(:images) end |
#text_tokens ⇒ Object
Returns the PricingCategory for text token prices, or an empty category if the model has none.
28 29 30 |
# File 'lib/ruby_llm/model/pricing.rb', line 28 def text_tokens category(:text_tokens) end |
#to_h ⇒ Object
Returns the pricing data as a nested Hash keyed by category. Categories without prices are omitted.
52 53 54 |
# File 'lib/ruby_llm/model/pricing.rb', line 52 def to_h @data.transform_values(&:to_h) end |