Skip to content

An AI-powered task-management system you can drop into Cursor, Lovable, Windsurf, Roo, and others.

Fix/vertex auth service account (#1542)

Momchil Dimitrov Georgevskib817d6f9f278
diff --git a/.changeset/violet-colts-sip.md b/.changeset/violet-colts-sip.md
new file mode 100644
index 00000000..1d67d4e2
--- /dev/null
+++ b/.changeset/violet-colts-sip.md
@@ -0,0 +1,5 @@
+---
+"task-master-ai": patch
+---
+
+Fixed vertex-ai authentication when using service account and vertex location env variable.
diff --git a/scripts/modules/ai-services-unified.js b/scripts/modules/ai-services-unified.js
index 30e4519e..42f9b028 100644
--- a/scripts/modules/ai-services-unified.js
+++ b/scripts/modules/ai-services-unified.js
@@ -359,10 +359,14 @@ function _getVertexConfiguration(projectRoot, session) {
`Using Vertex AI configuration: Project ID=${projectId}, Location=${location}`
);
+ const credentials = credentialsPath
+ ? { keyFile: credentialsPath }
+ : undefined;
+
return {
projectId,
location,
- ...(credentialsPath && { credentials: { credentialsFromEnv: true } })
+ ...(credentials && { credentials })
};
}
diff --git a/scripts/modules/config-manager.js b/scripts/modules/config-manager.js
index f1ea7e6c..688bbfd6 100644
--- a/scripts/modules/config-manager.js
+++ b/scripts/modules/config-manager.js
@@ -719,11 +719,11 @@ function getVertexProjectId(explicitRoot = null) {
/**
* Gets the Google Cloud location for Vertex AI from configuration
* @param {string|null} explicitRoot - Optional explicit path to the project root.
- * @returns {string} The location or default value of "us-central1"
+ * @returns {string} The location
*/
function getVertexLocation(explicitRoot = null) {
// Return value from config or default
- return getGlobalConfig(explicitRoot).vertexLocation || 'us-central1';
+ return getGlobalConfig(explicitRoot).vertexLocation;
}
function getResponseLanguage(explicitRoot = null) {
diff --git a/src/ai-providers/google-vertex.js b/src/ai-providers/google-vertex.js
index 12662709..fcdfbb09 100644
--- a/src/ai-providers/google-vertex.js
+++ b/src/ai-providers/google-vertex.js
@@ -48,30 +48,71 @@ export class VertexAIProvider extends BaseAIProvider {
return 'GOOGLE_API_KEY';
}
+ /**
+ * API key is optional, Service Account credentials can be used instead.
+ * @returns {boolean}
+ */
+ isRequiredApiKey() {
+ return false;
+ }
+
+ /**
+ * API key or Service Account is mandatory.
+ * @returns {boolean}
+ */
+ isAuthenticationRequired() {
+ return true;
+ }
+
+ /**
+ * Validates that a credential value is present and non-empty.
+ * @private
+ * @param {string|object|null|undefined} value
+ * @returns {boolean}
+ */
+ isValidCredential(value) {
+ if (!value) return false;
+ if (typeof value === 'string') {
+ return value.trim().length > 0;
+ }
+ return typeof value === 'object';
+ }
+
/**
* Validates Vertex AI-specific authentication parameters
* @param {object} params - Parameters to validate
- * @throws {Error} If required parameters are missing
+ * @throws {VertexAuthError|VertexConfigError}
*/
validateAuth(params) {
const { apiKey, projectId, location, credentials } = params;
// Check for API key OR service account credentials
- if (!apiKey && !credentials) {
+ const hasValidApiKey = this.isValidCredential(apiKey);
+ const hasValidCredentials = this.isValidCredential(credentials);
+
+ if (!hasValidApiKey && !hasValidCredentials) {
throw new VertexAuthError(
- 'Either Google API key (GOOGLE_API_KEY) or service account credentials (GOOGLE_APPLICATION_CREDENTIALS) is required for Vertex AI'
+ 'Vertex AI requires authentication. Provide one of the following:\n' +
+ ' • GOOGLE_API_KEY environment variable (typical for API-based auth), OR\n' +
+ ' • GOOGLE_APPLICATION_CREDENTIALS pointing to a service account JSON file (recommended for production)'
);
}
// Project ID is required for Vertex AI
- if (!projectId) {
+ if (
+ !projectId ||
+ (typeof projectId === 'string' && projectId.trim().length === 0)
+ ) {
throw new VertexConfigError(
'Google Cloud project ID is required for Vertex AI. Set VERTEX_PROJECT_ID environment variable.'
);
}
// Location is required for Vertex AI
- if (!location) {
+ if (
+ !location ||
+ (typeof location === 'string' && location.trim().length === 0)
+ ) {
throw new VertexConfigError(
'Google Cloud location is required for Vertex AI. Set VERTEX_LOCATION environment variable (e.g., "us-central1").'
);
@@ -97,7 +138,11 @@ export class VertexAIProvider extends BaseAIProvider {
// Configure auth options - either API key or service account
const authOptions = {};
if (apiKey) {
- authOptions.apiKey = apiKey;
+ // Vercel AI SDK expects googleAuthOptions even when using apiKey for some configurations
+ authOptions.googleAuthOptions = {
+ ...credentials,
+ apiKey
+ };
} else if (credentials) {
authOptions.googleAuthOptions = credentials;
}
@@ -105,7 +150,7 @@ export class VertexAIProvider extends BaseAIProvider {
// Return Vertex AI client
return createVertex({
...authOptions,
- projectId,
+ project: projectId,
location,
...(baseURL && { baseURL }),
...(fetchImpl && { fetch: fetchImpl })