Skip to main content
To use an agent for automatic setup, see the Quickstart.
The .NET SDK is in beta. APIs can change between minor versions.

Sign up

If you don’t have a Braintrust account, sign up for free at braintrust.dev.

Install the SDK

The Braintrust .NET SDK requires .NET 8.0 or later. Add the core package to your project:
Each AI provider has its own integration package, which you add alongside the core package in the steps below.

Set an API key

Create an API key in API key settings and set it as an environment variable, along with the project to log to:
The SDK reads BRAINTRUST_API_KEY from the environment, or from a .env.braintrust file discovered upward from your working directory. Keep your API key out of version control.

Configure tracing

Wrap your AI provider’s client with Braintrust to trace its calls. Select your provider:
1

Add the OpenAI integration package

2

Wrap the OpenAI client

Initialize Braintrust, get an ActivitySource, and wrap the client with BraintrustOpenAI.WrapOpenAI. Every call on the wrapped client is traced.
1

Add the Anthropic integration package

2

Wrap the Anthropic client

Call .WithBraintrust() on the Anthropic client. Once wrapped, every Messages.Create call (including streaming) emits a span.
1

Add the Azure OpenAI integration package

2

Wrap the Azure OpenAI client

Create an instrumented client with WrapAzureOpenAI, then pass your Azure deployment name to GetChatClient.
#skip-compile
For Microsoft Entra ID authentication, pass a TokenCredential to WrapAzureOpenAI in place of the API key. See the Azure AI Foundry integration for details.
1

Add the Agent Framework integration package

2

Add Braintrust tracing to your agent

UseBraintrustTracing instruments the LLM and tool calls on the ChatClientBuilder, and WithBraintrustAgentTracing wraps the agent so each run is captured as a span.
#skip-compile
To learn more about what each integration captures, find your 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