Configuration
Set provider credentials, choose default models, and give parts of your application their own settings.
After reading this guide, you will know:
- How to configure the providers you use.
- How to set default models for chats and individual operations.
- How to configure RubyLLM in a Rails initializer.
- How to give an agent or a tenant its own credentials with a context.
- Where to find every setting.
Configuring Providers
RubyLLM.configure sets your application’s credentials and defaults. Configure each provider you use with its API key:
RubyLLM.configure do |config|
config.openai_api_key = ENV.fetch("OPENAI_API_KEY")
config.anthropic_api_key = ENV.fetch("ANTHROPIC_API_KEY")
end
That’s all most applications need. RubyLLM chooses default models, timeouts, and retries, and you change only what your application needs.
Configure only the providers you use. RubyLLM doesn’t ask for the others, and raises RubyLLM::ConfigurationError when you use a provider without its required credentials. See Provider Setup for every provider’s settings, including regions, projects, Bedrock and Vertex AI authentication, and OpenAI-compatible endpoints.
To send a provider’s requests to a gateway or another endpoint, set its *_api_base setting to a base URL in the form Provider-Specific API Base URLs lists. RubyLLM uses it as given and raises RubyLLM::ConfigurationError when it includes an endpoint path.
Configuring RubyLLM in Rails
In Rails, the install generator writes config/initializers/ruby_llm.rb. Read keys from your credentials and send RubyLLM’s logs to the Rails log:
# config/initializers/ruby_llm.rb
RubyLLM.configure do |config|
config.openai_api_key = Rails.application.credentials.openai_api_key
config.anthropic_api_key = Rails.application.credentials.anthropic_api_key
config.default_model = "claude-sonnet-5"
config.logger = Rails.logger
end
See Rails Integration for persistence, attachments, streaming, and jobs.
Default Models
RubyLLM.chat and each individual operation use a default model when you don’t pass model:. Set the defaults your application needs:
RubyLLM.configure do |config|
config.default_model = "claude-sonnet-5" # RubyLLM.chat and agents
config.default_embedding_model = "text-embedding-3-large" # RubyLLM.embed
config.default_image_model = "gpt-image-2" # RubyLLM.paint
config.default_video_model = "grok-imagine-video-1.5" # RubyLLM.animate
config.default_speech_model = "gpt-4o-mini-tts-2025-12-15" # RubyLLM.speak
config.default_transcription_model = "gpt-transcribe" # RubyLLM.transcribe
config.default_ocr_model = "mistral-ocr-latest" # RubyLLM.ocr
config.default_moderation_model = "omni-moderation-latest" # RubyLLM.moderate
config.default_judgment_model = "jev-latest" # RubyLLM.judge
end
Without them, RubyLLM uses these models:
| Setting | Default |
|---|---|
default_model |
gpt-6.1-sol |
default_embedding_model |
text-embedding-3-small |
default_image_model |
gpt-image-2 |
default_video_model |
grok-imagine-video-1.5 |
default_speech_model |
gpt-4o-mini-tts-2025-12-15 |
default_transcription_model |
gpt-transcribe |
default_ocr_model |
mistral-ocr-latest |
default_moderation_model |
omni-moderation-latest |
default_judgment_model |
jev-latest |
rerank has no default: pass model: on each call.
Giving Part of Your Application Its Own Settings
Global configuration suits most of an application. Sometimes one part needs different settings: the support desk bills its model usage to a separate OpenAI project, or each store on your platform brings its own key. A context is a copy of the configuration with your changes, and it has the same entry points as RubyLLM:
store_ai = RubyLLM.context do |config|
config.openai_api_key = store.openai_api_key
config.request_timeout = 180
end
store_ai.chat.ask "Do you ship to Canada?"
store_ai.transcribe "voicemail.mp3"
An agent takes a context with the context macro, so every chat it builds uses it:
class SupportAgent < RubyLLM::Agent
context do |config|
config.openai_api_key = Rails.application.credentials.support_openai_api_key
end
end
See Contexts for multi-tenant applications and how contexts share connections.
Every Setting
The reference pages list every setting:
- Provider Setup and Custom Endpoints: each provider’s keys, endpoints, regions, and authentication.
- Connection, Logging and Contexts: timeouts, retries, proxies, logging, the model registry file, and every other setting in one block.
- The Configuration API reference documents each setting’s type and default.
Next Steps
- Rails Integration: the support desk on your own records and jobs.
- Provider Setup and Custom Endpoints: every provider’s settings.
- Model Registry: find models and refresh the registry.