Skip to content

Commit 361a71f

Browse files
opencode-agent[bot]rekram1-nodeneriousy
authored
fix(opencode): route Vertex multi-regions through REP (anomalyco#42648)
Co-authored-by: Aiden Cline <[email protected]> Co-authored-by: Filip <[email protected]>
1 parent fa8f170 commit 361a71f

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

‎packages/opencode/src/provider/provider.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ function googleVertexAnthropicBaseURL(project: string | undefined, location: str
9898
return `https://aiplatform.${location}.rep.googleapis.com/v1/projects/${project}/locations/${location}/publishers/anthropic/models`
9999
}
100100

101+
function googleVertexEndpoint(location: string) {
102+
if (location === "global") return "aiplatform.googleapis.com"
103+
if (location === "eu" || location === "us") return `aiplatform.${location}.rep.googleapis.com`
104+
return `${location}-aiplatform.googleapis.com`
105+
}
106+
101107
type BundledSDK = {
102108
languageModel(modelId: string): LanguageModelV3
103109
chat?: (modelId: string) => LanguageModelV3
@@ -519,11 +525,10 @@ function custom(dep: CustomDep): Record<string, CustomLoader> {
519525
return {
520526
autoload: true,
521527
vars(_options: Record<string, any>) {
522-
const endpoint = location === "global" ? "aiplatform.googleapis.com" : `${location}-aiplatform.googleapis.com`
523528
return {
524529
...(project && { GOOGLE_VERTEX_PROJECT: project }),
525530
GOOGLE_VERTEX_LOCATION: location,
526-
GOOGLE_VERTEX_ENDPOINT: endpoint,
531+
GOOGLE_VERTEX_ENDPOINT: googleVertexEndpoint(location),
527532
}
528533
},
529534
options: {

‎packages/opencode/test/provider/provider.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,6 +1909,38 @@ it.instance("Google Vertex: keeps regional Claude endpoints unchanged", () =>
19091909
}),
19101910
)
19111911

1912+
it.instance("Google Vertex: uses REP endpoint for Gemini continental multi-regions", () =>
1913+
Effect.gen(function* () {
1914+
yield* set("GOOGLE_CLOUD_PROJECT", "test-project")
1915+
yield* set("VERTEX_LOCATION", "eu")
1916+
const provider = yield* Provider.Service
1917+
const model = yield* provider.getModel(
1918+
ProviderV2.ID.make("google-vertex"),
1919+
ModelV2.ID.make("gemini-3.5-flash"),
1920+
)
1921+
const language = yield* provider.getLanguage(model)
1922+
expect(languageBaseURL(language)).toBe(
1923+
"https://aiplatform.eu.rep.googleapis.com/v1beta1/projects/test-project/locations/eu/publishers/google",
1924+
)
1925+
}),
1926+
)
1927+
1928+
it.instance("Google Vertex: keeps regional Gemini endpoints unchanged", () =>
1929+
Effect.gen(function* () {
1930+
yield* set("GOOGLE_CLOUD_PROJECT", "test-project")
1931+
yield* set("VERTEX_LOCATION", "europe-west1")
1932+
const provider = yield* Provider.Service
1933+
const model = yield* provider.getModel(
1934+
ProviderV2.ID.make("google-vertex"),
1935+
ModelV2.ID.make("gemini-3.5-flash"),
1936+
)
1937+
const language = yield* provider.getLanguage(model)
1938+
expect(languageBaseURL(language)).toBe(
1939+
"https://europe-west1-aiplatform.googleapis.com/v1beta1/projects/test-project/locations/europe-west1/publishers/google",
1940+
)
1941+
}),
1942+
)
1943+
19121944
it.instance("cloudflare-ai-gateway loads with env variables", () =>
19131945
Effect.gen(function* () {
19141946
yield* set("CLOUDFLARE_ACCOUNT_ID", "test-account")

0 commit comments

Comments
 (0)