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; }