Skip to content

[Claimed #1923] feat: Make model api key optional on API#1953

Merged
miguelg719 merged 5 commits intomainfrom
external-contributor-pr-1923
Apr 6, 2026
Merged

[Claimed #1923] feat: Make model api key optional on API#1953
miguelg719 merged 5 commits intomainfrom
external-contributor-pr-1923

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Apr 3, 2026

Mirrored from external contributor PR #1923 after approval by @miguelg719.

Original author: @chromiebot
Original PR: #1923
Approved source head SHA: 49c1be2be843d441e3234f6ab591e2ce5bd84087

@chromiebot, please continue any follow-up discussion on this mirrored PR. When the external PR gets new commits, this same internal PR will be marked stale until the latest external commit is approved and refreshed here.

Original description

why

Introducing Model Gateway on Browserbase

what changed

modelApiKey is now optional on API

test plan


Summary by cubic

Make the model API key optional in StagehandAPIClient.init() so sessions can start without a key, supporting Model Gateway. When provided, behavior is unchanged and the x-model-api-key header is sent.

  • Bug Fixes
    • Remove throw in init(); make modelApiKey optional across types.
    • Conditionally send x-model-api-key; omit model apiKey in prepareModelConfig when undefined.
    • Add unit tests for header behavior and a server integration test for starting without the header; add a patch changeset for @browserbasehq/stagehand.

Written for commit 7170d9e. Summary will update on new commits. Review in cubic

Chromie Bot and others added 2 commits March 30, 2026 16:15
These tests verify that modelApiKey should be optional when calling
init(). Currently they fail because init() throws when modelApiKey
is not provided.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Previously, StagehandAPIClient.init() required modelApiKey and threw
an error if it was not provided. This change makes it optional:

- Remove the required check that threw "modelApiKey is required"
- Conditionally include x-model-api-key header only when key is present
- Update prepareModelConfig to handle undefined modelApiKey gracefully
- Update TypeScript types to reflect optionality

When modelApiKey is provided, behavior is unchanged. When omitted,
the server is expected to handle model authentication on its own.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added external-contributor Tracks PRs mirrored from external contributor forks. external-contributor:mirrored An internal mirrored PR currently exists for this external contributor PR. labels Apr 3, 2026
@github-actions
Copy link
Copy Markdown
Contributor Author

github-actions bot commented Apr 3, 2026

This mirrored PR has been merged into main. The original external PR #1923 is now completed.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 3, 2026

🦋 Changeset detected

Latest commit: 7170d9e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@browserbasehq/stagehand Patch
@browserbasehq/stagehand-evals Patch
@browserbasehq/stagehand-server-v3 Patch
@browserbasehq/stagehand-server-v4 Patch

Not sure what this means? Click here to learn what changesets are.

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

Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

1 issue found across 2 files

Confidence score: 3/5

  • There is a meaningful regression risk: packages/core/lib/v3/api.ts appears to include Stagehand REST API client/server breaking changes without the required integration coverage under packages/server/test (severity 7/10, confidence 9/10).
  • This is likely user-impacting if behavior diverges between client and server, so the PR is not a low-risk merge until integration tests validate the contract change.
  • Pay close attention to packages/core/lib/v3/api.ts and packages/server/test - API contract changes need integration tests to catch breakage across client/server boundaries.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/core/lib/v3/api.ts">

<violation number="1" location="packages/core/lib/v3/api.ts:108">
P1: Custom agent: **Any breaking changes to Stagehand REST API client / server implementation must be covered by an integration test under packages/server/test**

Rule d1dcea1f-c2ef-4728-9dd1-a92623cd374f is violated: this REST API client behavior change (optional `modelApiKey` / conditional `x-model-api-key`) is not covered by a server integration test for session start without a model key.</violation>
</file>
Architecture diagram
sequenceDiagram
    participant User as Client Application
    participant SDK as StagehandAPIClient
    participant API as Stagehand API Server

    User->>SDK: init(params)
    
    Note over SDK: CHANGED: No longer throws if<br/>modelApiKey is missing
    
    SDK->>SDK: prepareModelConfig(model)
    alt apiKey provided in params or instance
        SDK->>SDK: Set apiKey in model configuration
    else apiKey omitted
        SDK->>SDK: NEW: Return model configuration<br/>without apiKey field
    end

    SDK->>SDK: Construct Headers
    opt modelApiKey is present
        Note over SDK: Set x-model-api-key header
    end

    SDK->>API: POST /session/start (fetch)
    Note over SDK,API: Headers: x-api-key, x-bb-session-id, ...
    
    alt modelApiKey provided
        Note over SDK,API: CHANGED: Includes x-model-api-key
    else modelApiKey omitted
        Note over SDK,API: NEW: Excludes x-model-api-key
    end

    API-->>SDK: SessionStartResult (200 OK)
    SDK-->>User: Initialized Instance
Loading

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

@miguelg719 miguelg719 merged commit 5c889df into main Apr 6, 2026
383 of 386 checks passed
@github-actions github-actions bot added external-contributor:completed The mirrored PR has been merged and the external contributor flow is complete. and removed external-contributor:mirrored An internal mirrored PR currently exists for this external contributor PR. labels Apr 6, 2026
miguelg719 pushed a commit that referenced this pull request Apr 8, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @browserbasehq/stagehand@3.2.1

### Patch Changes

- [#1843](#1843)
[`144e18e`](144e18e)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - apply user
defined toolTimeout to all agent tools (other than wait & think tools)

- [#1872](#1872)
[`d3c3736`](d3c3736)
Thanks [@tkattkat](https://github.com/tkattkat)! - Add support for LLM
provider middleware

- [#1953](#1953)
[`5c889df`](5c889df)
Thanks [@github-actions](https://github.com/apps/github-actions)! -
(NEW) Model Gateway: make model api key optional on API

- [#1924](#1924)
[`a1ab39e`](a1ab39e)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix issue
where stagehand could not attach to new tabs that were created manually.

- [#1874](#1874)
[`f3fe7ce`](f3fe7ce)
Thanks [@miguelg719](https://github.com/miguelg719)! - Add headers (LLM)
to ModelConfig

- [#1964](#1964)
[`5fb9785`](5fb9785)
Thanks [@github-actions](https://github.com/apps/github-actions)! -
chore: update examples

- [#1901](#1901)
[`f5d1f1f`](f5d1f1f)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - pass
timeout as timeoutMs in goto()

- [#1858](#1858)
[`8bf5db8`](8bf5db8)
Thanks [@monadoid](https://github.com/monadoid)! - Add explicit SSE
event names for local v3 streaming and update the generated SDK contract
to match.

- [#1899](#1899)
[`6dc2276`](6dc2276)
Thanks [@tkattkat](https://github.com/tkattkat)! - fix: include
screenshot in openai cua agents first message

## @browserbasehq/stagehand-evals@1.1.10

### Patch Changes

- Updated dependencies
\[[`144e18e`](144e18e),
[`d3c3736`](d3c3736),
[`5c889df`](5c889df),
[`a1ab39e`](a1ab39e),
[`f3fe7ce`](f3fe7ce),
[`5fb9785`](5fb9785),
[`f5d1f1f`](f5d1f1f),
[`8bf5db8`](8bf5db8),
[`6dc2276`](6dc2276)]:
    -   @browserbasehq/stagehand@3.2.1

## @browserbasehq/stagehand-server-v3@3.6.2

### Patch Changes

- [#1901](#1901)
[`f5d1f1f`](f5d1f1f)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - pass
timeout as timeoutMs in goto()

- [#1873](#1873)
[`a98801a`](a98801a)
Thanks [@miguelg719](https://github.com/miguelg719)! - Fix schema
parsing bug for Pydantic `.model_json_schema()` on missing nested
references

- [#1858](#1858)
[`8bf5db8`](8bf5db8)
Thanks [@monadoid](https://github.com/monadoid)! - Add explicit SSE
event names for local v3 streaming and update the generated SDK contract
to match.

- [#1937](#1937)
[`249f5ed`](249f5ed)
Thanks [@monadoid](https://github.com/monadoid)! - Improve server-v3
error passthrough for local operation failures

- Updated dependencies
\[[`144e18e`](144e18e),
[`d3c3736`](d3c3736),
[`5c889df`](5c889df),
[`a1ab39e`](a1ab39e),
[`f3fe7ce`](f3fe7ce),
[`5fb9785`](5fb9785),
[`f5d1f1f`](f5d1f1f),
[`8bf5db8`](8bf5db8),
[`6dc2276`](6dc2276)]:
    -   @browserbasehq/stagehand@3.2.1

## @browserbasehq/stagehand-server-v4@3.6.2

### Patch Changes

- Updated dependencies
\[[`144e18e`](144e18e),
[`d3c3736`](d3c3736),
[`5c889df`](5c889df),
[`a1ab39e`](a1ab39e),
[`f3fe7ce`](f3fe7ce),
[`5fb9785`](5fb9785),
[`f5d1f1f`](f5d1f1f),
[`8bf5db8`](8bf5db8),
[`6dc2276`](6dc2276)]:
    -   @browserbasehq/stagehand@3.2.1

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contributor:completed The mirrored PR has been merged and the external contributor flow is complete. external-contributor Tracks PRs mirrored from external contributor forks.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants