Add web browsing capabilities to Braintrust
Integrate Browserbase with Braintrust
Get your Browserbase API Key
Go over the Dashboard’s Settings tab:
Then copy your API Key directly from the input and
set the BROWSERBASE_API_KEY
environment variable.
Create a Braintrust Organization
Create a new Braintrust organization if you haven’t already.
Install Braintrust, Zod, and Playwright
In addition to Braintrust and Browserbase SDK, we’ll also use Zod for parameter validation.
Set organization-wide variables in Braintrust
We’ll set the BROWSERBASE_API_KEY
environment variable in Braintrust. This will allow us to use the Browserbase SDK to fetch page content.
In addition to setting the BROWSERBASE_API_KEY
environment variable, we’ll also need to upload your AI API keys to Braintrust.
Braintrust supports a variety of AI providers, so you can select the one that best fits your needs. You can set the AI provider in the Braintrust Settings page.
Update your Braintrust project to use Browserbase
Running your existing code in Braintrust works well with Browserbase as a tool.
Tools can be created through code. Let’s define a load function that fetches and returns the page content from a given URL.
Here’s an example of how to modify your existing code to use Browserbase as a tool in Braintrust:
Make sure you set your environment variables BRAINTRUST_API_KEY
,
BROWSERBASE_API_KEY
, BROWSERBASE_PROJECT_ID
locally before proceeding.
Push the function to Braintrust
Now, we’ll use the Braintrust CLI to push the function to Braintrust. This will deploy the function to Braintrust and make it available to use in your project.
Once the command completes, you should see the function listed in the Library’s “Tools” tab. You can now input a URL and use the “Load page” tool to fetch the page content.
You’ve successfully integrated Browserbase with Braintrust! You can use tools to create simple and composable agents that perform tasks like web-scraping, retrieval augmented generation (RAG), API execution, and much more. Learn more about prompting and tool calling in Braintrust Docs.
Was this page helpful?