diff --git a/src/agents/model-auth-env.ts b/src/agents/model-auth-env.ts index 71e5a44d593..5c1d8800f3d 100644 --- a/src/agents/model-auth-env.ts +++ b/src/agents/model-auth-env.ts @@ -70,7 +70,9 @@ export function resolveEnvApiKey( return resolved; } } - return null; + if (normalized !== "google-vertex") { + return null; + } } if (normalized === "google-vertex") { diff --git a/src/agents/model-auth.profiles.test.ts b/src/agents/model-auth.profiles.test.ts index 23819b70cca..99baf9c435e 100644 --- a/src/agents/model-auth.profiles.test.ts +++ b/src/agents/model-auth.profiles.test.ts @@ -827,6 +827,29 @@ describe("getApiKeyForModel", () => { }); }); + it("resolveEnvApiKey('google-vertex') keeps ADC fallback when manifest env candidates are empty", async () => { + const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-google-adc-candidates-")); + const credentialsPath = path.join(tempDir, "adc.json"); + await fs.writeFile(credentialsPath, "{}", "utf8"); + + try { + const resolved = resolveEnvApiKey( + "google-vertex", + { + GOOGLE_APPLICATION_CREDENTIALS: credentialsPath, + GOOGLE_CLOUD_LOCATION: "us-central1", + GOOGLE_CLOUD_PROJECT: "vertex-project", + } as NodeJS.ProcessEnv, + { candidateMap: { "google-vertex": ["GOOGLE_CLOUD_API_KEY"] } }, + ); + + expect(resolved?.apiKey).toBe("gcp-vertex-credentials"); + expect(resolved?.source).toBe("gcloud adc"); + } finally { + await fs.rm(tempDir, { recursive: true, force: true }); + } + }); + it("resolveEnvApiKey('anthropic-vertex') accepts GOOGLE_APPLICATION_CREDENTIALS with project_id", async () => { await expectVertexAdcEnvApiKey({ provider: "anthropic-vertex",