class RubyLLM::Model::PricingCategory
A PricingCategory holds the standard, batch, and long-context pricing tiers for one kind of model usage, such as text tokens or images. Model#pricing returns a Pricing collection whose categories are PricingCategory instances. Prices are in USD per million tokens.
model = RubyLLM.models.find "claude-sonnet-5" category = model.pricing.text_tokens category.input # => 3 category.output # => 15
Constants
- TIERS
-
The billing tiers a category may define.
Attributes
The batch-tier PricingTier, or nil when the model has no batch pricing for this category.
The long-context PricingTier, or nil when the model has no separate rates for prompts above long_context_threshold.
Prompt-size threshold (in tokens) above which long-context rates apply, or nil when the model has no long-context tier.
The standard-tier PricingTier, or nil when the model has no standard pricing for this category.
Public Instance Methods
Source
# File lib/ruby_llm/model/pricing_category.rb, line 58 def cache_read_input standard&.cache_read_input_per_million end
Returns the standard-tier cache read price in USD per million tokens, or nil if the price is missing.
Source
# File lib/ruby_llm/model/pricing_category.rb, line 64 def cache_write_input standard&.cache_write_input_per_million end
Returns the standard-tier cache write price in USD per million tokens, or nil if the price is missing.
Source
# File lib/ruby_llm/model/pricing_category.rb, line 46 def input standard&.input_per_million end
Returns the standard-tier input price in USD per million tokens, or nil if the price is missing.
Source
# File lib/ruby_llm/model/pricing_category.rb, line 52 def output standard&.output_per_million end
Returns the standard-tier output price in USD per million tokens, or nil if the price is missing.
Source
# File lib/ruby_llm/model/pricing_category.rb, line 70 def reasoning_output standard&.reasoning_output_per_million end
Returns the standard-tier reasoning output price in USD per million tokens, or nil if the price is missing.
Source
# File lib/ruby_llm/model/pricing_category.rb, line 77 def tier_for(prompt_tokens) if long_context && long_context_threshold && prompt_tokens.to_i > long_context_threshold long_context else standard end end
Returns the PricingTier that applies for a prompt of the given size. Uses long_context when that tier exists and prompt_tokens is greater than long_context_threshold; otherwise returns standard.
Source
# File lib/ruby_llm/model/pricing_category.rb, line 88 def to_h result = {} result[:standard] = standard.to_h if standard result[:batch] = batch.to_h if batch result[:long_context] = long_context.to_h if long_context result[:long_context_threshold] = long_context_threshold if long_context_threshold result end
Returns a Hash with present tier hashes and optional :long_context_threshold, omitting absent entries.