Skip to main content
🌟 Preview: Browser Functions - Deploy your web automation code directly on Browserbase with browser functions. Scale your act() automations in the cloud with zero infrastructure setup. Reach out to hello@browserbase.com to get beta access.

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.
Every request to this endpoint opens a Browserbase session and spends model tokens. Vercel serves production deployments publicly, so gate the handler before you deploy it. The handlers below reject any request that does not present Authorization: Bearer $CRON_SECRET, the same header Vercel sends on cron invocations.
1

Install Vercel CLI

To download and install Vercel CLI, run one of the following commands:
2

Project layout

Create the structure with:
3

api/run.ts (Node.js runtime)

4

package.json

5

tsconfig.json

6

vercel.json

See Vercel’s configuring functions docs for more details.
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. CRON_SECRET is the secret the handler compares against the Authorization header, and Vercel sends it automatically when a cron job invokes the function:
Using the Model Gateway means BROWSERBASE_API_KEY is the only secret you need to deploy.
See also: Browser Configuration for details on required variables.
9

Test locally

Replicate the Vercel environment locally to exercise your Function before deploying. Run from the project root.
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:
  1. Generate a 32-character secret (you can use openssl rand -hex 16)
  2. Go to your project in Vercel
  3. Navigate to Settings, then Deployment Protection
  4. Add the secret to “Protection Bypass for Automation”
Then invoke the function with the bypass header:
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:

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 maxDuration and/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.