Repository navigation
feat(sdk-python): add Browserbase client_options to launch and connect - #3119
Merged
miguelg719 merged 9 commits intoOct 7, 2026
Merged
miguelg719 merged 9 commits into
miguelg719 merged 9 commits into
Conversation
Mirror the TypeScript clientOptions: timeout, max_retries, default_headers, and default_query configure the AsyncBrowserbase client used for session and extension management. http_client is omitted because each call closes its client. Removes the pending-Python parity exemption.
3 of 4 tasks
🦋 Changeset detectedLatest commit: d92a4f6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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.
No issues found across 10 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Architecture diagram
sequenceDiagram
participant User as Python Caller
participant Browser as BrowserbaseBrowser
participant Session as BrowserbaseSessionClient
participant Official as OfficialBrowserbaseAPI
participant BBClient as AsyncBrowserbase
participant BBAPI as Browserbase API
Note over User,BBAPI: Client Options Configuration Flow
User->>Browser: launch(api_key, client_options, ...)
Browser->>Browser: Validate browser_settings
Browser->>Browser: NEW: Validate client_options via BrowserbaseClientOptions Pydantic model
alt Valid client_options
Browser->>Session: _create_browserbase_session_client(api_key, base_url, sdk_client_options)
Session->>Official: Create _OfficialBrowserbaseAPI with normalized options dict
else Invalid client_options (e.g. api_key, base_url, negative values)
Browser-->>User: Raise ValidationError (no API call made)
end
Note over User,BBAPI: Launch Path
Browser->>Session: create_session(options)
Session->>Official: create_session(options, metadata, extension_id)
Official->>Official: Build kwargs for session creation
Official->>BBClient: AsyncBrowserbase(**client_options, api_key, base_url)
BBClient->>BBClient: NEW: Apply timeout, max_retries, default_headers, default_query
BBClient->>BBAPI: POST /v1/sessions with configured headers/timeout
BBAPI-->>BBClient: Session created (id, connect_url)
BBClient-->>Official: Return session data
Official-->>Session: Return (session_id, connect_url)
Session-->>Browser: session details
Browser-->>User: ResolvedBrowserSource with CDP URL
Note over User,BBAPI: Connect Path (similar flow)
User->>Browser: connect(api_key, session_id, client_options)
Browser->>Browser: Build and validate BrowserbaseConnectOptions
Browser->>Session: _create_browserbase_session_client(api_key, base_url, client_options)
Session->>Official: Create API wrapper with normalized options
Session->>Official: connect_session(session_id)
Official->>BBClient: AsyncBrowserbase(**client_options, api_key, base_url)
BBClient->>BBAPI: GET /v1/sessions/{session_id}
BBAPI-->>BBClient: Session details
BBClient-->>Official: Retrieved session
Official-->>Session: Return session info
Session-->>Browser: Connection established
Browser-->>User: StagehandBrowser instance
…client-options-python
AsyncBrowserbase.close() closes its HTTP client, so Stagehand's per-call 'async with' would close a caller's client after the first request. When http_client is supplied, build AsyncBrowserbase around it without closing it; Stagehand-created clients are still closed. httpx becomes a direct dependency since it now appears in a public type.
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 10 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Turn on auto-fix | Re-trigger cubic
…client-options-python # Conflicts: # packages/docs/v4/configuration/browser.mdx
4 of 6 tasks
The embedded archive on main is stale (built 7df07ed4 vs embedded 9ddb0309), which fails 'Python wheel smoke' on any Python-touching PR. Regenerated with 'go run ./internal/extensionpack' only; no source changes.
…client-options-python
seanmcguire12
approved these changes
Oct 7, 2026
seanmcguire12
left a comment
Member
There was a problem hiding this comment.
maybe add a docs example using async with httpx.AsyncClient(...)? other than that LGTM
miguelg719
merged commit Oct 7, 2026
1220e0b
into
feat/browserbase-client-options
42 of 43 checks passed
miguelg719
added a commit
that referenced
this pull request
Oct 7, 2026
# why Sibling to #2933. That PR lets callers inject a `Browserbase` SDK instance. This PR takes the alternative approach: Stagehand keeps building the Browserbase client, and callers pass the client's HTTP settings instead. - One `apiKey` authenticates both Browserbase and the Stagehand runtime. An injected client could carry a different key. - Stagehand controls the SDK version and how the client is built. A hand-made or mismatched-version instance can't break calls like `extensions.delete` that depend on SDK-specific options. - Python can offer the same option, which #3119 does. The shared fields (`timeout`, `max_retries`, `default_headers`, `default_query`) exist in both SDKs. The options are nested under `clientOptions` rather than flattened, because `browserbase.launch()` passes unknown keys through to `SessionCreateParams`, which already has a `timeout` field (the session timeout in seconds). # what changed - `clientOptions?: BrowserbaseClientOptions` on `browserbase.launch()` and `browserbase.connect()`. The type is `Pick<ClientOptions, "timeout" | "maxRetries" | "defaultHeaders" | "defaultQuery" | "fetch">`, validated by a strict schema. `apiKey` and `baseURL` are rejected inside it. `BrowserbaseClientOptions` is exported. - In the cross-language parity test, `BrowserbaseConnectOptions.client_options` is temporarily exempt for Python, until the stacked #3119 removes the exemption, and pending for Go. Go talks to Browserbase over its own `net/http` client rather than the official SDK. - Adds docs (`configuration/browser.mdx`, TypeScript only for now) and a minor changeset for `@browserbasehq/stagehand`. # test plan - [x] `tsc --noEmit`, oxfmt, oxlint; sdk-ts unit tests and `rules/ast-grep` parity tests (31 files, 407 tests) - [x] One test builds a real `@browserbasehq/sdk` client with a spy `fetch` and checks that the request URL, `defaultQuery`, `defaultHeaders` and API key are applied - [x] Published-tarball consumer type fixture uses `BrowserbaseClientOptions` - [ ] No live Browserbase session was launched
miguelg719
added a commit
that referenced
this pull request
Oct 7, 2026
) # why Stacked on #3119 (Python), which is stacked on #3118 (TypeScript). Those PRs add Browserbase client options to `browserbase.launch()` / `browserbase.connect()` in TS and Python. This PR adds the Go equivalent, so the three SDKs are at parity again and the parity test no longer needs a Go exemption. # what changed - New `BrowserbaseClientOptions` struct, set as `ClientOptions *BrowserbaseClientOptions` on both `BrowserbaseLaunchOptions` and `BrowserbaseConnectOptions`: - `Timeout time.Duration`: applies to each attempt; 0 keeps the 60s default. - `MaxRetries *int`: nil keeps the default of 2. - `DefaultHeaders map[string]string`, `DefaultQuery map[string]string`. - `HTTPClient *http.Client`: owned by the caller and never modified. - Go talks to Browserbase over its own `net/http` client, so the internal options it already had (HTTP client, max retries) are now exposed, plus headers and query. - The timeout is applied per attempt through the request context, both for the default client and for a client the caller passes in, and it also covers reading the response body. The default client no longer sets `http.Client.Timeout` itself. If an attempt times out, only requests that are safe to resend (retrieve, release, delete) are retried, each with a new deadline. Creates fail immediately. - Negative `Timeout` or `MaxRetries`, invalid header names, and header values containing control characters are rejected before any request is sent. - `ClientOptions` is never sent in the session-create body; a test checks the body contents. - Removes `pendingGoBrowserFields` from the cross-language parity test. - Docs: the client-options section is a TypeScript / Python / Go tab group again. - Adds a minor changeset for `@browserbasehq/stagehand-go`. This PR is the only change in the stack that releases Go. # header precedence Same rule as TS and Python: `DefaultHeaders` override Stagehand's own headers on conflict, including `X-BB-API-Key` and `User-Agent`. Both Browserbase SDKs apply caller default headers last; this was checked in their source (`@browserbasehq/sdk` `index.js` `defaultHeaders`, and the Python `_base_client`). Go still rejects invalid header names or values before sending. # test plan - [x] `go vet`; gofmt (prints nothing); `go test -race` on every package except examples; generator `--check`; `scripts/check-examples.sh` - [x] New `browserbase_client_options_test.go` uses `httptest` servers to cover: - options reaching requests, and later changes to the caller's maps having no effect; - default headers and query on POST and GET, with caller defaults overriding Stagehand's headers (mutation-checked); - `MaxRetries` set to 0 and 1, and the default; - the per-attempt timeout, including a retry getting a new deadline and the deadline covering the response body; - a caller `HTTPClient` being used and left unmodified; - invalid options failing with zero requests reaching the server, on both launch and connect; - full launch and connect through the real factory. - [x] Mutation-checked: with the per-attempt deadline removed, the timeout test fails in about 5s with a clear message. - [x] `rules/ast-grep` parity tests (Go exemption removed), docs tests, the TS suite, oxfmt, oxlint, `check-changesets` - [ ] Plain `go test ./...` fails only because `packages/sdk-go/examples` doesn't build as a single package; that was already the case. CI and the justfile exclude `/examples`. - [ ] No live Browserbase session was launched
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.
why
Stacked on #3118, which adds
clientOptionsto the TypeScript SDK. This PR adds the same option to Python, so callers can tune the Browserbase client Stagehand builds for session management without injecting their own client.what changed
client_options: BrowserbaseClientOptionsonbrowserbase.launch()andbrowserbase.connect(). Fields:timeout(seconds),max_retries,default_headers,default_query,http_client. It's a public TypedDict backed by a strict Pydantic runtime model, so unknown keys such asapi_keyorbase_urlare rejected._OfficialBrowserbaseAPIbuilds everyAsyncBrowserbasewith these options.api_keyandbase_urlstay top-level.http_client: httpx.AsyncClientis the Python counterpart to TSfetch: custom transports, proxies, mocks, request/response hooks. The SDK'sAsyncBrowserbase.close()closes its HTTP client, so for a caller-supplied client Stagehand buildsAsyncBrowserbasearound it without closing it. The caller owns the client and must keep it open untilbrowser.close()returns. Clients Stagehand creates are still closed.httpxbecomes a direct dependency because it now appears in a public type; it was already in the lock file throughbrowserbase.BrowserbaseClientOptionsto the check that keeps Python's input types and runtime models in sync.stagehand-python.test plan
httpx.Client), and building a realAsyncBrowserbasewith the options applied.http_clientwith a mock transport: all four requests (extension upload, session create, release, extension delete) go through it, and it is still open afterwards. With the ownership check disabled, this test fails at session create.ty check, ruff check and ruff format,uv lock --check,generate.py --checkrules/ast-grepparity tests with the Python exemption removed, and the docs tests