One delightful Ruby framework for every major AI provider. Build AI agents, chatbots, RAG apps, and multimodal workflows in beautiful, expressive code.
Keine Überschriften im README
The Ruby AI framework
Build AI features the Ruby way: models, tools, agents, evaluations, and Rails conventions, designed together, with one consistent API.
chat = RubyLLM.chat
chat.ask "What's the best way to learn Ruby?"
chat.ask "What's in this image?", with: "ruby_conf.jpg"
chat.with_model("claude-sonnet-5").ask "Now say it as a haiku"
RubyLLM.paint("a sunset over mountains in watercolor").save("sunset.png")
More than a client for model APIs. RubyLLM gives your application the conventions, the runtime, and every piece in between, designed to work together. Everything below ships in RubyLLM 2.1.
Keep questions and expected answers in a dataset. RubyLLM checks correctness by default. Run the same evaluation from Ruby, RSpec, Minitest, or Rake.
app/agents/support_agent.rb
class SupportAgent < RubyLLM::Agent
instructions "Accept returns of unopened items within 30 days."
end
app/evals/support_evaluation.rb
class SupportEvaluation < RubyLLM::Evaluation
def perform(input)
SupportAgent.new.ask(input)
end
end
app/evals/support_evaluation.yml
cases:-name: within_return_window
inputs: Can I return an unopened item after 14 days?
expected_output: Yes, unopened items can be returned within 30 days.
-name: past_return_window
inputs: Can I return an unopened item after 45 days?
expected_output: No, the 30-day return window has passed.
The model evaluator checks meaning, so answers can use different wording. Declare your own criteria, add Ruby assertions, or choose a configured evaluator agent or judgment model. Read the evaluation guides.
class Chat < ApplicationRecord
acts_as_chat
end
chat = Chat.create! model: "gpt-6-luna"
chat.ask "What's in this file?", with: "report.pdf"
Start your Rails server and visit http://localhost:3000/chats to try the chat interface. See the Rails guide for persistence, streaming, and background jobs.
#Start with one line. Add files, tools, and agents
These examples use 2.1.1. Follow Getting Started to install it and configure the providers you want to try. For 1.x, use the 1.x docs.
# Just ask
RubyLLM.chat.ask "What's the best way to learn Ruby?"
# Ask about files with a model that supports their input types
chat = RubyLLM.chat(model: "gemini-3.7-flash")
chat.ask "What's in this image?", with: "ruby_conf.jpg"
chat.ask "What's happening in this video?", with: "video.mp4"
chat.ask "Describe this meeting", with: "meeting.wav"
chat.ask "Summarize this document", with: "contract.pdf"
chat.ask "Explain this code", with: "app.rb"
# Multiple files at once
chat.ask "Analyze these files", with: ["diagram.png", "report.pdf", "notes.txt"]
# Stream responses
chat.ask "Tell me a story about Ruby" do |chunk|
print chunk.content
end
# Generate images
image = RubyLLM.paint "a sunset over mountains in watercolor style"
image.save "sunset.png"
# Generate videos
video = RubyLLM.animate "a paper boat sailing down a rainy gutter"
video.save "paper_boat.mp4"
# Create embeddings
embedding = RubyLLM.embed "Ruby is elegant and expressive"
embedding.vector
# Rank search results
documents = ["Reset your password in Settings.", "Invoices arrive by email."]
ranked = RubyLLM.rerank("How do I reset my password?", documents, model: "rerank-v3.5")
ranked.results.first.document
# Transcribe audio to text
transcript = RubyLLM.transcribe "meeting.wav"
puts transcript.text
# Turn text into speech
speech = RubyLLM.speak "Hello, welcome to RubyLLM!"
speech.save "welcome.mp3"
# Extract document text as markdown
document = RubyLLM.ocr "contract.pdf"
puts document.markdown
# Check whether a moderation model flags content
RubyLLM.moderate("Some user-generated content").flagged?
# Ask a typed question about your data
class Urgency < RubyLLM::Judge
probability :urgent, "Does this need attention today?"
end
Urgency.judge("Please refund my duplicate charge today.").urgent.probability
# Let AI use your code
class Weather < RubyLLM::Tool
description "Get current weather"
def execute(latitude:, longitude:)
url = "https://api.open-meteo.com/v1/forecast?latitude=#{latitude}&longitude=#{longitude}¤t=temperature_2m,wind_speed_10m"
JSON.parse(Faraday.get(url).body)
end
end
chat.with_tools(Weather).ask "What's the weather in Berlin?"
# Define an agent with instructions + tools
class WeatherAssistant < RubyLLM::Agent
model "gpt-6-luna"
instructions "Be concise and always use tools for weather."
tools Weather
end
WeatherAssistant.new.ask "What's the weather in Berlin?"
# Get structured output
class ProductSchema < Schematist::Schema
string :name
number :price
array :features do
string
end
end
response = chat.with_schema(ProductSchema).ask "Analyze this product", with: "product.txt"
response.parsed
Configure a provider in your script, or in config/initializers/ruby_llm.rb in Rails:
require 'ruby_llm'
RubyLLM.configure do |config|
config.openai_api_key = ENV.fetch('OPENAI_API_KEY')
end
Configure the other providers used by the examples as needed: Gemini for files, xAI for video, Mistral for OCR, and Cohere for reranking. Getting Started shows each setup beside its example. Upgrading an existing app? Follow the upgrade guide.
Give your coding assistant the RubyLLM API and documentation that match your application. From your application directory, install the skill packaged with your gem:
gem exec skill add "$(bundle show ruby_llm)"--skill rubyllm --agents coding
--agents coding installs it for the coding assistants your project uses, not into your app's app/skills. In Claude Code, you can also install it as a plugin:
Extracted system prompts from Anthropic - Claude Fable 5.1, Opus 5, Claude Design, Claude Code. OpenAI - ChatGPT GPT-6-Astra, Codex. Google - Gemini 3.8 Flash, 3.1 Pro, Antigravity. xAI - Grok, Grok Bot, Cursor, Kimi and more! Updated regularly.