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.- Visit Anthropic’s Console and create a new API key.
- Go to Settings > AI providers.
- 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.
- Under Model providers, click Anthropic.
-
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.
-
API key: Paste an Anthropic API key into the Secret field.
-
If you chose Workload identity federation, use the setup values shown in Braintrust to configure Anthropic:
-
Create an Anthropic service account. Copy the
svac_...service account ID. - 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.
- 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.
- 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
defaultfor 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.
-
Create an Anthropic service account. Copy the
- Click Save.
Tracing
Braintrust traces Anthropic calls automatically with thebraintrust/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.- Auto-instrumentation
- Manual instrumentation
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.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.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 theoutput_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 BraintrustEval 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.Use Anthropic as an LLM judge
You can use Anthropic models to score the outputs of other AI systems. This example uses theLLMClassifierFromSpec scorer to score the relevance of the outputs of an AI system.Install the autoevals package to use the LLMClassifierFromSpec scorer.LLMClassifierFromSpec scorer to score the relevance of the output. You can then include relevanceScorer as a scorer in your Eval function (see above).