Skip to content

Commit cb00fd1

Browse files
committed
fix(vertexai): correct URL construction for global endpoint
When location is set to 'global', the plugin was incorrectly constructing the URL as https://global-aiplatform.googleapis.com, which results in 404. The correct URL for global endpoint should be https://aiplatform.googleapis.com without the location prefix. This fix applies to: - list-models.ts: Model listing endpoint - upsert_datapoints.ts: Vector search datapoint upsert endpoint - predict.ts: Prediction endpoint - evaluation/evaluator_factory.ts: Evaluation service endpoint - modelgarden/v2/llama.ts: Llama model garden endpoint Implementation uses a ternary operator for optimal performance and follows the same pattern as Google's official Gen AI SDK. Fixes #3651
1 parent 6e58dbe commit cb00fd1

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

js/plugins/vertexai/src/evaluation/evaluator_factory.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ export class EvaluatorFactory {
8282

8383
metadata.input = request;
8484
const client = await this.auth.getClient();
85-
const url = `https://${this.location}-aiplatform.googleapis.com/v1beta1/${locationName}:evaluateInstances`;
85+
const baseUrl = this.location === 'global'
86+
? 'https://aiplatform.googleapis.com'
87+
: `https://${this.location}-aiplatform.googleapis.com`;
88+
89+
const url = `${baseUrl}/v1beta1/${locationName}:evaluateInstances`;
8690
const response = await client.request({
8791
url,
8892
method: 'POST',

js/plugins/vertexai/src/list-models.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,14 @@ export async function listModels(
3838
): Promise<Model[]> {
3939
const fetch = (await import('node-fetch')).default;
4040
const accessToken = await authClient.getAccessToken();
41+
42+
// Global endpoint uses base URL without location prefix
43+
const baseUrl = location === 'global'
44+
? 'https://aiplatform.googleapis.com'
45+
: `https://${location}-aiplatform.googleapis.com`;
46+
4147
const response = await fetch(
42-
`https://${location}-aiplatform.googleapis.com/v1beta1/publishers/google/models`,
48+
`${baseUrl}/v1beta1/publishers/google/models`,
4349
{
4450
method: 'GET',
4551
headers: {

js/plugins/vertexai/src/modelgarden/v2/llama.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,13 @@ async function resolveOptions(
146146
clientOptions: ClientOptions,
147147
requestConfig?: LlamaConfig
148148
) {
149-
const baseUrlTemplate =
150-
clientOptions.baseUrlTemplate ??
151-
'https://{location}-aiplatform.googleapis.com/v1/projects/{projectId}/locations/{location}/endpoints/openapi';
152149
const location = requestConfig?.location || clientOptions.location;
150+
const defaultTemplate = location === 'global'
151+
? 'https://aiplatform.googleapis.com/v1/projects/{projectId}/locations/{location}/endpoints/openapi'
152+
: 'https://{location}-aiplatform.googleapis.com/v1/projects/{projectId}/locations/{location}/endpoints/openapi';
153+
154+
const baseUrlTemplate = clientOptions.baseUrlTemplate ?? defaultTemplate;
155+
153156
const baseURL = baseUrlTemplate
154157
.replace(/{location}/g, location)
155158
.replace(/{projectId}/g, clientOptions.projectId);

js/plugins/vertexai/src/predict.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ function endpoint(options: {
2323
location: string;
2424
model: string;
2525
}) {
26+
const baseUrl = options.location === 'global'
27+
? 'https://aiplatform.googleapis.com'
28+
: `https://${options.location}-aiplatform.googleapis.com`;
2629
return (
27-
`https://${options.location}-aiplatform.googleapis.com/v1/` +
30+
`${baseUrl}/v1/` +
2831
`projects/${options.projectId}/locations/${options.location}/` +
2932
`publishers/google/models/${options.model}:predict`
3033
);

js/plugins/vertexai/src/vectorsearch/vector_search/upsert_datapoints.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ export async function upsertDatapoints(
4545
): Promise<void> {
4646
const { datapoints, authClient, projectId, location, indexId } = params;
4747
const accessToken = await authClient.getAccessToken();
48-
const url = `https://${location}-aiplatform.googleapis.com/v1/projects/${projectId}/locations/${location}/indexes/${indexId}:upsertDatapoints`;
48+
const baseUrl = location === 'global'
49+
? 'https://aiplatform.googleapis.com'
50+
: `https://${location}-aiplatform.googleapis.com`;
51+
52+
const url = `${baseUrl}/v1/projects/${projectId}/locations/${location}/indexes/${indexId}:upsertDatapoints`;
4953

5054
const requestBody = {
5155
datapoints: datapoints.map((dp) => {

0 commit comments

Comments
 (0)