continuedev/continue · error · Error

region and projectId are required for VertexAI (when not usi

Error message

region and projectId are required for VertexAI (when not using express/apiKey mode)

What it means

VertexAI standard mode (no apiKey) requires both region and projectId in setupAuthentication; missing either throws this error from the constructor before any request is made.

Source

Thrown at packages/openai-adapters/src/apis/VertexAI.ts:87

    }
  }

  private setupAuthentication(): void {
    const { apiKey, env } = this.config;
    const { region, projectId, keyFile, keyJson } = env || {};

    // Validate authentication configuration
    if (apiKey) {
      // Express mode validation
      if (region || projectId || keyFile || keyJson) {
        throw new Error(
          "VertexAI in express mode (apiKey only) cannot be configured with region, projectId, keyFile, or keyJson",
        );
      }
    } else {
      // Standard mode validation
      if (!region || !projectId) {
        throw new Error(
          "region and projectId are required for VertexAI (when not using express/apiKey mode)",
        );
      }
      if (keyFile && keyJson) {
        throw new Error(
          "VertexAI credentials can be configured with either keyFile or keyJson but not both",
        );
      }
    }

    // Set up authentication client
    if (keyJson) {
      try {
        const parsed = JSON.parse(keyJson);
        if (!parsed?.private_key) {
          throw new Error("VertexAI: keyJson must contain a valid private key");
        }
        parsed.private_key = parsed.private_key.replace(/\\n/g, "\n");

View on GitHub (pinned to 5522c6f44c)

Solutions

  1. Set both region (e.g. us-central1) and projectId in the Vertex env config
  2. Or switch to express mode by supplying apiKey only
  3. Verify the env object actually reaches the adapter (not just process.env)

Example fix

// before
new VertexAIApi({ env: { keyJson } })
// after
new VertexAIApi({ env: { region: 'us-central1', projectId: 'my-project', keyJson } })
Defensive patterns

Strategy: validation

Validate before calling

if (!cfg.apiKey && (!cfg.env?.region || !cfg.env?.projectId)) throw new Error('region and projectId required for standard mode');

Type guard

const isValidStandardConfig = (c: VertexConfig) => !c.apiKey ? !!(c.env?.region && c.env?.projectId) : true;

Try / catch

try { new VertexAIApi(cfg); } catch (e) { if (e.message.includes('region and projectId are required')) throw new ConfigError('Set VERTEX region+projectId or use apiKey'); throw e; }

Prevention

When it happens

Trigger: Constructing VertexAIApi without apiKey and with env lacking region or projectId (e.g. only keyJson provided).

Common situations: Service-account setups copied from Google examples that omit the region; env var names not matching what the adapter reads; assuming projectId is inferred from the service account (it is not).

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


AI-assisted analysis of continuedev/continue@5522c6f44c (2026-08-27). Data as JSON: /api/errors/d19669c488a78c0c. Report an issue: GitHub.