Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require 'irb'

RubyLLM.configure do |config|
config.anthropic_api_key = ENV.fetch('ANTHROPIC_API_KEY', nil)
config.anthropic_api_base = ENV.fetch('ANTHROPIC_BASE_URL', nil)
config.bedrock_api_key = ENV.fetch('AWS_ACCESS_KEY_ID', nil)
config.bedrock_region = ENV.fetch('AWS_REGION', nil)
config.bedrock_secret_key = ENV.fetch('AWS_SECRET_ACCESS_KEY', nil)
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_llm/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Configuration
:openai_organization_id,
:openai_project_id,
:openai_use_system_role,
:anthropic_api_base,
:anthropic_api_key,
:gemini_api_key,
:gemini_api_base,
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_llm/providers/anthropic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Anthropic < Provider
include Anthropic::Tools

def api_base
'https://api.anthropic.com'
@config.anthropic_api_base || 'https://api.anthropic.com'
end

def headers
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_llm/providers/anthropic/chat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Chat
module_function

def completion_url
'/v1/messages'
'v1/messages'
end

def render_payload(messages, tools:, temperature:, model:, stream: false, schema: nil, thinking: nil) # rubocop:disable Metrics/ParameterLists,Lint/UnusedMethodArgument
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_llm/providers/anthropic/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Models
module_function

def models_url
'/v1/models'
'v1/models'
end

def parse_list_models_response(response, slug, capabilities)
Expand Down
39 changes: 39 additions & 0 deletions spec/ruby_llm/providers/anthropic_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe RubyLLM::Providers::Anthropic do
subject(:provider) { described_class.new(config) }

let(:config) do
instance_double(
RubyLLM::Configuration,
request_timeout: 300,
max_retries: 3,
retry_interval: 0.1,
retry_interval_randomness: 0.5,
retry_backoff_factor: 2,
http_proxy: nil,
anthropic_api_key: 'test-key',
anthropic_api_base: anthropic_api_base
)
end

describe '#api_base' do
context 'when anthropic_api_base is not set' do
let(:anthropic_api_base) { nil }

it 'returns the default Anthropic API URL' do
expect(provider.api_base).to eq('https://api.anthropic.com')
end
end

context 'when anthropic_api_base is set' do
let(:anthropic_api_base) { 'https://custom-anthropic-endpoint.example.com' }

it 'returns the custom API URL' do
expect(provider.api_base).to eq('https://custom-anthropic-endpoint.example.com')
end
end
end
end