[Claimed #1923] feat: Make model api key optional on API#1953
Merged
miguelg719 merged 5 commits intomainfrom Apr 6, 2026
Merged
[Claimed #1923] feat: Make model api key optional on API#1953miguelg719 merged 5 commits intomainfrom
miguelg719 merged 5 commits intomainfrom
Conversation
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>
Contributor
Author
|
This mirrored PR has been merged into |
🦋 Changeset detectedLatest commit: 7170d9e The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
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 |
Contributor
There was a problem hiding this comment.
1 issue found across 2 files
Confidence score: 3/5
- There is a meaningful regression risk:
packages/core/lib/v3/api.tsappears to include Stagehand REST API client/server breaking changes without the required integration coverage underpackages/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.tsandpackages/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
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.
tkattkat
approved these changes
Apr 6, 2026
This was referenced Apr 6, 2026
Merged
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
modelApiKeyis now optional on APItest 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 thex-model-api-keyheader is sent.init(); makemodelApiKeyoptional across types.x-model-api-key; omit modelapiKeyinprepareModelConfigwhen undefined.@browserbasehq/stagehand.Written for commit 7170d9e. Summary will update on new commits. Review in cubic