Exploring the Model Registry
RubyLLM ships with a built-in registry of 600+ models across all supported providers. The registry is bundled with the gem — no API calls or keys needed to browse it.
The Registry API
RubyLLM.models.all # every modelRubyLLM.models.chat_models # chat/completion modelsRubyLLM.models.embedding_models # embedding modelsRubyLLM.models.by_provider(:openai) # filter by providerRubyLLM.models.find("claude-sonnet-4-6") # find specific modelYour Task
Open explore_models.rb and write code to:
- Print the total number of models in the registry
- List all providers (unique, sorted)
- Print the first 10 chat models with their id, provider, and context window
- Find a specific model and display its details
# 1. Total modelsputs "Total models: #{RubyLLM.models.all.count}"
# 2. Providersproviders = RubyLLM.models.all.map(&:provider).uniq.sortputs "Providers: #{providers.join(', ')}"
# 3. First 10 chat modelsRubyLLM.models.chat_models.first(10).each do |model| puts " %-30s %-12s %s tokens" % [model.id, model.provider, model.context_window]end
# 4. Specific model detailsmodel = RubyLLM.models.find("gpt-4o")puts " Context window: #{model.context_window} tokens"puts " Vision: #{model.supports_vision?}"Run it:
$ ruby explore_models.rbThis works without any API keys — the data is bundled in the gem.
Model Properties
Each model exposes rich metadata:
| Property | Description |
|---|---|
.id | Model identifier (e.g., "claude-sonnet-4-6") |
.provider | Provider name (e.g., "anthropic") |
.context_window | Max tokens the model can process |
.supports_vision? | Can it analyze images? |
.supports_json_mode? | Structured JSON output support? |
.input_price_per_million | Cost per million input tokens |
.output_price_per_million | Cost per million output tokens |
Filtering with Enumerable
Since the registry returns arrays, you can chain Ruby’s Enumerable methods:
# Find all OpenAI models with vision supportRubyLLM.models.by_provider(:openai).select(&:supports_vision?)
# Find the cheapest chat modelRubyLLM.models.chat_models.min_by(&:input_price_per_million)
# Group models by providerRubyLLM.models.all.group_by(&:provider).transform_values(&:count)
# Filter by model familyRubyLLM.models.by_family("claude3_sonnet")Custom Endpoints & Unlisted Models
Some deployments use custom API endpoints (Azure OpenAI, local Ollama, etc.) or models not yet in the registry. Use assume_model_exists: true to bypass registry validation:
# Azure OpenAI endpointRubyLLM.configure do |config| config.openai_api_base = "https://YOUR_RESOURCE.openai.azure.com" config.openai_api_key = ENV["AZURE_OPENAI_KEY"]end
chat = RubyLLM.chat( model: "my-gpt4-deployment", provider: :openai, assume_model_exists: true)The provider: keyword is required when assuming existence — it tells RubyLLM which API format to use.
Keeping the Registry Fresh
The bundled registry is a snapshot. To pull the latest models from all configured providers:
RubyLLM.models.refresh! # update in memoryRubyLLM.models.save_to_json # persist to diskIn a Rails app, run this after initial setup. The rake models:update task is for gem maintainers only — use refresh! in application code.
- Preparing Ruby runtime