Compare commits

...

1 Commits

Author SHA1 Message Date
Filip 5ceeeb3e2c fix(core): route Vertex multi-regions through REP 2026-08-14 19:28:36 +00:00
2 changed files with 63 additions and 3 deletions
@@ -26,6 +26,7 @@ function resolveLocation(options: Record<string, any>) {
function vertexEndpoint(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`
}
@@ -111,13 +112,18 @@ export const GoogleVertexPlugin = define({
if (evt.package !== "@ai-sdk/google-vertex") return
const mod = yield* Effect.promise(() => import("@ai-sdk/google-vertex"))
const project = resolveProject(evt.options)
const location = resolveLocation(evt.options)
const location = String(resolveLocation(evt.options))
const options = { ...evt.options }
delete options.fetch
evt.sdk = mod.createVertex({
...options,
project,
location,
...((location === "eu" || location === "us") && project && !options.apiKey && !options.baseURL
? {
baseURL: `https://${vertexEndpoint(location)}/v1beta1/projects/${project}/locations/${location}/publishers/google`,
}
: {}),
})
}),
)
@@ -230,7 +230,7 @@ describe("GoogleVertexPlugin", () => {
),
)
it.effect("keeps OpenAI-compatible Vertex endpoint templates regional for eu", () =>
it.effect("uses the REP endpoint for OpenAI-compatible Vertex multi-regions", () =>
Effect.gen(function* () {
const catalog = yield* Catalog.Service
yield* catalog.transform((catalog) =>
@@ -248,11 +248,65 @@ describe("GoogleVertexPlugin", () => {
const provider = required(yield* catalog.provider.get(Provider.ID.make("google-vertex")))
expect(provider).toMatchObject({
package: "aisdk:@ai-sdk/openai-compatible",
settings: { baseURL: "https://eu-aiplatform.googleapis.com/v1/projects/config-project/locations/eu" },
settings: {
baseURL: "https://aiplatform.eu.rep.googleapis.com/v1/projects/config-project/locations/eu",
},
})
}),
)
it.effect("uses the REP endpoint for the native Vertex SDK in multi-regions", () =>
withEnv(
{
GOOGLE_CLOUD_PROJECT: "env-project",
GOOGLE_VERTEX_LOCATION: "us",
},
() =>
Effect.gen(function* () {
vertexOptions.length = 0
const aisdk = yield* AISDK.Service
yield* addPlugin()
yield* aisdk.runSDK({
model: Model.Info.make({
...Model.Info.default(Provider.ID.make("google-vertex"), Model.ID.make("gemini")),
modelID: Model.ID.make("gemini"),
package: "aisdk:@ai-sdk/google-vertex",
}),
package: "@ai-sdk/google-vertex",
options: { name: "google-vertex" },
})
expect(vertexOptions).toHaveLength(1)
expect(vertexOptions[0].baseURL).toBe(
"https://aiplatform.us.rep.googleapis.com/v1beta1/projects/env-project/locations/us/publishers/google",
)
}),
),
)
it.effect("preserves custom native Vertex base URLs in multi-regions", () =>
Effect.gen(function* () {
vertexOptions.length = 0
const aisdk = yield* AISDK.Service
yield* addPlugin()
yield* aisdk.runSDK({
model: Model.Info.make({
...Model.Info.default(Provider.ID.make("google-vertex"), Model.ID.make("gemini")),
modelID: Model.ID.make("gemini"),
package: "aisdk:@ai-sdk/google-vertex",
}),
package: "@ai-sdk/google-vertex",
options: {
name: "google-vertex",
project: "project",
location: "eu",
baseURL: "https://vertex.example/v1",
},
})
expect(vertexOptions).toHaveLength(1)
expect(vertexOptions[0].baseURL).toBe("https://vertex.example/v1")
}),
)
it.effect("defaults location to us-central1 when only project is configured", () =>
withEnv(
{