Skip to main content
Braintrust integrates with Anthropic so you can call Claude models from the Braintrust playground, API, and SDKs. Braintrust also traces Anthropic SDK calls from your application, including streaming, prompt caching, server-side tool use, and managed agents, and receives the OpenTelemetry traces that the Claude API exports.

Add Anthropic as an AI provider

To use Anthropic models in the Braintrust playground, API, and gateway, connect Anthropic as a provider in your organization or project AI providers.
  1. Visit Anthropic’s Console and create a new API key.
  2. Go to Settings > Models.
  3. Click Organization provider to make the provider available across every project in the organization. To limit it to the current project, select the Project tab and click Project provider instead.
  4. Under Model providers, click Anthropic.
  5. Choose your authentication method:
    • API key: Paste an Anthropic API key into the field below the authentication options.
      API keys are stored as one-way cryptographic hashes, never in plaintext.
    • Workload identity federation: Exchange a Braintrust-signed OIDC token for an Anthropic access token, instead of storing a long-lived Anthropic API key in Braintrust.
      Workload identity federation is available only for organization-level providers on Braintrust-hosted organizations with the Braintrust gateway enabled. Project-level providers and self-hosted deployments must use API key authentication.
  6. If you chose Workload identity federation, use the setup values shown in Braintrust to configure Anthropic:
    1. Create an Anthropic service account. Copy the svac_... service account ID.
    2. Register the Braintrust issuer in Anthropic. Use the Issuer URL shown in Braintrust, set JWKS source to OIDC discovery, leave Discovery base URL blank, turn Single-use tokens on, and set Max token lifetime to 1 hour.
    3. Create a federation rule in Anthropic. Use the Subject pattern, Expected audience, and Required claims shown in Braintrust. Select the service account from the previous step and the Anthropic workspace Braintrust should use.
    4. Paste the Anthropic IDs back into Braintrust:
    • Federation rule ID: The fdrl_... value in Anthropic’s Workload identity > Rules table.
    • Organization ID: The ID shown on Anthropic’s Organization settings > Organization page.
    • Service account ID: The svac_... ID from the Anthropic service account.
    • Workspace ID: Use default for Anthropic’s default workspace, or the workspace ID selected in the federation rule.
    • Subject suffix: A stable suffix for this Anthropic connection. It must match the final part of the subject pattern used in Anthropic.
    For general Anthropic concepts and Console details, see Anthropic’s workload identity federation docs.
  7. Click Create, or Update when editing an existing provider.

Tracing

Braintrust traces Anthropic calls automatically with the braintrust/hook.mjs import hook, or manually with wrapAnthropic. Either path produces the same spans.Pick the tracing path that fits your application. Auto-instrumentation is the recommended path for most users.

Setup

Install the Braintrust SDK alongside the Anthropic SDK, then configure your API keys.
1

Install packages

2

Get an Anthropic API key

Visit Anthropic’s Console and create a new API key, then add it as a Braintrust AI provider.
3

Set environment variables

.env

Trace your application

To trace Anthropic calls without modifying your application code, run your app with Braintrust’s import hook to patch @anthropic-ai/sdk at startup.
Run with the import hook:
The auto-instrumentation example uses plain JavaScript so node --import can run the file directly. The Braintrust APIs work the same in TypeScript projects. Compile your TypeScript to JavaScript and run the compiled file with the import hook, or run TypeScript directly with a TypeScript loader.
If you’re using a bundler, see Trace LLM calls for plugin and loader setup.

AWS Bedrock

To trace Claude models on AWS Bedrock through Anthropic’s @anthropic-ai/bedrock-sdk, create an AnthropicBedrock client and run with the import hook. The package is built on @anthropic-ai/sdk, so calls appear under anthropic.messages.create with provider: "anthropic" metadata, identical to the direct Anthropic SDK.
Run with the import hook:
To trace the native AWS Bedrock Runtime client (@aws-sdk/client-bedrock-runtime) instead, see AWS Bedrock.

Gateway

To call Anthropic through the Braintrust gateway, point an OpenAI-compatible client at the gateway base URL and use your Braintrust API key for authentication.

Structured outputs

Anthropic supports structured outputs natively via the output_config parameter on the Anthropic SDK, or through the Braintrust gateway using an OpenAI-shaped response_format.

What Braintrust traces

Braintrust emits spans for the Anthropic SDK’s messages API, beta tool runner, and beta sessions API. Message spans capture the input messages, system prompt, model, request parameters, response content, stop reason, and stop sequence. Beta tool-runner spans capture task input, tools, response messages, and aggregated metrics across iterations. Sessions spans capture the turn input, model, and response from anthropic.beta.sessions.turn and anthropic.beta.sessions.thread.turn calls.SpansMetrics

Collect sessions event streams

The anthropic.beta.sessions.turn and anthropic.beta.sessions.thread.turn spans are recorded automatically for non-streaming turns. When you consume a sessions event stream instead, call collectAnthropicSession on the stream to opt it into span collection. The client must be auto-instrumented or wrapped with wrapAnthropic, and collectAnthropicSession returns the same stream unchanged.

Tracing resources

Evals

Evaluations distill the non-deterministic outputs of Anthropic models into an effective feedback loop. The Braintrust Eval function is composed of a dataset of user inputs, a task, and a set of scorers. To learn more about evaluations, see the Experiments guide.

Basic eval setup

Evaluate the outputs of Anthropic models with Braintrust.
Learn more about eval data and scorers.

Use Anthropic as an LLM judge

You can use Anthropic models to score the outputs of other AI systems. This example uses the LLMClassifierFromSpec scorer to score the relevance of the outputs of an AI system.Install the autoevals package to use the LLMClassifierFromSpec scorer.
Create a scorer that uses the LLMClassifierFromSpec scorer to score the relevance of the output. You can then include relevanceScorer as a scorer in your Eval function (see above).

Export OpenTelemetry traces from the Claude API

The Claude API can export OpenTelemetry traces (now in public beta) of your Messages API requests and Claude Managed Agents sessions directly to Braintrust’s OTLP endpoint. Anthropic sends these spans from its servers, so they include work your application can’t observe, such as each model request, server tool use, compaction, and Managed Agents turn. No Braintrust SDK is required.

Add Braintrust as a destination

You need an admin role in your Claude Console organization.
1

Add a destination

A destination is an OTLP trace exporter that Anthropic runs for you. In the Claude Console, open the OpenTelemetry settings page and click Add destination.Set Provider to Braintrust and fill in the form:If your organization has a HIPAA, FERPA, or K-12 data-handling restriction with Anthropic, destinations export only metadata whatever their content mode.
If you’re self-hosting Braintrust, set Provider to Custom and enter:Anthropic appends /v1/traces to the endpoint URL and delivers only to a public hostname over HTTPS on port 443.The x-bt-parent header sets the trace’s parent project or experiment. You can use a prefix like project_id:, project_name:, or experiment_id: here.Custom destinations default to a Maximum content size of 0.75 MB per span. When a span’s content is larger, Anthropic shortens it and sets anthropic.content.truncated to true.
2

Choose which workspaces export

Set Workspaces to All to export spans from every workspace, Selected to export from only the workspaces you pick, or All except to export from every workspace except the ones you pick. To send different workspaces to different Braintrust projects, create one destination for each project.
3

Verify delivery

Send a Messages API request or run a Managed Agents session in a workspace that uses the destination. Confirm that the Delivery column in the Claude Console shows Healthy, then find the trace on the Logs page of your project. Spans from the Claude API have service.name set to claude-platform.If delivery shows Failing with status 401 or 403, check the API key and Project ID.

What Braintrust traces

Braintrust maps the Claude API spans with the GenAI semantic conventions:
  • Model request spans become LLM spans with the model and token metrics, so Braintrust can estimate cost.
  • Tool spans become tool spans named after the tool.
  • With Full content, the system prompt, input messages, and output messages of anthropic.messages.create and anthropic.session.turn spans become the span input and output, and tool arguments become the input of tool spans.
  • gen_ai.conversation.id, which holds the Managed Agents session thread ID, is stored with the span. Other attributes, such as anthropic.session.id, are stored as metadata.
Trace-level token counts and estimated cost add up the metrics of every span in the trace. For a Messages API request, the anthropic.messages.create span and its anthropic.model_request spans report the same tokens, so trace totals count them twice. If your application also sends its Anthropic SDK spans to the same project, those spans report the same tokens again. The Claude API spans of a Managed Agents session report each token once.To count each token once, sum only the anthropic.model_request, anthropic.compaction, and anthropic.session.outcome_evaluation spans:

Connect Claude API spans to your application’s traces

By default, the spans of each request or session form their own trace. To nest them under your application’s spans, pass a W3C traceparent header on your Claude API requests. The Claude SDK does this automatically when you call it inside an active OpenTelemetry span. When the Claude API spans join your trace, their root is your application’s span. Send your application’s spans to the same Braintrust project, either with an OTLP exporter or a Braintrust span processor. Otherwise, the trace has no root span and doesn’t appear on the Logs page.