Skip to content

fix: allow custom LLM clients to skip modelApiKey validation in BrowserBase - #966

Open
gingeekrishna wants to merge 1 commit into
browserbase:mainfrom
gingeekrishna:fix-stagehand-browsewrbase-899
Open

gingeekrishna wants to merge 1 commit into
browserbase:mainfrom
gingeekrishna:fix-stagehand-browsewrbase-899

Conversation

@gingeekrishna

Copy link
Copy Markdown

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.

@changeset-bot

changeset-bot Bot commented Aug 14, 2025 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 28cb782

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Edit Code Review Bot Settings | Greptile

@gingeekrishna

Copy link
Copy Markdown
Author

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, lib/api.ts no longer exists — the equivalent file is now located at packages/core/lib/v3/api.ts.

Additionally, it appears the upstream has independently addressed the modelApiKey being optional (there's even a dedicated test api-optional-model-api-key.test.ts confirming this). The "modelApiKey is required" error no longer exists in the new api.ts.

Given this, I'm going to update this PR to:

  1. Rebase on the latest main with the new monorepo structure
  2. Apply the fix to packages/core/lib/v3/api.ts if it isn't already fully covered upstream

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.

Copilot AI review requested due to automatic review settings June 2, 2026 22:12
@gingeekrishna
gingeekrishna force-pushed the fix-stagehand-browsewrbase-899 branch from bb30164 to dc1445d Compare June 2, 2026 22:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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]>
@gingeekrishna gingeekrishna reopened this Jun 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR is from an external contributor and must be approved by a stagehand team member with write access before CI can run.
Approving the latest commit mirrors it into an internal PR owned by the approver.
If new commits are pushed later, the internal PR stays open but is marked stale until someone approves the latest external commit and refreshes it.

@github-actions github-actions Bot added external-contributor Tracks PRs mirrored from external contributor forks. external-contributor:awaiting-approval Waiting for a stagehand team member to approve the latest external commit. labels Jun 21, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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
Loading

Re-trigger cubic

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contributor:awaiting-approval Waiting for a stagehand team member to approve the latest external commit. external-contributor Tracks PRs mirrored from external contributor forks.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants