To use an agent for automatic setup, see the Quickstart.
Sign up
If you don’t have a Braintrust account, sign up for free at braintrust.dev.Install the SDK
Add the Braintrust SDK to your project using your preferred package manager:Set an API key
On the Settings > API keys page, create an API key. Then, set it as an environment variable:.env
Configure tracing
There are two ways to instrument your app:- Auto-instrumentation (recommended): Call
auto_instrument()to patch supported AI libraries at startup, tracing your LLM calls without changing each call site. - Manual instrumentation: Initialize Braintrust yourself and wrap specific provider clients. Use this approach if you need precise control or if your provider isn’t supported by auto-instrumentation.
- Auto-instrumentation
- Manual instrumentation
Initialize the logger
Call
init_logger() once, as soon as possible on application startup. The SDK reads BRAINTRUST_API_KEY from the environment configured above.Enable automatic instrumentation
Call You can disable specific integrations by passing For supported integrations, see Trace LLM calls.
auto_instrument() after init_logger() and before creating any AI provider clients. If your app imports provider classes directly, such as from openai import OpenAI, call auto_instrument() before those imports when possible.False for that integration:Log application spans
Braintrust traces your LLM calls automatically, but not the code around them. Decorate any function with@traced to record it as a span: Braintrust captures the function’s arguments as the span’s input and its return value as the output, and nests any traced LLM calls made inside it underneath. This surfaces your application’s structure in the trace, not just isolated model calls.
Flush before exit
For scripts and jobs, callflush() before the process exits so buffered events are sent to Braintrust.
Next steps
Learn more about using the SDK to observe, evaluate, and improve your AI application:- Instrument — trace LLM calls and application logic
- Observe — search and analyze production traces
- Annotate — label traces and build datasets
- Evaluate — measure quality and catch regressions
- Deploy — ship to production with the AI gateway