ruby_llm: OpenRouter config not working in 1.3.0.rc1

Up until now, I’ve been using OpenRouter via:

RubyLLM.configure do |config|
  config.openai_api_key = "..."
  config.openai_api_base = "https://openrouter.ai/api/v1"
end

Now that 1.3.0.rc1 has added proper OpenRouter support, I changed it to:

RubyLLM.configure do |config|
  config.openrouter_api_key = "..."
end

but it fails with:

'RubyLLM::Connection#ensure_configured!': openai provider is not configured. Add this to your initialization: (RubyLLM::ConfigurationError)

RubyLLM.configure do |config|
  config.openai_api_key = ENV['OPENAI_API_KEY']
end

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (10 by maintainers)

Most upvoted comments

I added a rake task to automatically generate aliases.json so we’ll not need to update it manually ever again, solving the issue with gpt-4.1-nano above 120526c38a53f29408be2f59453a9b9cc3298548

FYI the reason you need the full model id is that nano is not here – https://github.com/crmne/ruby_llm/blob/main/lib/ruby_llm/aliases.json

And provider is optional if you are giving a full model id (which is specific to that provider).

you need to do:

chat = RubyLLM.chat(model: “gpt-4.1-nano”, provider: :openrouter)

That fails, but this works:

chat = RubyLLM.chat(model: "openai/gpt-4.1-nano", provider: :openrouter)

It seems the provider argument is not actually needed, as this also works:

chat = RubyLLM.chat(model: "openai/gpt-4.1-nano")

Because a single model (Claude) is available via Anthropic, Bedrock, and OpenRouter. The library needs to know which one you want to use. Once you tell it, it will use the corresponding key(s) you have configured.

Got it! I’ll fix it first thing tomorrow!