Skip to main content
This guide helps you migrate from the legacy Stagehand Python SDK to the new Stainless-based SDK with a Bring Your Own Browser (BYOB) architecture.
The new Python SDK is a pure API client. You manage the browser yourself using Playwright, Selenium, Puppeteer, or any other browser automation tool. The SDK handles only the AI-powered operations.

Overview of Changes

BYOB Architecture

You bring your own browser driver (Playwright, Selenium, etc.). The SDK is now a pure API client that handles AI-powered operations.

Session-Based API

All operations require an explicit session_id. Start a session, perform operations, and end it when done.

Multi-Browser Control

Scale browsers easily and control multiple browsers at once by passing the session ID for each browser you want to control.

Simplified Client

Cleaner initialization with dedicated parameters for API keys and configuration.

Current Limitations

The new SDK does not yet support:
  • Custom Python LLM client classes (e.g., model_client_options)
  • However, we do support custom endpoints like Bedrock or LLM proxies as long as they are OpenAI-API compatible

Step-by-Step Migration

1. Update Imports


2. Client Initialization

Key differences:
  • Configuration options like dom_settle_timeout_ms, self_heal, system_prompt, and verbose are not available in the new SDK
  • model_name is specified when starting a session, not in the config
  • You must connect Playwright separately to interact with the page

3. Navigation


4. Direct Page Interactions (Playwright)

Any direct page manipulation should use Playwright’s native API.
In the old SDK, page was a Stagehand-enhanced Playwright page. In the new SDK, page is a standard Playwright page. Direct Playwright methods work the same way.

5. AI-Powered Actions (act)

Acting on an Observed Element


6. Observing Elements (observe)


7. Extracting Data (extract)

Key difference: The new SDK requires an explicit JSON schema for extraction. This provides better type safety and clearer expectations for the AI model.

8. Closing the Session

Important: Always clean up both Playwright and the Stagehand session. Use a try/finally block to ensure cleanup happens even on errors.

9. Async vs Sync


Complete Migration Example


Quick Reference: Method Mapping


Troubleshooting

Ensure you’re using the correct session_id returned from client.sessions.start().
Make sure your Browserbase API key has the correct permissions and the session is still active.
These are required for all session operations. Use x_language="python" and x_sdk_version="3.0.6" (or the latest version).
The new SDK requires an explicit JSON schema. Make sure your schema matches the expected output structure.

Need Help?

Documentation

Full Stagehand documentation

Browserbase Docs

Browserbase documentation

GitHub Issues

Report issues or get help