Check out the convex-stagehand repo
Clone the GitHub repo to get started with Stagehand in Convex.
Installation
Install the convex-stagehand component and Zod for schema validation:Configuration
Add the Stagehand component to yourconvex/convex.config.ts:
convex/convex.config.ts
Environment Variables
Set the following environment variables in your Convex Dashboard:| Variable | Description |
|---|---|
BROWSERBASE_API_KEY | Your Browserbase API key |
BROWSERBASE_PROJECT_ID | Your Browserbase project ID |
MODEL_API_KEY | API key for your LLM provider (OpenAI, Anthropic, etc.) |
Basic Usage
Initialize the Client
Create a Stagehand instance in your Convex action:convex/actions.ts
Extract Data
Extract structured data from a web page using natural language instructions and Zod schemas:Perform Actions
Execute browser interactions using plain English:Observe Elements
Identify interactive elements on a page:Run Autonomous Tasks
Use the agent API for complex multi-step workflows:Session Management
For workflows that span multiple operations, you can reuse browser sessions:Model Configuration
The default model isopenai/gpt-4o. You can configure alternative providers:
Requirements
- Convex 1.29.3 or later
- A Browserbase account with API credentials
- An API key from a supported LLM provider (OpenAI, Anthropic, etc.)

