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 or higher - Stagehand requires a modern Node.js environment
Configure Stagehand with Cerebras
1
Install required dependencies
Install Stagehand and the necessary libraries. We’ll use Zod for defining structured data schemas and dotenv for managing API keys securely:
2
Configure environment variables
Create a
.env file in your project directory 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
Initialize Stagehand with Cerebras
Set up Stagehand to use Cerebras models for AI-powered browser automation. The This configuration initializes Stagehand directly with the Cerebras
modelName configuration allows you to use Cerebras’s ultra-fast inference for all AI operations:gpt-oss-120b model. By specifying the cerebras/ prefix in modelName and providing the API key in the model configuration, Stagehand automatically leverages Cerebras for ultra-fast inference.These examples require valid Browserbase credentials (
BROWSERBASE_API_KEY and BROWSERBASE_PROJECT_ID) to execute. The AI operations (extract(), observe(), act()) will make calls to Cerebras’s API for inference.4
Perform AI-powered browser actions
Now you can use Stagehand’s AI capabilities to interact with web pages intelligently. Here’s a complete example that navigates to a website and extracts information:This example demonstrates key Stagehand capabilities:
- extract() - Pulls structured data from pages using AI
- act() - Executes actions based on natural language instructions (can be added similarly)
- observe() - AI analyzes the page and suggests possible actions (can be added similarly)
Key Features
Ultra-Fast AI Operations
By using Cerebras models, Stagehand’s AI operations (observe, act, extract) run at unprecedented speeds, reducing automation time significantly.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.Structured Data Extraction
Use Zod schemas to define exactly what data you want to extract, and Stagehand will find and structure it for you.Flexible Browser Control
Stagehand provides both AI-powered actions and direct page access, allowing you to combine intelligent automation with precise control when needed.Next Steps
- Explore Stagehand’s full documentation for advanced features
- Try different Cerebras models to optimize for your use case
- Check out Stagehand Github for more automation patterns
- Migrate to GLM4.6: Ready to upgrade? Follow our migration guide to start using our latest model
FAQ
How do I handle rate limits?
How do I handle rate limits?
Cerebras has generous rate limits, but if you’re running many concurrent operations, consider:
- Adding delays between operations
- Using Browserbase’s session management to reuse browser contexts
- Implementing retry logic with exponential backoff
What's the difference between act() and observe()?
What's the difference between act() and observe()?
- observe() analyzes the page and returns suggestions without taking action. Use this when you want to preview options before committing.
- act() executes an action based on your instruction or a suggestion. This performs the actual browser interaction.
Which Cerebras model should I use for browser automation?
Which Cerebras model should I use for browser automation?
For most browser automation tasks, we recommend:
- gpt-oss-120b - Excellent performance for general automation and complex reasoning
- llama-3.3-70b - Strong alternative for multi-step workflows
- qwen-3-32b - Great balance of speed and capability for general automation
- llama3.1-8b - Fastest option for simple, repetitive tasks

