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.

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 > AI providers.
  3. Click Organization provider or Project provider, depending on whether you want the provider to be available across every project in the organization or just the current project.
  4. Under Model providers, click Anthropic.
  5. Choose your authentication method:
    • API key: Paste an Anthropic API key into the Secret field.
      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 Save.

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, then run the compiled file with the import hook.
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 and beta tool runner. 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.SpansMetrics

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).