diff --git a/.changeset/shiny-eels-stand.md b/.changeset/shiny-eels-stand.md new file mode 100644 index 000000000..a07c78374 --- /dev/null +++ b/.changeset/shiny-eels-stand.md @@ -0,0 +1,5 @@ +--- +"@browserbasehq/stagehand": patch +--- + +Add support for a custom baseUrl with google cua client diff --git a/packages/core/lib/v3/agent/GoogleCUAClient.ts b/packages/core/lib/v3/agent/GoogleCUAClient.ts index 968a542a4..9630472b4 100644 --- a/packages/core/lib/v3/agent/GoogleCUAClient.ts +++ b/packages/core/lib/v3/agent/GoogleCUAClient.ts @@ -6,6 +6,7 @@ import { FunctionCall, GenerateContentConfig, Tool, + GoogleGenAIOptions, } from "@google/genai"; import { LogLine } from "../types/public/logs"; import { @@ -42,6 +43,7 @@ export class GoogleCUAClient extends AgentClient { "ENVIRONMENT_BROWSER"; private generateContentConfig: GenerateContentConfig; private tools?: ToolSet; + private baseURL?: string; constructor( type: AgentType, modelName: string, @@ -58,11 +60,14 @@ export class GoogleCUAClient extends AgentClient { process.env.GEMINI_API_KEY || process.env.GOOGLE_GENERATIVE_AI_API_KEY || ""; + this.baseURL = clientOptions?.baseURL as string | undefined; // Initialize the Google Generative AI client - this.client = new GoogleGenAI({ + const genAIOptions: GoogleGenAIOptions = { apiKey: this.apiKey, - }); + ...(this.baseURL ? { httpOptions: { baseUrl: this.baseURL } } : {}), + }; + this.client = new GoogleGenAI(genAIOptions); // Get environment if specified if ( @@ -92,6 +97,7 @@ export class GoogleCUAClient extends AgentClient { // Store client options for reference this.clientOptions = { apiKey: this.apiKey, + ...(this.baseURL ? { baseURL: this.baseURL } : {}), }; // Initialize tools if provided