Compare commits

...

1 Commits

Author SHA1 Message Date
Aiden Cline c4b03db4d5 fix(opencode): route Vertex multi-regions through REP 2026-08-14 19:48:55 +00:00
2 changed files with 50 additions and 2 deletions
+18 -2
View File
@@ -98,6 +98,12 @@ function googleVertexAnthropicBaseURL(project: string | undefined, location: str
return `https://aiplatform.${location}.rep.googleapis.com/v1/projects/${project}/locations/${location}/publishers/anthropic/models`
}
function googleVertexEndpoint(location: string) {
if (location === "global") return "aiplatform.googleapis.com"
if (location === "eu" || location === "us") return `aiplatform.${location}.rep.googleapis.com`
return `${location}-aiplatform.googleapis.com`
}
type BundledSDK = {
languageModel(modelId: string): LanguageModelV3
chat?: (modelId: string) => LanguageModelV3
@@ -519,11 +525,10 @@ function custom(dep: CustomDep): Record<string, CustomLoader> {
return {
autoload: true,
vars(_options: Record<string, any>) {
const endpoint = location === "global" ? "aiplatform.googleapis.com" : `${location}-aiplatform.googleapis.com`
return {
...(project && { GOOGLE_VERTEX_PROJECT: project }),
GOOGLE_VERTEX_LOCATION: location,
GOOGLE_VERTEX_ENDPOINT: endpoint,
GOOGLE_VERTEX_ENDPOINT: googleVertexEndpoint(location),
}
},
options: {
@@ -1687,6 +1692,17 @@ const layer = Layer.effect(
if (baseURL) options.baseURL = baseURL
}
if (
model.providerID === "google-vertex" &&
model.api.npm === "@ai-sdk/google-vertex" &&
!options.baseURL &&
!options.apiKey &&
typeof options.project === "string" &&
(options.location === "eu" || options.location === "us")
) {
options.baseURL = `https://${googleVertexEndpoint(options.location)}/v1beta1/projects/${options.project}/locations/${options.location}/publishers/google`
}
if (model.providerID === "google-vertex" && !model.api.npm.includes("@ai-sdk/openai-compatible")) {
delete options.fetch
}
@@ -1909,6 +1909,38 @@ it.instance("Google Vertex: keeps regional Claude endpoints unchanged", () =>
}),
)
it.instance("Google Vertex: uses REP endpoint for Gemini continental multi-regions", () =>
Effect.gen(function* () {
yield* set("GOOGLE_CLOUD_PROJECT", "test-project")
yield* set("VERTEX_LOCATION", "eu")
const provider = yield* Provider.Service
const model = yield* provider.getModel(
ProviderV2.ID.make("google-vertex"),
ModelV2.ID.make("gemini-3.5-flash"),
)
const language = yield* provider.getLanguage(model)
expect(languageBaseURL(language)).toBe(
"https://aiplatform.eu.rep.googleapis.com/v1beta1/projects/test-project/locations/eu/publishers/google",
)
}),
)
it.instance("Google Vertex: keeps regional Gemini endpoints unchanged", () =>
Effect.gen(function* () {
yield* set("GOOGLE_CLOUD_PROJECT", "test-project")
yield* set("VERTEX_LOCATION", "europe-west1")
const provider = yield* Provider.Service
const model = yield* provider.getModel(
ProviderV2.ID.make("google-vertex"),
ModelV2.ID.make("gemini-3.5-flash"),
)
const language = yield* provider.getLanguage(model)
expect(languageBaseURL(language)).toBe(
"https://europe-west1-aiplatform.googleapis.com/v1beta1/projects/test-project/locations/europe-west1/publishers/google",
)
}),
)
it.instance("cloudflare-ai-gateway loads with env variables", () =>
Effect.gen(function* () {
yield* set("CLOUDFLARE_ACCOUNT_ID", "test-account")