Skip to content

Commit 3896130

Browse files
Fix Vertex AI Global Endpoint URL Construction (#553)
### Problem When configuring `RubyLLM` with `vertexai_location: "global"`, the `VertexAI` provider incorrectly constructs the API URL as `https://global-aiplatform.googleapis.com/v1beta1`. This hostname does not exist, causing requests to fail with a 404 error. According to the [Google Cloud Vertex AI documentation](https://docs.cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#global-endpoint), the global endpoint should use the base hostname `https://aiplatform.googleapis.com/v1beta1` without a location prefix. ### Solution Updated `RubyLLM::Providers::VertexAI#api_base` to handle `"global"` as a special case: - **Global:** Returns `https://aiplatform.googleapis.com/v1beta1` - **Regional:** Continues to return `https://{location}-aiplatform.googleapis.com/v1beta1` (e.g., `us-central1`) ### Changes - Modified `lib/ruby_llm/providers/vertexai.rb` to conditionally build the base URL. - Added `spec/ruby_llm/providers/vertexai_spec.rb` to verify the URL construction logic for both global and regional configurations. ### Verification - [x] Added unit tests confirming correct URL generation for `global` vs `us-central1` locations. Co-authored-by: Carmine Paolino <carmine@paolino.me>
1 parent bf218bd commit 3896130

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

lib/ruby_llm/providers/vertexai.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ def initialize(config)
1616
end
1717

1818
def api_base
19-
"https://#{@config.vertexai_location}-aiplatform.googleapis.com/v1beta1"
19+
if @config.vertexai_location == 'global'
20+
'https://aiplatform.googleapis.com/v1beta1'
21+
else
22+
"https://#{@config.vertexai_location}-aiplatform.googleapis.com/v1beta1"
23+
end
2024
end
2125

2226
def headers
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require 'spec_helper'
2+
3+
RSpec.describe RubyLLM::Providers::VertexAI do
4+
let(:config) { double('config', vertexai_location: location, vertexai_project_id: 'test-project') }
5+
subject { described_class.new(config) }
6+
7+
describe '#api_base' do
8+
context 'when location is global' do
9+
let(:location) { 'global' }
10+
11+
it 'uses the correct api_base without location prefix' do
12+
expect(subject.api_base).to eq('https://aiplatform.googleapis.com/v1beta1')
13+
end
14+
end
15+
16+
context 'when location is not global' do
17+
let(:location) { 'us-central1' }
18+
19+
it 'uses the correct api_base with location prefix' do
20+
expect(subject.api_base).to eq('https://us-central1-aiplatform.googleapis.com/v1beta1')
21+
end
22+
end
23+
end
24+
end

0 commit comments

Comments
 (0)