DEV Community

Cover image for Introducing RubyLLM 1.0: A Beautiful Way to Work with AI
Carmine Paolino
Carmine Paolino

Posted on

12 3 3 1

Introducing RubyLLM 1.0: A Beautiful Way to Work with AI

I released RubyLLM 1.0 today. It's a library that makes working with AI in Ruby feel natural, elegant, and enjoyable.

Why This Matters

AI should be accessible to Ruby developers without ceremony or complexity. When building Chat with Work, I wanted to simply write:

chat = RubyLLM.chat
chat.ask "What's the best way to learn Ruby?"
Enter fullscreen mode Exit fullscreen mode

And have it work - regardless of which model I'm using, whether I'm streaming responses, or which provider I've chosen. The API should get out of the way and let me focus on building my product.

The RubyLLM Philosophy

Beautiful interfaces matter. Ruby has always been about developer happiness. Your AI code should reflect that same elegance:

# Global methods for core operations - simple and expressive
chat = RubyLLM.chat
embedding = RubyLLM.embed("Ruby is elegant")
image = RubyLLM.paint("a sunset over mountains")

# Method chaining that reads like English
chat.with_model('gpt-4o-mini')
    .with_temperature(0.7)
    .ask("What's your favorite gem?")
Enter fullscreen mode Exit fullscreen mode

Convention over configuration. You shouldn't need to think about providers or remember multiple APIs:

# Don't care which model? We'll use a sensible default
chat = RubyLLM.chat

# Want a specific model? Just say so
chat = RubyLLM.chat(model: 'claude-3-5-sonnet')

# Switch to GPT mid-conversation? Just as easy
chat.with_model('gpt-4o-mini')
Enter fullscreen mode Exit fullscreen mode

Practical tools for real work. Function calling should be Ruby-like, not JSON Schema gymnastics:

class Search < RubyLLM::Tool
  description "Searches our knowledge base"
  param :query, desc: "Search query"
  param :limit, type: :integer, desc: "Max results", required: false

  def execute(query:, limit: 5)
    Document.search(query).limit(limit).map(&:title)
  end
end

# Clean, practical, Ruby-like
chat.with_tool(Search).ask "Find our product documentation"
Enter fullscreen mode Exit fullscreen mode

Streaming done right. No need to parse different formats for different providers:

chat.ask "Write a story about Ruby" do |chunk|
  # No provider-specific parsing - we handle that for you
  print chunk.content
end
Enter fullscreen mode Exit fullscreen mode

Token tracking by default. Cost management should be built-in:

response = chat.ask "Explain Ruby modules"
puts "This cost #{response.input_tokens + response.output_tokens} tokens"
Enter fullscreen mode Exit fullscreen mode

Meaningful error handling. Production apps need proper error types:

begin
  chat.ask "Question"
rescue RubyLLM::RateLimitError
  puts "Rate limited - backing off"
rescue RubyLLM::UnauthorizedError
  puts "API key issue - check configuration"
end
Enter fullscreen mode Exit fullscreen mode

Rails as a first-class citizen. Because most of us are building Rails apps:

class Chat < ApplicationRecord
  acts_as_chat
end

chat = Chat.create!(model_id: 'gemini-2.0-flash')
chat.ask "Hello"  # Everything persisted automatically
Enter fullscreen mode Exit fullscreen mode

Built for Real Applications

RubyLLM supports the features you actually need in production:

# Vision
chat.ask "What's in this image?", with: { image: "photo.jpg" }

# PDFs
chat.ask "Summarize this document", with: { pdf: "contract.pdf" }

# Audio
chat.ask "Transcribe this recording", with: { audio: "meeting.wav" }

# Multiple files
chat.ask "Compare these diagrams", with: { image: ["chart1.png", "chart2.png"] }
Enter fullscreen mode Exit fullscreen mode

Minimal Dependencies

Just Faraday, Zeitwerk, and a tiny event parser. No dependency hell.

Used in Production Today

RubyLLM powers Chat with Work in production. It's battle-tested with real-world AI integrations and built for serious applications.

Give it a try today: gem install ruby_llm

More details at rubyllm.com

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry πŸ•’

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more β†’

Top comments (5)

Collapse
 
giovapanasiti profile image
Giovanni Panasiti β€’

Love it!

Collapse
 
marioadriano profile image
MΓ‘rio SΓ©rgio Adriano β€’

This is a great Ruby gem

Collapse
 
crmne profile image
Carmine Paolino β€’

thank you!

Collapse
 
laikokwui profile image
Lai Kok Wui β€’

the model is cloud based or i have to download locallly?

Collapse
 
crmne profile image
Carmine Paolino β€’

Hi, this is not a model, it's library to talk with models.

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay