RubyLLM (gateway)

RubyLLM does not have a Ruby-side tracing instrumentor. Route all calls through the Respan gateway to capture every request as a trace.

Setup

1

Install RubyLLM

$gem install ruby_llm

Or add it to your Gemfile.

1gem "ruby_llm"
2

Set environment variables

$export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"

No provider key needed — the Respan gateway handles provider authentication.

3

Configure RubyLLM with Respan

1RubyLLM.configure do |config|
2 config.openai_api_key = ENV["RESPAN_API_KEY"]
3 config.openai_api_base = "https://api.respan.ai/api"
4end
4

Make your first request

1chat = RubyLLM.chat(model: "gpt-5.5")
2response = chat.ask("Hello, world!")
3puts response.content
5

View your trace

Open the Traces page to see your gateway-routed calls with prompts, tokens, and cost.

Switch models

Use another OpenAI model ID that Respan exposes through the same OpenAI-compatible endpoint.

1chat = RubyLLM.chat(model: "gpt-5.5")
2chat = RubyLLM.chat(model: "gpt-5-mini")
3
4response = chat.ask("Tell me about artificial intelligence")
5puts response.content

RubyLLM’s OpenAI-compatible adapter does not provide a provider-neutral way to show Claude or Gemini model switches in this setup. Use the Respan API or OpenAI SDK gateway pages for provider-neutral Claude and Gemini examples.

See the full model list.

Streaming

1chat = RubyLLM.chat(model: "gpt-5.5")
2chat.ask("Explain quantum computing") do |chunk|
3 print chunk.content
4end

Multi-tenancy with contexts

Use RubyLLM contexts to isolate per-tenant configuration.

1tenant_ctx = RubyLLM.context do |config|
2 config.openai_api_key = tenant.respan_api_key
3 config.openai_api_base = "https://api.respan.ai/api"
4end
5
6chat = tenant_ctx.chat(model: "gpt-5.5")
7response = chat.ask("Hello!")

Rails integration

Set your Respan config in an initializer.

1# config/initializers/ruby_llm.rb
2RubyLLM.configure do |config|
3 config.openai_api_key = ENV["RESPAN_API_KEY"]
4 config.openai_api_base = "https://api.respan.ai/api"
5end

Use acts_as_chat as normal — all LLM calls will be routed through Respan.