Revision 1, checked Oct 18, 2026. Installs exactly @browserbasehq/stagehand 4.2.1, zod 4.4.3, creates the files and adds the key names to your .env. It shows everything first and asks before changing anything.
A Node script that opens a real Chrome window on your machine, goes to a web page, and uses plain-English instructions to pull typed data off it (extract), click something (act), and list what can be clicked (observe). No cloud browser account needed, only a model key.
Prerequisites
Node.js 22.18 or newer and Google Chrome installed on your machine (Stagehand drives it through the Chrome DevTools Protocol).
An OpenAI API key in OPENAI_API_KEY.
Steps
Create a project and install the SDK. Keep Zod on 4.4.x; the docs say newer Zod minors can cause TypeScript errors with extract().
Shell
mkdir my-stagehand-app && cd my-stagehand-apppnpm init -ypnpm install @browserbasehq/stagehand@4.2.1 zod@4.4.3
Create index.ts:
typescript
import { localBrowser, Stagehand } from "@browserbasehq/stagehand";import { z } from "zod/v4";async function main() { const browser = await localBrowser.launch(); try { const stagehand = await Stagehand.create({ browser, model: { modelName: "openai/gpt-5.6-sol", apiKey: process.env.OPENAI_API_KEY, }, }); console.log("Stagehand session started"); try { const [page] = await browser.context.pages(); await page.goto("https://stagehand.dev"); const extractResult = await stagehand.extract( "Extract the value proposition from the page.", z.object({ valueProposition: z.string() }), ); console.log("Extract result:\n", extractResult.data); await stagehand.act("Click the 'Evals' button."); const observeResult = await stagehand.observe("What can I click on this page?"); console.log("Observe result:\n", observeResult.data); } finally { await stagehand.close(); } } finally { await browser.close(); }}main().catch((err) => { console.error(err); process.exit(1);});
Stagehand never reads environment variables for you. The script reads OPENAI_API_KEY itself and passes it in. A local browser cannot use Browserbase's Model Gateway, so you must give it a model and key.
Test it
Shell
export OPENAI_API_KEY="sk-..." # Your model provider API keypnpm dlx tsx index.ts # Run the example script
A Chrome window opens, visits stagehand.dev, and the terminal prints the extracted valueProposition, then the observe result after it clicks Evals.
Not confirmed
The docs do not say how much a run costs in model tokens.
The quickstart uses OpenAI; other providers (ANTHROPIC_API_KEY, GOOGLE_GENERATIVE_AI_API_KEY) are listed on the models page but not shown in this exact script.
Cloud mode (browserbase.launch() with BROWSERBASE_API_KEY) is mentioned but not covered here.
The docs run the script with pnpm dlx tsx and do not pin a tsx version.
Zod is pinned to 4.4.3 (the docs ask for 4.4.x) rather than the newest Zod release.