Skip to content

Commit d698dd1

Browse files
committed
OpenRouter support
1 parent a0f3704 commit d698dd1

File tree

50 files changed

+18563
-2098
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+18563
-2098
lines changed

.overcommit.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ PreCommit:
1818
exclude:
1919
- '**/db/structure.sql' # Ignore trailing whitespace in generated files
2020

21+
RakeTarget:
22+
enabled: true
23+
targets: ['models:update', 'models:docs']
24+
on_warn: fail
25+
2126
PostCheckout:
2227
ALL: # Special hook name that customizes all hooks of this type
2328
quiet: true # Change all post-checkout hooks to only display output on failure

bin/console

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ RubyLLM.configure do |config|
1616
config.bedrock_secret_key = ENV.fetch('AWS_SECRET_ACCESS_KEY', nil)
1717
config.bedrock_region = ENV.fetch('AWS_REGION', nil)
1818
config.bedrock_session_token = ENV.fetch('AWS_SESSION_TOKEN', nil)
19+
config.openrouter_api_key = ENV.fetch('OPENROUTER_API_KEY', nil)
1920
end
2021

2122
IRB.start(__FILE__)

docs/guides/available-models.md

Lines changed: 639 additions & 24 deletions
Large diffs are not rendered by default.

lib/ruby_llm.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
'openai' => 'OpenAI',
1717
'api' => 'API',
1818
'deepseek' => 'DeepSeek',
19-
'bedrock' => 'Bedrock'
19+
'bedrock' => 'Bedrock',
20+
'openrouter' => 'OpenRouter'
2021
)
2122
loader.ignore("#{__dir__}/tasks")
2223
loader.ignore("#{__dir__}/ruby_llm/railtie")
@@ -79,6 +80,7 @@ def logger
7980
RubyLLM::Provider.register :gemini, RubyLLM::Providers::Gemini
8081
RubyLLM::Provider.register :deepseek, RubyLLM::Providers::DeepSeek
8182
RubyLLM::Provider.register :bedrock, RubyLLM::Providers::Bedrock
83+
RubyLLM::Provider.register :openrouter, RubyLLM::Providers::OpenRouter
8284

8385
if defined?(Rails::Railtie)
8486
require 'ruby_llm/railtie'

lib/ruby_llm/aliases.json

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
{
22
"claude-3-5-sonnet": {
33
"anthropic": "claude-3-5-sonnet-20241022",
4-
"bedrock": "anthropic.claude-3-5-sonnet-20241022-v2:0"
4+
"bedrock": "anthropic.claude-3-5-sonnet-20241022-v2:0",
5+
"openrouter": "anthropic/claude-3.5-sonnet"
56
},
67
"claude-3-5-haiku": {
78
"anthropic": "claude-3-5-haiku-20241022",
8-
"bedrock": "anthropic.claude-3-5-haiku-20241022-v1:0"
9+
"bedrock": "anthropic.claude-3-5-haiku-20241022-v1:0",
10+
"openrouter": "anthropic/claude-3.5-haiku-20241022"
911
},
1012
"claude-3-7-sonnet": {
1113
"anthropic": "claude-3-7-sonnet-20250219",
12-
"bedrock": "us.anthropic.claude-3-7-sonnet-20250219-v1:0"
14+
"bedrock": "us.anthropic.claude-3-7-sonnet-20250219-v1:0",
15+
"openrouter": "us.anthropic.claude-3-7-sonnet-20250219-v1:0"
1316
},
1417
"claude-3-opus": {
1518
"anthropic": "claude-3-opus-20240229",
@@ -25,14 +28,53 @@
2528
},
2629
"claude-3": {
2730
"anthropic": "claude-3-sonnet-20240229",
28-
"bedrock": "anthropic.claude-3-sonnet-20240229-v1:0"
31+
"bedrock": "anthropic.claude-3-sonnet-20240229-v1:0",
32+
"openrouter": "anthropic/claude-3-sonnet"
2933
},
3034
"claude-2": {
3135
"anthropic": "claude-2.0",
32-
"bedrock": "anthropic.claude-2.0"
36+
"bedrock": "anthropic.claude-2.0",
37+
"openrouter": "anthropic/claude-2"
3338
},
3439
"claude-2-1": {
3540
"anthropic": "claude-2.1",
36-
"bedrock": "anthropic.claude-2.1"
41+
"bedrock": "anthropic.claude-2.1",
42+
"openrouter": "anthropic/claude-2.1"
43+
},
44+
"gpt-4o": {
45+
"openai": "gpt-4o",
46+
"openrouter": "openai/gpt-4o"
47+
},
48+
"gpt-4o-mini": {
49+
"openai": "gpt-4o-mini",
50+
"openrouter": "openai/gpt-4o-mini"
51+
},
52+
"gpt-4-turbo": {
53+
"openai": "gpt-4-turbo",
54+
"openrouter": "openai/gpt-4-turbo"
55+
},
56+
"gemini-1.5-flash": {
57+
"gemini": "gemini-1.5-flash",
58+
"openrouter": "google/gemini-flash-1.5"
59+
},
60+
"gemini-1.5-flash-8b": {
61+
"gemini": "gemini-1.5-flash-8b",
62+
"openrouter": "google/gemini-flash-1.5-8b"
63+
},
64+
"gemini-1.5-pro": {
65+
"gemini": "gemini-1.5-pro",
66+
"openrouter": "google/gemini-pro-1.5"
67+
},
68+
"gemini-2.0-flash": {
69+
"gemini": "gemini-2.0-flash",
70+
"openrouter": "google/gemini-2.0-flash-001"
71+
},
72+
"o1": {
73+
"openai": "o1",
74+
"openrouter": "openai/o1"
75+
},
76+
"o3-mini": {
77+
"openai": "o3-mini",
78+
"openrouter": "openai/o3-mini"
3779
}
3880
}

lib/ruby_llm/configuration.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Configuration
2020
:bedrock_secret_key,
2121
:bedrock_region,
2222
:bedrock_session_token,
23+
:openrouter_api_key,
2324
# Default models
2425
:default_model,
2526
:default_embedding_model,

lib/ruby_llm/connection.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def initialize(provider, config)
1919
end
2020

2121
def post(url, payload)
22+
RubyLLM.logger.debug "POST #{url} with payload: #{payload.inspect}"
2223
body = payload.is_a?(Hash) ? JSON.generate(payload, ascii_only: false) : payload
2324
@connection.post url, body do |req|
2425
req.headers.merge! @provider.headers(@config) if @provider.respond_to?(:headers)

0 commit comments

Comments
 (0)