Installation & Configuration
RubyLLM is a Ruby gem that gives you a single, elegant interface to work with multiple AI providers — OpenAI, Anthropic, Google Gemini, and more. Instead of learning a different SDK for each provider, you learn one API and swap models freely.
Installing the Gem
In any Ruby project, add RubyLLM to your Gemfile:
gem "ruby_llm"Then run bundle install. That’s it — no provider-specific gems needed.
Configuration
Open setup.rb in the editor. RubyLLM needs API keys to talk to providers. Complete the configure block:
RubyLLM.configure do |config| # Add your API key configuration here config.openai_api_key = ENV.fetch("OPENAI_API_KEY", nil) config.anthropic_api_key = ENV.fetch("ANTHROPIC_API_KEY", nil) config.gemini_api_key = ENV.fetch("GEMINI_API_KEY", nil)endYou only need keys for providers you plan to use:
| Provider | Config key | Models |
|---|---|---|
| OpenAI | config.openai_api_key | GPT-4o, o1, DALL-E |
| Anthropic | config.anthropic_api_key | Claude Sonnet, Opus, Haiku |
config.gemini_api_key | Gemini Pro, Flash |
Run the script to verify:
$ ruby setup.rbWhat Makes RubyLLM Different?
- One interface, many providers — switch from GPT to Claude by changing a model name
- Conversation history is automatic — no manual message array management
- Tools are just Ruby classes — no JSON schema boilerplate
- Streaming, embeddings, and image generation — all built in
Files
Preparing Environment
- Preparing Ruby runtime