---
title: Integrate BrainTrust with the TestingBot remote browser
description: Add web browsing capabilities to Braintrust with TestingBot's remote
  browser grid.
source_url:
  html: https://testingbot.com/support/ai/integrations/braintrust
  md: https://testingbot.com/support/ai/integrations/braintrust.md
---

# Using BrainTrust with TestingBot

## Braintrust Organization

To get started, make sure you create [a new Braintrust organization](https://www.braintrust.dev/docs/guides/projects). Next, install the necessary dependencies:

## Install dependencies

To use Braintrust with TestingBot, you need to install the following dependencies:

```bash
npm install zod braintrust playwright-core
```

## Variables

To use TestingBot with Braintrust, you need to set the following environment variables: `TESTINGBOT_KEY` and `TESTINGBOT_SECRET`.

You will also need to set up the AI API Key that you are using. Braintrust supports various AI providers, such as OpenAI, Anthropic and others.

## Tools

Braintrust allows you to create [tools](https://www.braintrust.dev/docs/guides/functions/tools) that can be used by agents. In this example, we will create a tool that takes a URL parameter and will use Readability to convert the HTML.

```javascript
import * as braintrust from "braintrust";
import { z } from "zod";
import { chromium } from "playwright-core";

const testingBotKey = process.env.TESTINGBOT_KEY;
const testingBotSecret = process.env.TESTINGBOT_SECRET;

async function loadPage({ url }: { url: string }) {
  const browser = await chromium.connectOverCDP(
    `wss://cloud.testingbot.com/?key=${testingBotKey}&secret=${testingBotSecret}&browserName=chrome&browserVersion=latest`
  );

  const defaultContext = browser.contexts()[0];
  const page = await defaultContext.newPage();

  await page.goto(url);

  const readable = await page.evaluate(async () => {
    const readability = await import('https://cdn.skypack.dev/@mozilla/readability');
    return new readability.Readability(document).parse();
  });
  const text = `${readable?.title ?? ''}\n${readable?.textContent ?? ''}`;

  await browser.close();
  return { page: text };
}

const project = braintrust.projects.create({ name: "TestingBot API Tool" });

project.tools.create({
  handler: loadPage,
  parameters: z.object({
    url: z.string(),
  }),
  returns: z.object({
    page: z.string(),
  }),
  name: "Load page",
  slug: "load-page",
  description: "Load a page from the internet",
  ifExists: "replace",
});
```

## Deploy tool

You can now deploy the tool to Braintrust. You can do this by running the following command:

```bash
npx braintrust push testingbot.ts
```

Once the tool is deployed, you will see the tool listed in the Library's Tools section. Now you can specify a URL and use the "Load page" tool to use the TestingBot tool.

### Looking for more help?

Have questions or need more information? Reach out via email or Slack.

[Email us](https://testingbot.com/contact/new) [Join our Slack](https://join.slack.com/t/testingb0t/shared_invite/zt-3bcw9xch-jk19~6XPs_xBrsAgAedkCw)
