Skip to main content
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:
gem "braintrust", require: "braintrust/setup"
If you add the SDK to a Gemfile, run:
bundle install

Set an API key

Create an API key in API key settings and set it as an environment variable:
.env
BRAINTRUST_API_KEY="your-api-key"
BRAINTRUST_DEFAULT_PROJECT="My project"
The SDK picks up your API key automatically, so remember to set it locally and in production. Keep it out of version control.

Configure tracing

There are two ways to instrument your app:
  • Auto-instrumentation (recommended): The SDK automatically traces supported AI provider gems.
  • Manual instrumentation: Initialize Braintrust yourself and instrument specific provider clients. Use this approach if you need precise control over when instrumentation runs.
1

Initialize the SDK

Auto-instrumentation patches supported AI libraries before you make provider calls. Pick the setup style that fits your app:
Add the SDK to your Gemfile with require: "braintrust/setup":
Gemfile
# List provider gems before braintrust so Bundler loads them first.
gem "openai"
gem "braintrust", require: "braintrust/setup"
Make sure your application loads Bundler before requiring application code:
app.rb
require "bundler/setup"
Bundler.require
When braintrust/setup loads, it calls Braintrust.init and instruments the supported provider gems already loaded in the process. List provider gems before braintrust in your Gemfile so Bundler.require loads them first. Gems loaded after braintrust/setup runs are not instrumented.
Add the SDK to your Gemfile with require: "braintrust/setup":
Gemfile
gem "braintrust", require: "braintrust/setup"
Rails loads Bundler during boot, so the setup file runs as the app starts. If you prefer an initializer, require the setup file there instead:
config/initializers/braintrust.rb
require "braintrust/setup"
To instrument a Ruby process without changing application source code, install the gem and wrap the command with braintrust exec:
gem install braintrust
braintrust exec -- ruby app.rb
braintrust exec -- bundle exec rails server
Use --only or --except to filter integrations:
braintrust exec --only openai,anthropic -- ruby app.rb
braintrust exec --except ruby_llm -- ruby app.rb
2

Find your AI provider

To learn more about what gets traced, find your AI provider in SDK integrations.

Verify tracing

Run your app and make an AI call. A trace will show up in your Braintrust Logs, usually within seconds.
If traces appear in Braintrust, you’ve successfully set up the SDK.
If your traces don’t appear in Braintrust, see Troubleshooting.

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