Add OpenAI as an AI provider
To use OpenAI models in the Braintrust playground, API, and gateway, connect OpenAI as a provider in your organization or project AI providers.- 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 OpenAI.
-
Choose your authentication method:
-
API key: Visit OpenAI’s API platform, create a new API key, and paste it 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 OpenAI access token, instead of storing a long-lived OpenAI 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: Visit OpenAI’s API platform, create a new API key, and paste it into the Secret field.
-
If you chose Workload identity federation, use the setup values shown in Braintrust to configure OpenAI:
- Create a workload identity provider in OpenAI. Enter a descriptive Name, use the OIDC issuer URL and Audience shown in Braintrust, and leave uploaded JWKS and attribute transformations disabled.
- From the workload identity provider details page, create a mapping. Use
subas the Key and the subject pattern shown in Braintrust as the Value. Add a mapping attribute for each additional claim shown in Braintrust. Choose the OpenAI Project, Service account, and Permissions Braintrust should use. - Paste the OpenAI IDs back into Braintrust:
- Identity provider ID: The workload identity provider ID configured for Braintrust.
- Service account ID: The OpenAI service account ID Braintrust should use.
- Subject suffix: A stable suffix for this OpenAI connection. It must match the final part of the subject pattern used in OpenAI.
- Click Save.
For the GPT-5 family, whether the
temperature parameter is configurable depends on the reasoning effort. GPT-5.1 and later accept temperature only when reasoning effort is set to none. At any higher reasoning effort, and for older GPT-5 models (gpt-5, gpt-5-mini, gpt-5-nano) and GPT-5 Pro, temperature isn’t configurable and is disabled in the Braintrust UI.Tracing
Braintrust traces OpenAI calls automatically with thebraintrust/hook.mjs import hook, or manually with wrapOpenAI. Either path produces the same spans. Auto-instrumentation is the recommended path for most users.Setup
Install the Braintrust SDK alongside the OpenAI SDK, then configure your API keys.1
Install packages
2
Get an OpenAI API key
Visit OpenAI’s API platform and create a new API key, then add it as a Braintrust AI provider.
3
Set environment variables
.env
Auto-instrumentation
To trace OpenAI calls without modifying your application code, initialize Braintrust, create a normal OpenAI client, then run your app with Braintrust’s import hook to patch the OpenAI SDK at startup.1
Initialize Braintrust and call OpenAI
2
Run with the import hook
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.
Manual instrumentation
To trace OpenAI calls manually, wrap your client withwrapOpenAI yourself. Once wrapped, every chat.completions.create call (including streaming) emits a span.Streaming
wrapOpenAI can automatically log metrics like prompt_tokens, completion_tokens, and tokens for streaming LLM calls if the LLM API returns them. Set include_usage to true in the stream_options parameter to receive these metrics from OpenAI.Structured outputs
OpenAI’s structured outputs are supported with the wrapper functions.Function calling and tools
Braintrust supports OpenAI function calling for building AI agents with tools.Gateway
To call OpenAI through the Braintrust gateway, point your client at the gateway base URL and use your Braintrust API key for authentication. Use any supported provider’s SDK to call OpenAI models./embeddings endpoint for generating embeddings. See Generate embeddings for an example.What Braintrust traces
Braintrust instruments the OpenAI client and emits an LLM span per call. Chat and responses spans capture the request messages or input, the response output, and the request parameters as metadata. Embeddings and moderation spans capture their inputs and results.SpansMetrics
Tracing resources
Evals
Evaluations help you distill the non-deterministic outputs of OpenAI models into an effective feedback loop that enables you to ship more reliable, higher quality products. BraintrustEval is a simple function 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 OpenAI models with Braintrust.Use OpenAI as an LLM judge
You can use OpenAI 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 outputs of an AI system. You can then include relevanceScorer as a scorer in your Eval function (see above).