Check out the Browserbase Playbook

We’ve created a Github repository with plenty of ready-to-run guides for Stagehand, including persistent contexts and deploying to Vercel.

1

Prerequisites

Before you begin, you’ll need to install Node.js and NPM. We highly recommend using nvm to manage your Node.js versions, and running on Node version 20+.

We highly recommend using the Node.js runtime environment to run Stagehand scripts, as opposed to newer alternatives like Deno or Bun.

2

Create a new project

You can use npx to create a new project. You should have npx included with npm, the default package manager for Node.js.

npx create-browser-app --example quickstart

To create a blank Stagehand project without the quickstart example, run:

npx create-browser-app

This will create a new directory called my-app, and install the Stagehand package. It will ask you the following questions:

✔ Select AI model to use: OpenAI GPT-4o
✔ Would you like to run locally or on Browserbase? Browserbase
✔ Enable DOM debugging features? Yes
✔ Enable prompt caching? Yes

Large Language Models

In addition, you’ll need either an OpenAI API Key or Anthropic API key. Stagehand allows you to choose between the following models:

We also support GPT-4o-mini, but it is not recommended for production use.

Browserbase

Lastly, if you want access to advanced features like custom contexts, extensions, and captcha solving, you’ll need a Browserbase account. We give you 10 free sessions to get started. You can get your Project ID and API Key from the Browserbase dashboard.

3

Install dependencies and run the script

cd my-app
npm install
npm run start

Use the package manager of your choice to install the dependencies. We also have a postinstall script that will automatically install the Playwright browser with playwright install.

View the code on Github

All of the code for this quickstart is available on Github.