Configure Browserbase for Vercel AI
Get your API Key
Go over the Dashboard’s Settings tab:
Then, copy your API key and project ID directly from the input and set the
BROWSERBASE_API_KEY
and BROWSERBASE_PROJECT_ID
environment variables.
Install the Vercel AI, Anthropic, Jsdom, Playwright, and Readability
We use Playwright to navigate the web and extract content, Jsdom to parse the HTML, and Readability to extract the text.
As for the Vercel AI SDK and Anthropic, we use them to generate the prompts and handle the responses.
Create the Session
The session is created to allow the browser to connect to the Browserbase API.
We’ll use the session ID to create a connection to the browser and extract the content from the page.
Create a function to receive and summarize the page content
In this step, we’ll create a function to receive and summarize the page content. Based off a user’s message, we’ll create a search query and extract the content from the page.
We’ll use Jsdom to parse the HTML and Readability to extract the text.
Create the GET request to generate the summary
Next.js provides Route Handlers that can be used to direct incoming requests to the appropriate server components.
Below is an example of a route handler in the App Router, which processes the GET
method using the Browserbase API and returns the text content of the page:
Be sure to store the ANTHROPIC_API_KEY
environment variable in your .env
file.
Congratulations! You’ve successfully created a GET
request to generate the summary of the page content using the Browserbase API and Vercel AI SDK.
In addition to learning how to use the Browserbase API with Vercel AI SDK, we’ve attached a Browserbase x Nextjs template to get you started.
Was this page helpful?