The Ruby AI framework
open sourceMITself-hostablefree
RubyLLM is a Ruby library and framework for building AI features with one API across 23 providers, including OpenAI, Anthropic, Gemini, Bedrock, OpenRouter, Ollama and any OpenAI-compatible endpoint. RubyLLM.chat handles conversations with streaming through a block, attachments (images, audio, video, PDFs), structured output from a Ruby schema (with_schema, read back with response.parsed), tools that call your Ruby methods, agents, prompt caching and fallbacks; separate calls generate images, video, speech, embeddings and rerankings. In Rails it saves chats with Active Record (acts_as_chat), streams replies with Hotwire and has generators for a chat UI. It also has evaluations, cost tracking, OpenTelemetry tracing and a model registry with capabilities and prices.
Problems it solves
- one Ruby API for OpenAI, Claude and Gemini so I can switch models without rewriting code
- save LLM conversations in my Rails database and stream replies to the page with Hotwire
- add a chat interface to my Rails app quickly
- let the model call Ruby methods in my app as tools
- get structured data back from an LLM as a Ruby object that matches my schema
- track how much each AI conversation costs in my Ruby app
- fall back to another model when the first provider fails
- ask a model about an uploaded PDF, image or audio file from Ruby
- run a local model through Ollama from my Ruby code with the same API as hosted ones
- test my AI agent's answers against a dataset from RSpec or Minitest
- generate embeddings and rerank search results from Ruby
- build reusable AI agents with instructions and tools in a Rails app
Features
- 23 providers and any OpenAI-compatible API
- chat with streaming through a block
- attachments: images, video, audio, PDFs and other documents
- structured output with with_schema and response.parsed
- tools, tool approval, provider tools and MCP connectors
- RubyLLM::Agent and a step-by-step agentic loop
- image and video generation, transcription and speech, OCR, embeddings, reranking, moderation
- prompt caching, compaction, token counting, fallbacks and cancellation
- Rails: Active Record persistence (acts_as_chat), Active Storage, Hotwire streaming, generators and chat UI
- evaluations with datasets, model criteria and Ruby assertions; judgments
View 4 more
- per-attempt cost tracking, instrumentation and OpenTelemetry tracing
- model registry with capabilities, limits and pricing
- fiber-based async; provider batch processing
- code execution sandbox and skills in the Agent Skills format (2.2)
Limitations
- Doesn't support Ruby versions before 3.21
Alternatives
The same job
These do what RubyLLM does.
- OpenAI Ruby SDK Official Ruby SDK for the OpenAI API
- ruby-openai Use the OpenAI API with Ruby
