Skip to content

Commit 1d6f53a

Browse files
TomerAberbachstainless-app[bot]
authored andcommitted
feat(vertex): add support for US multi-region endpoint
1 parent b2ae37a commit 1d6f53a

2 files changed

Lines changed: 63 additions & 2 deletions

File tree

vertex/vertex.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ func WithCredentials(ctx context.Context, region string, projectID string, creds
4646
middleware := vertexMiddleware(region, projectID)
4747

4848
var baseURL string
49-
if region == "global" {
49+
switch region {
50+
case "global":
5051
baseURL = "https://aiplatform.googleapis.com/"
51-
} else {
52+
case "us":
53+
baseURL = "https://aiplatform.us.rep.googleapis.com/"
54+
default:
5255
baseURL = fmt.Sprintf("https://%s-aiplatform.googleapis.com/", region)
5356
}
5457

vertex/vertex_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package vertex
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"golang.org/x/oauth2"
8+
"golang.org/x/oauth2/google"
9+
10+
"github.com/anthropics/anthropic-sdk-go/internal/requestconfig"
11+
)
12+
13+
func TestBaseURLForRegion(t *testing.T) {
14+
testCases := []struct {
15+
name string
16+
region string
17+
expectedURL string
18+
}{
19+
{
20+
name: "global region",
21+
region: "global",
22+
expectedURL: "https://aiplatform.googleapis.com/",
23+
},
24+
{
25+
name: "us region",
26+
region: "us",
27+
expectedURL: "https://aiplatform.us.rep.googleapis.com/",
28+
},
29+
{
30+
name: "specific region",
31+
region: "us-central1",
32+
expectedURL: "https://us-central1-aiplatform.googleapis.com/",
33+
},
34+
{
35+
name: "europe region",
36+
region: "europe-west1",
37+
expectedURL: "https://europe-west1-aiplatform.googleapis.com/",
38+
},
39+
}
40+
41+
for _, tc := range testCases {
42+
t.Run(tc.name, func(t *testing.T) {
43+
creds := &google.Credentials{
44+
TokenSource: oauth2.StaticTokenSource(&oauth2.Token{AccessToken: "fake"}),
45+
}
46+
opt := WithCredentials(context.Background(), tc.region, "test-project", creds)
47+
48+
cfg := &requestconfig.RequestConfig{}
49+
if err := opt.Apply(cfg); err != nil {
50+
t.Fatalf("Failed to apply option: %v", err)
51+
}
52+
53+
if cfg.BaseURL.String() != tc.expectedURL {
54+
t.Errorf("Expected base URL %q, got %q", tc.expectedURL, cfg.BaseURL.String())
55+
}
56+
})
57+
}
58+
}

0 commit comments

Comments
 (0)