# braintrust

> SDK for integrating Braintrust

Latest version **3.37.2** (published 2026-10-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install braintrust
pnpm add braintrust
yarn add braintrust
bun add braintrust
```

Provides the commands `bt`, `braintrust`.

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; large bundle.

## Facts

| | |
|---|---|
| Version | 3.37.2 |
| Published | 2026-10-09 |
| First published | 2023-07-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 28 |
| Unpacked size | 34.6 MB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 28 |
| Maintainers | braintrust |

## Links

- npm: https://www.npmjs.com/package/braintrust
- Repository: https://github.com/braintrustdata/braintrust-sdk-javascript
- Homepage: https://www.braintrust.dev/docs
- Issues: https://github.com/braintrustdata/braintrust-sdk-javascript/issues
- npm.io page: https://npm.io/package/braintrust

## Dependencies (28)

- [ajv](https://npm.io/package/ajv.md) ^8.20.0
- [cors](https://npm.io/package/cors.md) ^2.8.5
- [uuid](https://npm.io/package/uuid.md) ^11.1.1
- [acorn](https://npm.io/package/acorn.md) ^8.16.0
- [dotenv](https://npm.io/package/dotenv.md) ^16.4.5
- [astring](https://npm.io/package/astring.md) ^1.9.0
- [esbuild](https://npm.io/package/esbuild.md) 0.28.1
- [esquery](https://npm.io/package/esquery.md) ^1.7.0
- [express](https://npm.io/package/express.md) ^5.2.1
- [meriyah](https://npm.io/package/meriyah.md) ^6.1.4
- [argparse](https://npm.io/package/argparse.md) ^2.0.1
- [mustache](https://npm.io/package/mustache.md) ^4.2.0
- [semifies](https://npm.io/package/semifies.md) ^1.0.0
- [unplugin](https://npm.io/package/unplugin.md) ^2.3.5
- [@next/env](https://npm.io/package/@next/env.md) ^14.2.3
- [minimatch](https://npm.io/package/minimatch.md) ^10.2.5
- [pluralize](https://npm.io/package/pluralize.md) ^8.0.0
- [cli-table3](https://npm.io/package/cli-table3.md) ^0.6.5
- [source-map](https://npm.io/package/source-map.md) ^0.7.4
- [termi-link](https://npm.io/package/termi-link.md) ^1.0.1
- [http-errors](https://npm.io/package/http-errors.md) ^2.0.0
- [cli-progress](https://npm.io/package/cli-progress.md) ^3.12.0
- [cjs-module-lexer](https://npm.io/package/cjs-module-lexer.md) ^2.2.0
- [@vercel/functions](https://npm.io/package/@vercel/functions.md) ^1.0.2
- [eventsource-parser](https://npm.io/package/eventsource-parser.md) ^1.1.2
- [zod-to-json-schema](https://npm.io/package/zod-to-json-schema.md) ^3.25.0
- [acorn-import-attributes](https://npm.io/package/acorn-import-attributes.md) ^1.9.5
- [module-details-from-path](https://npm.io/package/module-details-from-path.md) ^1.0.4

## Recent versions

- 3.37.2 (latest) — 2026-10-09
- 3.4.0-canary.20260319.54.g4c1af9e (canary) — 2026-03-23
- 3.3.0-rc.45 (rc) — 2026-03-02
- 2.2.1-rc.0 (next) — 2026-02-08
- 0.4.7 (beta) — 2025-10-21
- 0.4.4-alpha.1 (alpha) — 2025-10-16
- 0.0.141-dev1 (dev) — 2024-07-05
- 3.37.1 — 2026-10-07
- 3.37.0 — 2026-10-05
- 3.36.0 — 2026-10-01
- 3.35.0 — 2026-09-23
- 3.34.0 — 2026-09-17
- 3.33.0 — 2026-09-15
- 3.32.0 — 2026-09-09
- 3.31.0 — 2026-09-09
- … 294 more at https://npm.io/package/braintrust/versions

## README

[![Braintrust](https://raw.githubusercontent.com/braintrustdata/braintrust-sdk-javascript/main/braintrust-logo.svg)](https://www.braintrust.dev/)

# Braintrust JavaScript SDK

[![npm version](https://img.shields.io/npm/v/braintrust.svg)](https://www.npmjs.com/package/braintrust)

An isomorphic JavaScript/TypeScript SDK for logging, tracing, and evaluating AI applications with [Braintrust](https://www.braintrust.dev/). For more details, see the [TypeScript SDK docs](https://www.braintrust.dev/docs/reference/sdks/typescript).

## Installation

Install the SDK:

```bash
npm install braintrust
```

## Quickstart

Run a simple experiment (replace `YOUR_API_KEY` with your Braintrust API key):

```typescript
import * as braintrust from "braintrust";

async function main() {
  const experiment = await braintrust.init("NodeTest", {
    apiKey: "YOUR_API_KEY",
  });

  experiment.log({
    input: { test: 1 },
    output: "foo",
    expected: "bar",
    scores: {
      n: 0.5,
    },
    metadata: {
      id: 1,
    },
  });

  console.log(await experiment.summarize());
}

main().catch(console.error);
```

## Auto-Instrumentation

Braintrust can automatically instrument popular AI SDKs (OpenAI, Anthropic, Vercel AI SDK, and others) to log calls without manual wrapper code.

### Node.js

Use the runtime import hook:

```bash
node --import braintrust/hook.mjs app.js
```

### Bundled Apps

Use a bundler plugin:

Vite:

```ts
import { braintrustVitePlugin } from "braintrust/vite";

export default {
  plugins: [braintrustVitePlugin()],
};
```

Webpack:

```js
const { braintrustWebpackPlugin } = require("braintrust/webpack");

module.exports = {
  plugins: [braintrustWebpackPlugin()],
};
```

esbuild:

```ts
import { braintrustEsbuildPlugin } from "braintrust/esbuild";

await esbuild.build({
  plugins: [braintrustEsbuildPlugin()],
});
```

Rollup:

```ts
import { braintrustRollupPlugin } from "braintrust/rollup";

export default {
  plugins: [braintrustRollupPlugin()],
};
```

If you use TypeScript or other transpilation plugins, place the Braintrust plugin after them so transformed output is instrumented.

For deeper details, see the [auto-instrumentation architecture docs](src/auto-instrumentations/README.md).

## Migration Guides

### Upgrading from 2.x to 3.x

See the [Migrate from v2.x to v3.x guide](https://www.braintrust.dev/docs/reference/sdks/typescript/migrations/v2-to-v3).

In 3.x, browser usage should move to `@braintrust/browser` instead of relying on the legacy `braintrust/browser` path.

### Upgrading from 1.x to 2.x

See the [Migrate from v1.x to v2.x guide](https://www.braintrust.dev/docs/reference/sdks/typescript/migrations/v1-to-v2).

### Upgrading from 0.x to 1.x

See the [Migrate from v1.x to v2.x guide](https://www.braintrust.dev/docs/reference/sdks/typescript/migrations/v0-to-v1).

## Compatibility

The `braintrust` package is compatible with Node.js versions 20.12.0, 22.13.0, for the respective major Node.js release lines and above.

---
_Source: https://npm.io/package/braintrust · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
