- Stagehand + Vercel AI SDK
Get your API keys
You’ll need credentials from two services:Browserbase: Go to the Dashboard Settings and copy your API key.
Anthropic: Get your API key from the Anthropic Console.Create a

.env.local file with:Create a Stagehand session
Initialize a Stagehand instance connected to Browserbase. Each session gets its own cloud browser with a live debug view.
Node.js
Define research functions
Each research function takes a Stagehand instance, navigates to a source, and uses You can create similar functions for Wikipedia, YouTube, Hacker News, and Google News, each using
stagehand.extract() to pull structured data from the page using AI.Here’s an example that searches DuckDuckGo and visits top results:Node.js
stagehand.extract() with different schemas. See the full template for all five research functions.Create the API route with SSE streaming
Create
app/api/research/route.ts to handle research requests. This route creates parallel Stagehand sessions and streams findings back via Server-Sent Events.Node.js
Full Template on GitHub
Browse the complete source code with frontend components, SSE streaming, and live browser views.
Deploy to Vercel
One-click deploy with automatic Browserbase setup via the Vercel Marketplace.
Expected output
The research route streamsstatus, liveViews, and findings events, followed by complete with the collected findings and summary. Results vary by query and by which sources respond successfully.
Cleanup
The route closes its Stagehand instances and browser connections infinally. Stop the local development server when testing is complete. If session creation or the request fails before cleanup, release remaining sessions using Manage browser sessions. Remove a test deployment if you no longer want the route to accept requests.
Related guides
Functions quickstart
Deploy a browser workflow as a Function.
Session timeouts
Set time limits for browser sessions.