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-5.4') model.name # => "GPT-5.4" 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-5.4".
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.4".
The model’s pricing as a Model::Pricing object, in USD per million tokens.
The provider slug as a String, e.g. "openai".
Public Instance Methods
Source
# File lib/ruby_llm/model.rb, line 140 def cost_for(tokens) tokens = tokens.tokens if tokens.respond_to?(:tokens) Cost.new(tokens:, model: self) end
Source
# File lib/ruby_llm/model.rb, line 97 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.4".
Source
# File lib/ruby_llm/model.rb, line 127 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 148 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 91 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 155 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') 'chat' end
Returns the model’s primary function, inferred from its output modalities: "chat", "embedding", "moderation", "image", "audio", or "video".