Installation
Quick Start
Here’s everything you need to get started:Client Setup
Basic Initialization
Environment Variables
Set these in your environment or.env file:
Browser Client Usage
Creating a Browser Client
Thebrowser_client() method creates a BrowserClient that automatically manages browser sessions:
Using BrowserClient
Always use the context manager - it ensures proper cleanup:Page Automation Methods
Thepage object (from Stagehand) provides AI-powered browser automation:
Navigation
AI-Powered Actions
Screenshots
Element Interaction
Waiting
Evaluation
Advanced Examples
Web Scraping Example
Form Filling Example
Multi-Page Workflow
Available Models
The SDK supports multiple AI models for browser automation:Available Providers
Environment Variables
Required:SIMULTANEOUS_PROJECT_ID- Your project UUIDOPENAI_API_KEY- For AI-powered browser actions
SIMULTANEOUS_API_KEY- API key for authenticationANTHROPIC_API_KEY- For Claude models (if usingModels.CLAUDE_3_5)BROWSERBASE_PROJECT_ID- Browserbase project ID (if different from default)BROWSERBASE_REGION- Browserbase region (default: “sfo”)
Error Handling
Choosing a Model
Models.O4_MINI- Fast and cost-effective for simple tasks (recommended)Models.GPT4O- More capable for complex interactionsModels.CLAUDE_3_5- Alternative AI model (requiresANTHROPIC_API_KEY)
Best Practices
- ✅ Always use
async withfor automatic cleanup - ✅ Set
OPENAI_API_KEYenvironment variable - ✅ Use
O4_MINIfor simple tasks to save costs - ✅ Take screenshots for debugging (
await page.screenshot()) - ✅ Wait for elements before interacting (
await page.wait_for_selector())
