fix(ai): add vertex ai dummy value for configured credentials

This commit is contained in:
Anton Kuzmenko 2026-01-04 12:59:19 -08:00
parent 024ec33bf2
commit a3f30e085a
2 changed files with 17 additions and 1 deletions

View file

@ -2,6 +2,10 @@
## [Unreleased]
### Fixed
- Vertex AI dummy value for `getEnvApiKey()`: Returns `"<authenticated>"` 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

View file

@ -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 "<authenticated>";
}
}
const envMap: Record<string, string> = {
openai: "OPENAI_API_KEY",