Repository navigation
fix: allow custom LLM clients to skip modelApiKey validation in BrowserBase - #966
gingeekrishna wants to merge 1 commit into
Conversation
|
There was a problem hiding this comment.
Greptile Summary
This PR modifies the API key validation logic in lib/api.ts to resolve issue #899, which prevented custom LLM clients like AWS Bedrock from working in the BrowserBase environment. The change updates the StagehandAPI.init() method to conditionally validate API keys based on the provider type.
The implementation works by parsing the provider name from the modelName parameter (e.g., "openai/gpt-4o" -> "openai") and checking if it matches one of the built-in providers: OpenAI, Anthropic, Google, or AISDK. Only these built-in providers now require a modelApiKey to be provided. Custom LLM clients that don't use these providers can skip the validation entirely, allowing them to handle authentication through their own mechanisms.
This change maintains backward compatibility with existing integrations while expanding support for custom LLM providers. The solution is elegant because it leverages the existing modelName parameter format to infer provider type without requiring additional configuration parameters. For custom clients, the modelApiKey defaults to an empty string when not provided, which aligns with how these clients typically handle authentication internally.
The fix integrates well with the existing Stagehand architecture, which already supports custom LLM clients through the modelClientOptions configuration. This change simply removes the artificial barrier that was preventing these custom clients from working in the BrowserBase environment.
Confidence score: 4/5
- This PR is safe to merge with minimal risk as it relaxes validation for a specific use case without compromising security
- Score reflects well-targeted fix that addresses the core issue without breaking existing functionality for built-in providers
- Pay close attention to the provider name parsing logic and ensure custom clients handle authentication properly
1 file reviewed, no comments
|
Thanks for the review! I wanted to provide an update on the current state of this PR. After investigating the merge conflicts, I found that the upstream repo has been significantly restructured into a monorepo (via PR #1117). As a result, Additionally, it appears the upstream has independently addressed the Given this, I'm going to update this PR to:
I'll push the updated changes shortly. If the fix is already fully covered by the upstream changes, I'll close this PR accordingly and reference the upstream fix. |
bb30164 to
dc1445d
Compare
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ustom LLM clients Fixes browserbase#899. Users using custom LLM clients (e.g. AWS Bedrock) with env: "BROWSERBASE" received "StagehandAPIError: modelApiKey is required" in versions prior to 3.4.0. The error was removed in browserbase#1953 (modelApiKey is now optional), but the docs had no entry explaining this to users who encounter the error on older versions or search for it. Added a troubleshooting accordion to the Models page documenting: - What causes the error and when it was fixed - That upgrading to 3.4.0+ resolves it without any code changes - A temporary workaround for users who cannot upgrade immediately Signed-off-by: Radhakrishnan Pachyappan <[email protected]>
|
This PR is from an external contributor and must be approved by a stagehand team member with write access before CI can run. |
There was a problem hiding this comment.
No issues found across 1 file
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Architecture diagram
sequenceDiagram
participant App as Application Code
participant Stagehand as Stagehand SDK
participant Auth as Auth Validator
participant LlmClient as LLM Client
participant BrowserBase as BrowserBase Environment
Note over App,BrowserBase: Custom LLM Client Flow (e.g. AWS Bedrock)
App->>Stagehand: new Stagehand({ env: "BROWSERBASE", llmClient: customLlmClient })
Stagehand->>Auth: validateModelConfig()
alt Built-in Provider (OpenAI/Anthropic/Google/AISDK)
Auth->>Auth: Check modelApiKey required
Auth-->>Stagehand: Error: modelApiKey is required
Stagehand-->>App: StagehandAPIError
else Custom LLM Client (e.g. AWS Bedrock)
Auth->>Auth: Skip API key validation
Auth-->>Stagehand: Validation passed
Stagehand->>LlmClient: Initialize custom client
LlmClient-->>Stagehand: Client ready
Stagehand->>BrowserBase: Use custom client for LLM calls
BrowserBase-->>Stagehand: Response
Stagehand-->>App: Result
end
This PR fixes issue #899 by updating [api.ts] to allow custom LLM clients (such as AWS Bedrock) to skip the [modelApiKey] validation in the BrowserBase environment. The API key requirement is now enforced only for built-in providers (OpenAI, Anthropic, Google, AISDK), enabling custom LLMs to work without an API key. This resolves the error and supports broader LLM integration.