Auto-instrumentation
Auto-instrumentation patches supported AI libraries at startup so every LLM call is captured without wrapping individual clients. This is the recommended way to set up tracing. The examples on this page use OpenAI, but Braintrust supports many providers and frameworks.- TypeScript
- Python
- Ruby
- Go
- Java
- .NET
Auto-instrumentation in TypeScript uses a startup hook that patches supported AI libraries automatically.For local development, the Braintrust Node.js SDK can instead read The nearest file wins. Discovery runs the first time the SDK needs the key, so construction succeeds even when no key is present at startup. This applies to the Node.js SDK only, not the browser, edge, or workerd builds. Add
Set your environment variables
BRAINTRUST_API_KEY from a .env.braintrust file. When no key is set explicitly or through the environment, the SDK searches upward from the working directory to the filesystem root for a file like this:.env.braintrust
.env.braintrust to your .gitignore so the key isn’t committed.Trace your LLM calls
This example traces a single OpenAI call:
Disabling specific integrations
Disabling specific integrations
Auto-instrumentation enables every supported TypeScript integration by default. Disable individual integrations with the The names match the supported libraries, such as
BRAINTRUST_DISABLE_INSTRUMENTATION environment variable, a comma-separated, case-insensitive list of integration names to skip:openai, anthropic, ai-sdk, langchain, and aws-bedrock. See Supported libraries for the full list.To configure the same behavior in code, call configureInstrumentation() before importing any AI SDKs:Run your app
Run with the
--import flag to enable auto-instrumentation:Using a bundler?
Using a bundler?
If you’re using a bundler or a framework that uses one, use the appropriate bundler plugin instead of the
Vite (Next.js (Nuxt (
--import flag. The plugins are included in the Braintrust SDK:| Bundler / Framework | Import path |
|---|---|
| Vite / SvelteKit | braintrust/vite |
| Nuxt | braintrust/vite (client) + braintrust/rollup (Nitro server) |
| Next.js | braintrust/next |
| Webpack | braintrust/webpack |
| esbuild | braintrust/esbuild |
| Rollup | braintrust/rollup |
vite.config.ts):next.config.ts):Wrap your config with wrapNextjsConfigWithBraintrust. It selects the webpack plugin or the Turbopack loader based on the active Next.js build, so the same setup works whether you use Webpack (Next.js 15 and earlier) or Turbopack (Next.js 16+).nuxt.config.ts) — Nuxt uses Vite for the client build and Rollup (via Nitro) for the server build, so both plugins are needed:Node.js version requirements
Node.js version requirements
Requires Node.js 18.19.0+ or 20.6.0+ for
--import flag support. Check with node --version.Streaming responses are fully supported — Braintrust automatically collects streamed chunks and logs the complete response as a single span.
Manual instrumentation
Manual instrumentation lets you explicitly instrument individual client instances. This is an alternative to auto-instrumentation, useful if you prefer explicit control or if auto-instrumentation isn’t supported by the libraries you’re using. Unlike auto-instrumentation, you need to wrap each client instance in your application.- TypeScript
- Python
- Ruby
- Go
- Java
- .NET
Braintrust gateway
The Braintrust gateway provides a unified OpenAI-compatible API for accessing models from many providers. When you call a model through the gateway, your requests are automatically traced — no SDK instrumentation needed. The gateway also provides automatic caching and observability across providers.Supported libraries
To help you log traces, Braintrust’s SDKs support automatic and manual instrumentation for many common libraries. Select a language to get started.- TypeScript
- Python
- Ruby
- Go
- Java
- .NET
| Library | Min. library version | Setup guide |
|---|---|---|
| openai | 4.0.0 | OpenAI |
| @anthropic-ai/sdk | 0.60.0 | Anthropic |
| @anthropic-ai/bedrock-sdk | 0.30.2 | Anthropic |
| @aws-sdk/client-bedrock-runtime | 3.1048.0 | AWS Bedrock |
| @google/genai | 1.0.0 | Gemini |
| @google/adk | 0.6.x, 1.x | Google ADK |
| ai (Vercel AI SDK) | 3.0.0 | Vercel AI SDK |
| @anthropic-ai/claude-agent-sdk | 0.1.0 | Claude Agent SDK |
| @mistralai/mistralai | 1.0.0 | Mistral |
| @openrouter/agent | 0.1.2 | OpenRouter Agent |
| @openrouter/sdk | 0.9.11 | OpenRouter SDK |
| @huggingface/inference | 2.0.0 | Hugging Face |
| cohere-ai | 7.0.0 | Cohere |
| groq-sdk | 1.0.0 | Groq |
| @openai/agents | 0.0.14 | OpenAI Agents SDK |
| @openai/codex-sdk | 0.128.0 | OpenAI Codex SDK |
| @cursor/sdk | 1.0.7 | Cursor SDK |
| @flue/runtime | 0.8.0 | Flue |
| @strands-agents/sdk | 1.0.0 | Strands Agent SDK |
| @langchain/core | 0.3.42 | LangChain |
| genkit | 1.0.0 | Firebase Genkit |
| @mastra/core | 1.20.0 | Mastra |
| eve | 0.20.0 | Eve |
| @earendil-works/pi-coding-agent | 0.79.0 | Pi Coding Agent SDK |
Braintrust also integrates with frameworks like LangChain, LangGraph, AgentScope, CrewAI, LlamaIndex, Mastra, Eve, and OpenTelemetry. Many Python frameworks can be auto-instrumented directly with
braintrust.auto_instrument(), while others still require framework-specific setup. See Integrations.Next steps
- Trace application logic to trace non-LLM code like data retrieval, tool calls, and business logic
- Advanced tracing for distributed tracing, custom rendering, and more
- Explore integrations with AI providers, SDKs, and developer tools