diff --git a/packages/ai/CHANGELOG.md b/packages/ai/CHANGELOG.md index 19086ef7..bb5d4b4e 100644 --- a/packages/ai/CHANGELOG.md +++ b/packages/ai/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Fixed + +- Vertex AI dummy value for `getEnvApiKey()`: Returns `""` when Application Default Credentials are configured (`~/.config/gcloud/application_default_credentials.json` exists) and both `GOOGLE_CLOUD_PROJECT` (or `GCLOUD_PROJECT`) and `GOOGLE_CLOUD_LOCATION` are set. This allows `streamSimple()` to work with Vertex AI without explicit `apiKey` option. + ## [0.34.2] - 2026-01-04 ## [0.34.1] - 2026-01-04 diff --git a/packages/ai/src/stream.ts b/packages/ai/src/stream.ts index b2149579..8f186dad 100644 --- a/packages/ai/src/stream.ts +++ b/packages/ai/src/stream.ts @@ -1,3 +1,6 @@ +import { existsSync } from "node:fs"; +import { homedir } from "node:os"; +import { join } from "node:path"; import { supportsXhigh } from "./models.js"; import { type AnthropicOptions, streamAnthropic } from "./providers/anthropic.js"; import { type GoogleOptions, streamGoogle } from "./providers/google.js"; @@ -41,7 +44,16 @@ export function getEnvApiKey(provider: any): string | undefined { // Vertex AI uses Application Default Credentials, not API keys. // Auth is configured via `gcloud auth application-default login`. - // Don't return a dummy value - require explicit auth.json configuration. + if (provider === "google-vertex") { + const credentialsPath = join(homedir(), ".config", "gcloud", "application_default_credentials.json"); + const hasCredentials = existsSync(credentialsPath); + const hasProject = !!(process.env.GOOGLE_CLOUD_PROJECT || process.env.GCLOUD_PROJECT); + const hasLocation = !!process.env.GOOGLE_CLOUD_LOCATION; + + if (hasCredentials && hasProject && hasLocation) { + return ""; + } + } const envMap: Record = { openai: "OPENAI_API_KEY",