class RubyLLM::Model
A Model describes one entry in the model registry: the model’s identity, capabilities, modalities, pricing, and provider metadata. Instances come from the registry through RubyLLM.models and from Chat#model.
model = RubyLLM.models.find('gpt-6.1-sol') model.name # => "GPT-5.6" model.provider # => "openai" model.context_window # => 1050000 model.supports?(:vision) # => true
Attributes
The model’s capability names as an array of Strings, e.g. ["function_calling", "streaming"].
The maximum number of input tokens the model accepts, or nil.
The model’s release timestamp as a UTC Time, or nil.
The model family as a String, e.g. "gpt", or nil.
The provider’s identifier for the model, e.g. "gpt-6.1-sol".
The model’s training data cutoff as a Date, or nil.
The maximum number of tokens the model can generate, or nil.
Provider-specific metadata as a Hash.
The supported input and output modalities as a Model::Modalities object.
model.modalities.input # => ["text", "image", "pdf"] model.modalities.output # => ["text"]
The human-readable model name, e.g. "GPT-5.6".
The provider slug as a String, e.g. "openai".
The time the configured provider stopped listing the model, as a UTC Time, or nil while the provider still lists it. Only a store that keeps unlisted entries, such as the Rails model table, sets it.
Public Instance Methods
# File lib/ruby_llm/model.rb, line 190 def cost_for(tokens, tier: :standard) requests = usage_entries_of(tokens) if requests.any? complete = requests.all? { |entry| entry.usage_available? || entry.tokens.reported_cost } return Cost.aggregate(requests.map { |entry| cost_for(entry.tokens, tier:) }, complete:) end tokens = tokens.tokens if tokens.respond_to?(:tokens) Cost.new(tokens:, model: self, tier:) end
Builds a Cost for tokens (a Tokens object, or anything responding to tokens) using this model’s pricing. A Chat or Message is priced one provider request at a time, so each request pays the context tier its own prompt reached.
cost = model.cost_for(response.tokens) puts cost.total
Pass tier: :batch to use the model’s explicit batch rates. Amounts the model has no batch price for are nil.
Source
# File lib/ruby_llm/model.rb, line 142 def label provider_name = provider_class&.display_name || provider "#{provider_name} - #{name}" end
Returns the provider display name and model name combined, e.g. "OpenAI - GPT-5.6".
Source
# File lib/ruby_llm/model.rb, line 172 def price(kind) column = PRICES.fetch(kind) do raise ArgumentError, "Unknown price kind: #{kind.inspect}. Valid kinds: #{PRICES.keys.join(', ')}" end pricing.text_tokens.public_send(column) end
Returns the standard text-token price for kind in USD per million tokens, or nil if the registry has no such price. Valid kinds are :input, :output, :cache_read, and :cache_write.
model.price(:input) # => 2.5 model.price(:output) # => 10.0
Source
# File lib/ruby_llm/model.rb, line 55 def pricing config = RubyLLM.config revision = config.revision prices = config.prices return @pricing if prices.empty? priced = @priced return priced.last if priced && priced[0].equal?(config) && priced[1] == revision override = configured_prices(prices) pricing = override.empty? ? @pricing : Pricing.new(Pricing.overridden(@pricing_data, override)) @priced = [config, revision, pricing].freeze pricing end
The model’s pricing as a Model::Pricing object, in USD per million tokens: the registry’s prices, with the ones set through Configuration#price in their place.
Source
# File lib/ruby_llm/model.rb, line 203 def provider_class RubyLLM::Provider.resolve provider end
Returns the Provider class registered for this model’s provider slug, or nil if no such provider is registered.
Source
# File lib/ruby_llm/model.rb, line 126 def supports?(capability) capabilities.include?(capability.to_s) end
Returns whether capabilities includes capability, given as a String or Symbol.
model.supports?(:function_calling) # => true
Source
# File lib/ruby_llm/model.rb, line 210 def type output = modalities.output return :embedding if output.include?('embeddings') return :moderation if output.include?('moderation') return :image if output.include?('image') return :audio if output.include?('audio') return :video if output.include?('video') return :rerank if output.include?('rerank') return :judgment if output.include?('judgment') :chat end
Returns the model’s primary function, inferred from its output modalities: :chat, :embedding, :moderation, :image, :audio, :video, :rerank, or :judgment.
Source
# File lib/ruby_llm/model.rb, line 136 def unlisted? !unlisted_at.nil? end
Returns whether the configured provider has stopped listing the model. An unlisted model is kept only because application records still reference it, and it may already be failing at the provider.
model.unlisted? # => false