Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/core/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,11 @@ function makeIdStringSchema(orig: z.ZodString): z.ZodString {
* Mapping from LLM provider names to their corresponding environment variable names for API keys.
*/
export const providerEnvVarMap: Partial<
Record<ModelProvider | string, string>
Record<ModelProvider | string, string | Array<string>>
> = {
openai: "OPENAI_API_KEY",
anthropic: "ANTHROPIC_API_KEY",
google: "GOOGLE_GENERATIVE_AI_API_KEY",
google: ["GEMINI_API_KEY", "GOOGLE_GENERATIVE_AI_API_KEY"],
groq: "GROQ_API_KEY",
cerebras: "CEREBRAS_API_KEY",
togetherai: "TOGETHER_AI_API_KEY",
Expand Down Expand Up @@ -435,7 +435,11 @@ export function loadApiKeyFromEnv(
return undefined;
}

const apiKeyFromEnv = process.env[envVarName];
const apiKeyFromEnv = Array.isArray(envVarName)
? envVarName
.map((name) => process.env[name])
.find((key) => key && key.length > 0)
: process.env[envVarName as string];
if (typeof apiKeyFromEnv === "string" && apiKeyFromEnv.length > 0) {
return apiKeyFromEnv;
}
Expand Down
5 changes: 4 additions & 1 deletion packages/core/lib/v3/agent/GoogleCUAClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ export class GoogleCUAClient extends AgentClient {

// Process client options
this.apiKey =
(clientOptions?.apiKey as string) || process.env.GEMINI_API_KEY || "";
(clientOptions?.apiKey as string) ||
process.env.GEMINI_API_KEY ||
process.env.GOOGLE_GENERATIVE_AI_API_KEY ||
"";

// Initialize the Google Generative AI client
this.client = new GoogleGenAI({
Expand Down
17 changes: 13 additions & 4 deletions packages/core/lib/v3/v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,19 @@ export class V3 {
// Ensure API key is set
let apiKey = (baseClientOptions as { apiKey?: string }).apiKey;
if (!apiKey) {
apiKey = loadApiKeyFromEnv(
this.modelName.split("/")[0], // "openai", "anthropic", etc
this.logger,
);
try {
apiKey = loadApiKeyFromEnv(
this.modelName.split("/")[0], // "openai", "anthropic", etc
this.logger,
);
} catch (error) {
this.logger({
category: "init",
message: `Error loading API key for model ${this.modelName}: ${error}. Continuing without LLM client.`,
level: 0,
});
throw error;
}
Comment on lines +207 to +219
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: loadApiKeyFromEnv never throws errors (it returns undefined on failure), making this try-catch unreachable.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/core/lib/v3/v3.ts
Line: 207:219

Comment:
**style:** `loadApiKeyFromEnv` never throws errors (it returns `undefined` on failure), making this try-catch unreachable.

How can I resolve this? If you propose a fix, please make it concise.

}
this.modelClientOptions = {
...baseClientOptions,
Expand Down
5 changes: 4 additions & 1 deletion packages/core/lib/v3Evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ export class V3Evaluator {
this.v3 = v3;
this.modelName = modelName || ("google/gemini-2.5-flash" as AvailableModel);
this.modelClientOptions = modelClientOptions || {
apiKey: process.env.GOOGLE_GENERATIVE_AI_API_KEY || "",
apiKey:
process.env.GEMINI_API_KEY ||
process.env.GOOGLE_GENERATIVE_AI_API_KEY ||
"",
};
}

Expand Down
4 changes: 2 additions & 2 deletions packages/evals/initV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ export async function initV3({
if (process.env.OPENAI_API_KEY)
internalModel = "openai/gpt-4.1-mini" as AvailableModel;
else if (
process.env.GOOGLE_API_KEY ||
process.env.GEMINI_API_KEY ||
process.env.GOOGLE_GENERATIVE_AI_API_KEY
)
internalModel = "google/gemini-2.0-flash" as AvailableModel;
else if (process.env.ANTHROPIC_API_KEY)
internalModel = "anthropic/claude-3-7-sonnet-latest" as AvailableModel;
else
throw new Error(
"V3 init: No AISDK API key found. Set one of OPENAI_API_KEY, GOOGLE_API_KEY/GOOGLE_GENERATIVE_AI_API_KEY, or ANTHROPIC_API_KEY to run CUA evals.",
"V3 init: No AISDK API key found. Set one of OPENAI_API_KEY, GEMINI_API_KEY/GOOGLE_GENERATIVE_AI_API_KEY, or ANTHROPIC_API_KEY to run CUA evals.",
);
}

Expand Down
Loading