Deploy on Vercel
Run Stagehand on Browserbase inside a Vercel Function. This guide shows a minimal HTTP endpoint you can call directly or on a schedule.1
Install Vercel CLI
To download and install Vercel CLI, run one of the following commands:
2
Project layout
- TypeScript
- Python
- Go
- TypeScript
- Python
- Go
3
api/run.ts (Node.js runtime)
- TypeScript
- Python
- Go
4
package.json
- TypeScript
- Python
- Go
5
tsconfig.json
- TypeScript
- Python
- Go
6
vercel.json
- TypeScript
- Python
- Go
7
Link your project
Link your local folder to a Vercel project before configuring environment variables:
8
Environment variables
Never commit secrets. Add variables via the Vercel CLI, then read them in your handler and pass them where you launch the browser and create the Stagehand client. See also: Browser Configuration for details on required variables.
CRON_SECRET is the secret the handler compares against the Authorization header, and Vercel sends it automatically when a cron job invokes the function:9
Test locally
Replicate the Vercel environment locally to exercise your Function before deploying. Run from the project root.
- TypeScript
- Python
- Go
10
Deploy
11
Execute the function
Every request needs
Authorization: Bearer $CRON_SECRET. Requests without it get a 401 and never reach Browserbase.12
Configure protection bypass for automation
If the deployment also sits behind Vercel Deployment Protection, create a Protection Bypass for Automation so scripted callers can reach it:
- Generate a 32-character secret (you can use
openssl rand -hex 16) - Go to your project in Vercel
- Navigate to Settings, then Deployment Protection
- Add the secret to “Protection Bypass for Automation”
13
Optional: cron on Vercel
Hit the same endpoint on a schedule by extending
vercel.json. Cron invocations arrive as GET requests carrying Authorization: Bearer $CRON_SECRET, so the handler’s secret check passes without extra configuration:- TypeScript
- Python
- Go
Features
- No local browsers needed with a Browserbase browser. Browserbase provides the browsers, so your function ships without a Chrome binary.
- Fast functionality: Offload browser work to Browserbase and return JSON promptly.
- Long-running tasks: Raise
maxDurationand/or consider Edge runtime limits depending on plan. - Cheap repeat runs: Turn on server-side caching so scheduled invocations replay recorded actions instead of paying for inference every hour.

