# Braintrust

> Connect Braintrust so errored LLM spans open incidents, prompt version changes join the change timeline, and Ace can pause an alert or scoring rule or restore a prompt version after approval.

Source: https://tryace.dev/docs/integrations/braintrust

Ace reads Braintrust to see which model, span or prompt version changed around an incident, and adds an errored-span alert to each project itself. It can also put a prompt back on the version an environment served before a change.

| | |
| --- | --- |
| Category | LLM observability |
| Ace reads | LLM spans by model, errored spans and their traces, estimated cost, prompt versions per environment, alerts and online scoring rules |
| Ace can change | Pause or resume an alert or online scoring rule, restore a prompt version in an environment, each after approval and only after an admin allows actions |
| Opens incidents | Yes, from errored-span alerts, for workloads that route Braintrust. Prompt and dataset changes join the change timeline. |
| Setup | Service token. Ace adds its alerts to each project itself |

## What it reads
Ace reads the projects in the connection while it investigates a workload that routes its alerts, or that turns Braintrust on under **Observability** in its settings (`https://app.tryace.dev/workloads/<workload-id>/settings/observability`).

- Spans in the incident window by model: spans, errored spans, error rate, p95 latency, prompt and completion tokens, and estimated cost.
- The same for an equal window before the incident, and errors over time, to see when it started.
- The most recent errored spans, with span name and type, model, the error and links to the span and its trace.
- Every span of one trace, with parents, errors, durations, tokens and scores.
- Which prompt version each environment serves, next to each prompt's latest version.
- Alerts and online scoring rules, with their status. Ace marks its own alerts.
- The share of errored spans after a fix, to confirm the problem stopped.

Ace never reads span inputs or outputs. Costs are Braintrust's estimate from token counts and list prices, not a bill.

Braintrust allows about 20 queries a minute per organization and per project, shared with your own API use. Ace makes few queries, and tells the investigation when it reaches the limit. Ace blocks any other Braintrust request before it leaves Ace.

Ace adds the organization, its environments and your projects with their prompts, functions, datasets, online scoring rules and alerts to the Blueprint.

### Cost findings

Every day, Ace checks the last 7 days of up to 10 projects for **Spend on errored LLM calls**: LLM spans that errored but still used tokens. It reports each project from $5 a month, with its calculation, under [**Cost opportunities**](https://app.tryace.dev/settings/integrations#cost-opportunities).

The amount is Braintrust's estimate, not your provider's bill. Ace can't change this in your application. Fix the cause of the errors, or stop retrying calls that fail after the model answered.

## What it can change
Each Braintrust action needs a person's approval every time, whatever your policy. Ace proposes them only after an admin turns on **Actions**. See [Actions and approvals](https://tryace.dev/docs/concepts/actions-and-approvals).

| Action | What it does | Undo |
| --- | --- | --- |
| Braintrust alert pause | Pauses one alert. Braintrust stops evaluating it and sends nothing until it is resumed. | Yes. Resumes it. |
| Braintrust alert resume | Resumes a paused alert from its next window. Windows it skipped while paused are not evaluated. | Yes. Pauses it again. |
| Braintrust online scoring pause | Pauses one online scoring rule, so its scorers stop running and spending. Logs from while it was paused stay unscored. | Yes. Resumes it. |
| Braintrust online scoring resume | Resumes a paused online scoring rule for new logs. | Yes. Pauses it again. |
| Braintrust prompt version restore | Assigns one prompt version to one environment, such as the version it served before a recorded change. Code that loads the prompt by environment gets it on its next load. | Yes. Assigns the version it replaced. |

Each undo is a new action, approved separately.

Safeguards:

- Ace refuses objects in projects outside the connection.
- Ace refuses an alert or rule already in that state, and a prompt version that doesn't exist or is already served.
- Ace rereads the object before it writes, and refuses if anyone paused, resumed or reassigned it since approval.
- A restore into an environment that had no version assigned has no undo, because Braintrust unassigns only from its CLI.
- A pause of one of Ace's own alerts holds. Ace doesn't resume it when it repairs its alerts.

Braintrust doesn't let Ace check what a token may change, so Settings shows **Checked when it runs**. A refused action names the permission it needs.

## What opens an incident

Braintrust alerts open incidents only on workloads that route Braintrust (see [Route alerts to a workload](#4-route-alerts-to-a-workload)).

When you connect, Ace adds an alert to each project. It fires when more than 5% of the project's spans error over 10 minutes, held for 5 minutes, checked every 5 minutes.

- A firing alert opens or joins an incident. Repeated firings of one alert join the same incident.
- Severity rises with how far the value is over the threshold: twice is high, four times is critical, and anything less is medium.
- The incident resolves when the alert recovers.
- An alert you [add by hand](#3-check-alerts) works the same if it sends recovery notifications. A log alert only fires, at medium severity.
- Ace ignores test deliveries, evaluation failures and projects outside the connection.

Ace also adds an environment-change notification to each project.

Dataset versions assigned to an environment reach the change timeline as they happen. Every 2 minutes, Ace reads which prompt version each environment serves, and a change joins the timeline too. Changes never open an incident.

- Braintrust records no time for a prompt assignment, so Ace dates it when it first sees it.
- Ace records the version each environment served before, so it can propose a restore.
- A rollback to a version served before is a change of its own.
- Ace reads 10 environments of up to 500 prompts each.

## Before you start

- The **admin** role in Ace.
- The **Owners** permission group in Braintrust, to create the service token.
- Braintrust Pro or Enterprise, for the **Viewers** and **Engineers** permission groups.

## Credentials and permissions

Ace uses one service token and stores it encrypted. A service token belongs to one organization. A personal API key also works, but acts as its user.

| Credential | Permission group | Why Ace needs it |
| --- | --- | --- |
| Service token (`bt-st-…`) | **Viewers** | Read the organization, projects, logs, prompts, environments, alerts and scoring rules. |
| Same token, for alerts | **Engineers** | Add, repair and remove Ace's alerts, and the secret header they send. |
| Same token, for actions | **Engineers**, or Update on the project | Pause and resume alerts and scoring rules, and assign prompt versions. |

An alert you add by hand sends a token Ace generates in the `x-ace-token` header. It proves a delivery comes from your Braintrust.

## Set up

### 1. Create a service token

1. In [**Settings** > **Service tokens**](https://www.braintrust.dev/app/~/configuration/service-tokens), choose **+ Service token** and name the service account Ace.
2. Assign it the **Engineers** permission group so Ace can set up its alerts and run actions you approve. Assign **Viewers** instead for reads only.
3. Name the token Ace, choose an expiration and choose **Create**.
4. Copy the token. Braintrust shows it only once.

### 2. Connect Braintrust

1. Open [**Settings** > **Integrations** > **Braintrust**](https://app.tryace.dev/settings/integrations/braintrust).
2. Fill in the form:

   | Field | What to enter |
   | --- | --- |
   | **Service token** | The token you created. It starts with `bt-st-`. |
   | **API URL** | Optional. The field adds `https://`. Blank means `api.braintrust.dev`. Enter `api-eu.braintrust.dev` for an EU organization. For your own data plane, copy the API URL from [**Settings** > **Data plane**](https://www.braintrust.dev/app/~/configuration/data-plane). |
   | **Projects** | Optional. Project names, comma-separated. Leave it blank to read every project the token can see. |
   | **Organization** | Only for a personal API key in several organizations. |

3. Select **Connect Braintrust**. Ace checks that the token can read the organization and the projects, and runs one small log query.

With **Projects** blank, Ace saves the ids of every project the token can read when you connect, up to 100. A project renamed later stays in. A project created later isn't read until you save the settings again with **Projects** blank.

Your own data plane must use HTTPS and be reachable from the internet. Ace doesn't connect to private network addresses. To change these settings later, open **Update credentials** (the gear) on the connection card, then select **Save and test**.

### 3. Check alerts

When you connect, Ace adds two alerts to each project: `ace-<id> errored spans` and `ace-<id> environment changes`. They send to Ace with the token in a write-only, encrypted header.

Ace checks them every hour and repairs any that changed. It removes its alerts from a project the connection no longer reads.

The [**Alerts** section](https://app.tryace.dev/settings/integrations/braintrust#alerts) shows what sends to Ace, and counts what Ace couldn't change. An alert someone paused in Braintrust stays paused and counts there.

If the token can't add them in any project, for example because it has only **Viewers**, the section shows **Ace could not set up Braintrust alerts.** with the reason when Ace has one. To add an alert by hand:

1. Copy the webhook URL.
2. Select **Generate a new token** and copy it. Ace shows it once, and its own alerts switch to the new token.
3. In [**Settings** > **Alerts**](https://www.braintrust.dev/app/~/configuration/automations/alerts), choose **Alert** and pick the project.
4. Choose **Time window** and set the calculation and trigger for the alert that should open incidents.
5. Under the action type, choose **Webhook** and paste the URL as **Webhook URL**.
6. In **Webhook settings**, add the header `x-ace-token` with the token as its value.
7. Choose **Encrypt**, then **Save**, then **Create**.

### 4. Route alerts to a workload

In the workload's settings, open **Alerts** (`https://app.tryace.dev/workloads/<workload-id>/settings/alerts`), tick Braintrust under **Sources** and turn on **Investigate alerts**.

### 5. Optional: allow actions

In the [**Actions** section](https://app.tryace.dev/settings/integrations/braintrust#actions), turn the switch **On**. The token needs **Engineers**, or Update on each project.

## Set up with an agent

Copy this prompt into a coding agent, or open it in one with the logos below it. The agent does the Braintrust side in your terminal and asks you for each decision and each step in a browser. See [how agent setup works](https://tryace.dev/docs/integrations#set-up-with-an-agent).

Give your coding agent this prompt:

```text
Help me connect Braintrust to Ace. Read https://tryace.dev/docs/integrations/braintrust/agent.md and follow it step by step. Ask me whenever you need a decision or something only I can do.
```

## Confirm it's working

- The page header shows **Connected**, and the card shows when Ace last synced and how many items it found. **Sync now** checks access again and refreshes the items.
- If a check fails, Ace shows the error. "Projects this key cannot read" names a project in **Projects** the token can't see.
- A personal API key in several organizations fails until you fill in **Organization**.
- The **Alerts** section shows **Not set up**, **Waiting for first alert**, **Verified** or **Last delivery failed**. It turns **Verified** when the first delivery arrives.
- The **Actions** section shows each action as **Checked when it runs**.

## Disconnect

1. In Ace, open [**Settings** > **Integrations** > **Braintrust**](https://app.tryace.dev/settings/integrations/braintrust) and select **Disconnect**, then **Disconnect Braintrust**. Ace deletes its alerts and their secrets from each project. To keep the connection but stop actions, turn off **Actions** instead.
2. If Ace says it couldn't remove them, delete the alerts named `ace-<id>` in [**Settings** > **Alerts**](https://www.braintrust.dev/app/~/configuration/automations/alerts). Delete any alert you added by hand too.
3. In Braintrust, delete the token under [**Settings** > **Service tokens**](https://www.braintrust.dev/app/~/configuration/service-tokens).

## Next steps

- [LangSmith](https://tryace.dev/docs/integrations/langsmith): add workflow runs and traces.
- [LiteLLM](https://tryace.dev/docs/integrations/litellm): add gateway errors and model spend.
- [Actions and approvals](https://tryace.dev/docs/concepts/actions-and-approvals)
- [All integrations](https://tryace.dev/docs/integrations)
