Skip to main content
There’s a new way to automate the web: by prompting. But a single prompt fails on complicated scripts. Stagehand lets you prompt at multiple levels of granularity—from agents to single actions—and interweave Playwright or traditional frameworks when you need them. Use any major model provider. Get started in 5 minutes.

Quickstart

1

Get your API keys

Your API key and Project ID are displayed in the Dashboard Navigation row:
You’ll also need an LLM API key from your model provider (this quickstart uses Google by default, but you can swap in any supported provider like OpenAI, Anthropic, etc.).
2

Set environment variables

export BROWSERBASE_API_KEY="your-api-key"
export BROWSERBASE_PROJECT_ID="your-project-id"
export MODEL_API_KEY="your-llm-api-key"
3

Install and run

pnpm add @browserbasehq/stagehand
npm pkg set type=module
import { Stagehand } from "@browserbasehq/stagehand";

const stagehand = new Stagehand({
  env: "BROWSERBASE",
  model: {
    modelName: "google/gemini-3-flash-preview",
    apiKey: process.env.MODEL_API_KEY,
  }
});
await stagehand.init();

const page = stagehand.context.pages()[0];
await page.goto("https://news.ycombinator.com");

// Let AI click
await stagehand.act("click on the comments link for the top story");

// Extract structured data
const data = await stagehand.extract("extract the title and points of the top story");
console.log(data);

await stagehand.close();
Save as script.ts, then run:
pnpm dlx tsx script.ts
4

Debug in Session Inspector

See every AI decision in the Stagehand tab of your session at https://browserbase.com/sessions/{session_id}.

Next Steps