Skip to content

Commit 108b73a

Browse files
committed
Support full Google GenAI client options
1 parent 7da5b55 commit 108b73a

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

.changeset/hot-crews-battle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand": patch
3+
---
4+
5+
Support full Google GenAI client options (to e.g. use Vertex AI, or control the region)

lib/llm/GoogleClient.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import {
88
FunctionCall,
99
Schema,
1010
Type,
11+
GoogleGenAIOptions as ClientOptions,
1112
} from "@google/genai";
1213
import zodToJsonSchema from "zod-to-json-schema";
1314

1415
import { LogLine } from "../../types/log";
15-
import { AvailableModel, ClientOptions } from "../../types/model";
16+
import { AvailableModel } from "../../types/model";
1617
import { LLMCache } from "../cache/LLMCache";
1718
import { validateZodSchema, toGeminiSchema, loadApiKeyFromEnv } from "../utils";
1819
import {
@@ -75,15 +76,15 @@ export class GoogleClient extends LLMClient {
7576
enableCaching?: boolean;
7677
cache?: LLMCache;
7778
modelName: AvailableModel;
78-
clientOptions?: ClientOptions; // Expecting { apiKey: string } here
79+
clientOptions?: ClientOptions;
7980
}) {
8081
super(modelName);
8182
if (!clientOptions?.apiKey) {
8283
// Try to get the API key from the environment variable GOOGLE_API_KEY
8384
clientOptions.apiKey = loadApiKeyFromEnv("google_legacy", logger);
8485
}
8586
this.clientOptions = clientOptions;
86-
this.client = new GoogleGenAI({ apiKey: clientOptions.apiKey });
87+
this.client = new GoogleGenAI(clientOptions);
8788
this.cache = cache;
8889
this.enableCaching = enableCaching;
8990
this.modelName = modelName;

types/model.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { ClientOptions as AnthropicClientOptions } from "@anthropic-ai/sdk";
2+
import { GoogleGenAIOptions as GoogleGenAIClientOptions } from "@google/genai";
23
import type { ClientOptions as OpenAIClientOptions } from "openai";
34
import { z } from "zod/v3";
45

@@ -44,7 +45,16 @@ export type ModelProvider =
4445
| "google"
4546
| "aisdk";
4647

47-
export type ClientOptions = OpenAIClientOptions | AnthropicClientOptions;
48+
export type ClientOptions = (
49+
| OpenAIClientOptions
50+
| AnthropicClientOptions
51+
| GoogleGenAIClientOptions
52+
) &
53+
// aisdk client language model options
54+
{
55+
apiKey?: string;
56+
baseURL?: string;
57+
};
4858

4959
export interface AnthropicJsonSchemaObject {
5060
definitions?: {

0 commit comments

Comments
 (0)