From f05d64e0738f5733308d79847af29aaebe6658ea Mon Sep 17 00:00:00 2001 From: anuragg-saxenaa Date: Fri, 27 Mar 2026 11:01:47 +0700 Subject: [PATCH] fix: use project-scoped Vertex URL for SA JSON auth and add ?alt=sse for streaming (closes #388) When using SA JSON + Bearer token, Vertex AI requires a project-scoped URL. The old code used the global publishers endpoint which only works with a raw API key, causing RESOURCE_PROJECT_INVALID errors. Changes in open-sse/executors/vertex.js buildUrl(): - SA JSON path: projects/{projectId}/locations/{location}/publishers/google/models/{model}:{action} - Appends ?alt=sse for streaming on SA JSON path - Location defaults to us-central1, overridable via providerSpecificData.location - Raw API key path unchanged (global publishers + ?key= param) Co-authored-by: anuragg-saxenaa Made-with: Cursor --- open-sse/executors/vertex.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/open-sse/executors/vertex.js b/open-sse/executors/vertex.js index 3df8d6b..47d7e89 100644 --- a/open-sse/executors/vertex.js +++ b/open-sse/executors/vertex.js @@ -53,13 +53,22 @@ export class VertexExecutor extends BaseExecutor { return rawKey ? `${url}?key=${rawKey}` : url; } - // Gemini on Vertex: always use global publishers endpoint - // ?alt=sse is required for proper SSE streaming (matches every other Gemini executor) - const action = stream ? "streamGenerateContent?alt=sse" : "generateContent"; - let url = `https://aiplatform.googleapis.com/v1/publishers/google/models/${model}:${action}`; + // Gemini on Vertex + const action = stream ? "streamGenerateContent" : "generateContent"; - // rawKey goes as a query param; use & because ?alt=sse already starts the query string - if (rawKey) url += `&key=${rawKey}`; + if (saJson) { + // SA JSON + Bearer token: must use project-scoped path to avoid RESOURCE_PROJECT_INVALID + const location = credentials?.providerSpecificData?.location || "us-central1"; + let url = `https://aiplatform.googleapis.com/v1/projects/${projectId}/locations/${location}/publishers/google/models/${model}:${action}`; + if (stream) url += "?alt=sse"; + return url; + } + + // Raw API key: use global publishers endpoint with ?key= param + // ?alt=sse is required for proper SSE streaming (matches every other Gemini executor) + let url = `https://aiplatform.googleapis.com/v1/publishers/google/models/${model}:${action}`; + if (stream) url += "?alt=sse"; + if (rawKey) url += stream ? `&key=${rawKey}` : `?key=${rawKey}`; return url; }