Skip to content

[JS] Vertex AI plugin uses incorrect URL for global location in Genkit #3651

@momokofujii

Description

@momokofujii

Describe the bug
When using the Vertex AI plugin in Genkit and specifying location: 'global', the request URL becomes https://global-aiplatform.googleapis.com, which results in a 404 error. The correct URL should be https://aiplatform.googleapis.com.

It seems that the root cause is in this line of code:

const response = await fetch(
`https://${location}-aiplatform.googleapis.com/v1beta1/publishers/google/models`,

Here, when location is global, it should use https://aiplatform.googleapis.com instead of https://global-aiplatform.googleapis.com.

For reference, the official Google library handles this correctly:
https://github.com/googleapis/js-genai/blob/beef4e38c8df0c41957a3b3394aa75298c646ee2/src/_api_client.ts#L185C1-L196C4

private baseUrlFromProjectLocation(): string {
    if (
      this.clientOptions.project &&
      this.clientOptions.location &&
      this.clientOptions.location !== 'global'
    ) {
      // Regional endpoint
      return `https://${this.clientOptions.location}-aiplatform.googleapis.com/`;
    }
    // Global endpoint (covers 'global' location and API key usage)
    return `https://aiplatform.googleapis.com/`;
}

To Reproduce
Steps to reproduce the behavior.

import { genkit } from 'genkit';
import { vertexAI } from '@genkit-ai/google-genai';

const ai = genkit({
  plugins: [
    vertexAI({ location: 'global' }),
  ],
});

When attempting to list or use models with location: 'global', the request fails with a 404 error.

Expected behavior
When location is set to 'global', the request should go to https://aiplatform.googleapis.com instead of https://global-aiplatform.googleapis.com, avoiding the 404 error.

Screenshots
If applicable, add screenshots to help explain your problem.

Runtime (please complete the following information):

  • OS: MacOS
  • Version 14.3

** Node version

  • v23.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingjs

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions