Skip to main content
Stagehand is an AI-powered web browsing framework that enables intelligent browser automation through natural language. By integrating Cerebras models, you can leverage ultra-fast inference for web scraping, form filling, automated testing, and complex multi-step workflows that feel responsive and natural.

Prerequisites

Before you begin, ensure you have:
  • Cerebras API Key - Get a free API key here
  • Browserbase Account - Visit Browserbase and create an account to get your API key and Project ID
  • Node.js 20.19 or higher, or Node.js 22.12 or higher - Required by current Stagehand releases
Stagehand works well with fast inference providers like Cerebras. Use gpt-oss-120b for current production browser-automation workloads.

Configure Stagehand with Cerebras

1

Create a new Stagehand project

The fastest way to get started is using the official Stagehand project creator, which sets up everything you need including dependencies:
Then follow the setup instructions:
The project template already includes zod and dotenv as dependencies—no need to install them separately.
2

Configure environment variables

Edit your .env file with your API credentials. You’ll need both Cerebras and Browserbase credentials to enable AI-powered browser automation:
You can find your Browserbase API Key and Project ID in the Browserbase Dashboard under the Overview section.
3

Extract structured data from Hacker News

Let’s start with a practical example—extracting the top stories from Hacker News. This demonstrates how Stagehand can intelligently parse and structure real web content:
We’re using Cerebras’s gpt-oss-120b model here, which excels at structured data extraction tasks due to its strong reasoning capabilities and fast inference speed.
4

Perform actions with natural language

Now let’s use Stagehand’s act() method to interact with a website. This example searches GitHub for “stagehand browserbase” and extracts results:
This example demonstrates Stagehand’s act() method—you describe what you want to do in plain English, and Stagehand figures out how to interact with the page. With Cerebras’s gpt-oss-120b model, these decisions happen in milliseconds.
Best Practice: Use atomic, single-step instructions for reliable automation. Instead of “Click the search box and search for X”, break it into: “Click the search button”, “Type X into the input”, “Press Enter”.
5

Observe and analyze page content

Before taking action, you can use observe() to understand what’s available on a page. This is useful for dynamic decision-making in your automation workflows:
The observe() method analyzes the page and returns suggestions without taking action. Use this when you want to preview options before committing, or when building adaptive automation that responds to different page states.
6

Build multi-step workflows

Combine all three methods—extract(), act(), and observe()—to create sophisticated automation workflows. This example navigates multiple sites and gathers comparative data:
Cerebras’s fast inference enables multi-step workflows to complete quickly, making it practical to build efficient browser automation that navigates multiple sites and makes intelligent decisions at each step.

Why Use Cerebras with Stagehand?

Cerebras’s ultra-fast inference provides several key advantages for browser automation:
  • Real-time responsiveness - Sub-second inference enables agents to react instantly to page changes and dynamic content, making automation feel natural
  • Complex reasoning - Models like gpt-oss-120b handle sophisticated multi-step workflows and make intelligent decisions about ambiguous page elements
  • Cost-effective scaling - Fast inference means lower costs for long-running automation tasks and dramatically reduced API usage compared to slower providers
  • Reliable execution - Low latency reduces timeouts and improves task completion rates, especially for time-sensitive operations and dynamic web applications
  • Better developer experience - Near-instantaneous responses during development make debugging and iteration significantly faster

Key Features

Four Powerful Primitives

Stagehand provides four complementary approaches to browser automation:
  • act() - Execute actions using natural language instructions (click, type, navigate, scroll)
  • extract() - Pull structured data from pages using AI, with Zod schema validation
  • observe() - Discover available actions on any page without executing them
  • agent() - Automate entire workflows autonomously for complex multi-step tasks

Natural Language Control

Describe what you want to do in plain English, and Stagehand’s AI will figure out how to interact with the page. No need for brittle CSS selectors or XPath queries.

Structured Data Extraction

Use Zod schemas to define exactly what data you want to extract, and Stagehand will find and structure it for you with built-in validation.

Works Everywhere

Stagehand v3 is compatible with all Chromium-based browsers. It also offers integrations with Playwright, Puppeteer, and Selenium for developers who want to combine AI-powered automation with traditional browser control.

Available Models

Stagehand works with all Cerebras models for browser automation: Change the modelName parameter when creating your Stagehand instance to switch between models.

Next Steps

Troubleshooting

If Stagehand struggles to locate page elements:
  1. Use atomic instructions - Break complex actions into single steps. Instead of “Click the search box and search for ‘query’”, use three separate calls: “Click the search button”, “Type ‘query’ into the search input”, “Press Enter”
  2. Be more specific in your instructions - Instead of “click the button”, try “click the blue submit button in the bottom right corner”
  3. Wait for dynamic content - Some elements load via JavaScript. Add explicit waits: await new Promise(r => setTimeout(r, 2000));
  4. Verify the element exists - Use observe() first to see what Stagehand detects on the page
  5. Try a different model - gpt-oss-120b generally has better reasoning for complex pages than faster models
Example with explicit waiting:
Stagehand can handle authenticated sessions through Browserbase’s session management. For sites that require authentication:Option 1: Let Stagehand handle the login flow
Option 2: Use Browserbase session persistenceCreate a session that persists authentication:
The session will maintain cookies and authentication state across runs.
  • observe() analyzes the page and returns suggestions without taking action. Use this when you want to preview options before committing, or when building agents that need to dynamically decide their next step.
  • act() executes an action based on your natural language instruction. This performs the actual browser interaction (clicking, typing, scrolling, etc.).
Recommended pattern: Use observe + act for more reliable automation:
Both methods leverage Cerebras’s fast inference to understand page context and determine the best course of action.
Traditional web scraping requires:
  • Writing brittle CSS selectors that break when the page layout changes
  • Manual handling of dynamic content and pagination
  • Complex parsing logic to structure data
Stagehand’s extract() method:
  • Uses AI to intelligently locate data regardless of page structure changes
  • Handles dynamic content automatically by understanding visual context
  • Structures data according to your Zod schema with built-in validation
  • Works across different websites with similar content types without code changes
Example comparison:Traditional scraping:
Stagehand:
The Stagehand version will work even if the CSS classes change.
For rate limits:
  1. Add delays between operations using await new Promise(r => setTimeout(r, 1000))
  2. Use Browserbase’s session management to spread requests across multiple browser contexts
  3. Implement exponential backoff retry logic
  4. Consider using Cerebras’s faster models (gpt-oss-120b) to reduce overall execution time
For CAPTCHAs and bot detection:Browserbase provides features specifically designed to avoid detection:
  • Residential proxies to appear as real users
  • Realistic browser fingerprints
  • Proper browser context management
Example with retry logic:
Choose your model based on the complexity of your automation task:gpt-oss-120b - Best for:
  • Complex, multi-step workflows with decision branching
  • Pages with ambiguous or hard-to-locate elements
  • Tasks requiring sophisticated reasoning about page content
  • When accuracy is more important than speed
gpt-oss-120b - Best for:
  • Structured data extraction from well-formatted pages
  • Balanced performance between speed and reasoning
  • General-purpose automation tasks
  • Great middle-ground for most use cases
gpt-oss-120b - Best for:
  • Simple, repetitive tasks with clear page structure
  • High-volume automation where speed is critical
  • Extracting data from consistent page layouts
  • When you need maximum throughput
Several strategies can help diagnose issues:
  1. Use observe() to see what Stagehand detects:
  1. Enable verbose logging to see Stagehand’s decision-making:
  1. Use Browserbase’s live view to watch the browser in real-time during development. The session URL is logged when you call stagehand.init().
  2. Start with simpler instructions and gradually add complexity to isolate where things break.

Additional Resources


To find navigation and other pages in this documentation, fetch the llms.txt file at: https://inference-docs.cerebras.ai/llms.txt