From bb301648217f5d287203a53eba393001ce138f5f Mon Sep 17 00:00:00 2001 From: RadhaKrishnan Date: Thu, 14 Aug 2025 16:24:24 +0530 Subject: [PATCH] fix: allow custom LLM clients to skip modelApiKey validation in BrowserBase env (closes #899) --- lib/api.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/api.ts b/lib/api.ts index fca3197a8..3b1099bc4 100644 --- a/lib/api.ts +++ b/lib/api.ts @@ -59,10 +59,13 @@ export class StagehandAPI { browserbaseSessionCreateParams, browserbaseSessionID, }: StartSessionParams): Promise { - if (!modelApiKey) { + // Only require modelApiKey for built-in providers, inferred from modelName + const builtInProviders = ["openai", "anthropic", "google", "aisdk"]; + const provider = modelName?.split("/")[0]?.toLowerCase(); + if (!modelApiKey && builtInProviders.includes(provider)) { throw new StagehandAPIError("modelApiKey is required"); } - this.modelApiKey = modelApiKey; + this.modelApiKey = modelApiKey ?? ""; const region = browserbaseSessionCreateParams?.region; if (region && region !== "us-west-2") {