Tracing
Tracing records what your application does as spans you can inspect in Braintrust. The recommended way to capture AI calls is auto-instrumentation: use thetrace/contrib packages to instrument supported provider libraries, either at build time with Orchestrion or with runtime middleware (see Go SDK integrations). Tracing is built on OpenTelemetry, so you trace your own code with the standard OpenTelemetry API. The APIs below create the client, trace your own code, and link to your traces.
braintrust.New
Creates a Braintrust client and configures the OpenTelemetry pipeline that exports spans to Braintrust. Call it once on startup, passing your TracerProvider and any options.
#skip-compile
(*braintrust.Client, error).
braintrust.New reads BRAINTRUST_API_KEY from the environment. Configure the rest with functional options or environment variables (see Configuration).
Because tracing is built on OpenTelemetry, you trace your own application code with the standard OpenTelemetry API, and traced AI calls nest under your spans.
#skip-compile
Client.Permalink
Builds a Braintrust UI URL for a span, so you can link straight to a trace from your own logs or app.
#skip-compile
string.
Evaluations
An evaluation runs your task over a set of cases, scores each output, and logs the results to an experiment, which is how you measure quality and catch regressions as you change prompts or models. The recommended pattern is to define an eval once withbraintrust.NewEval, then call Run with any dataset. The same definition works for local runs, bt eval <dir> runs from the command line, and remote eval runs triggered from the playground.
braintrust.NewEval
Creates a runnable *eval.Eval by combining a client with an eval definition. Call Run on it to execute the evaluation.
#skip-compile
*eval.Eval[I, R]. Run returns (*eval.Result, error).
eval.Eval[I, R] fields:
Name(string, required): eval name, used as the default experiment name and as the registration key for remote evals.Task(eval.TaskFunc[I, R], required): the function under evaluation. Wrap a plainfunc(ctx, input) (output, error)witheval.T, or useeval.TaskWithHooksif the task needs to read parameters or other run metadata.Scorers([]eval.Scorer[I, R]): scoring functions applied to each case. ProvideScorers,Classifiers, or both.Classifiers([]eval.Classifier[I, R]): classifiers applied to each case.ParameterSchema(eval.ParameterSchema): declares parameters the eval accepts. Each entry becomes a configurable control in the Braintrust playground (see Parameters).Dataset(eval.Dataset[I, R]): default dataset for the eval. A playground run supplies its own dataset and overrides this.bt eval <dir>and a directRuncall use it when no dataset is supplied at call time.ProjectName(string): Braintrust project for this eval. Falls back to the client’s configured project.
eval.RunOpts[I, R] fields (passed to Run):
Dataset(eval.Dataset[I, R]): test cases for this run. Defaults toEval.Dataset; required if the eval defines none.Experiment(string): experiment name. Defaults toEval.Name.ProjectName(string): overrides the project for this run.ProjectID(string): identifies the project by ID instead of by name. Takes precedence overProjectNamewhen set.Tags([]string): tags to apply to the experiment.Metadata(eval.Metadata): metadata to attach to the experiment.Update(bool): append to an existing experiment with the same name. Defaults tofalse.Parallelism(int): number of goroutines. Defaults to1.Quiet(bool): suppress result output. Defaults tofalse.
braintrust.NewEvaluator
Creates an evaluator for input type I and result type R, bound to a client. Call Run on it with the cases, task, and scorers to execute the evaluation and log an experiment.
#skip-compile
*eval.Evaluator[I, R]. Run returns (*eval.Result, error).
eval.Opts[I, R] fields:
Experiment(string, required): experiment name.Dataset(eval.Dataset[I, R], required): the cases to run. Build an in-memory one witheval.NewDataset(see Datasets).Task(eval.TaskFunc[I, R], required): the function under test. Wrap a plainfunc(ctx, input) (output, error)witheval.T.Scorers([]eval.Scorer[I, R]): scorers to apply to each case. ProvideScorers,Classifiers, or both.Classifiers([]eval.Classifier[I, R]): classifiers to apply to each case. ProvideScorers,Classifiers, or both.ProjectName(string): project to log to. Defaults to the client’s configured project.ProjectID(string): project ID. When set, takes precedence overProjectNameand uses the project as-is rather than creating it.Tags([]string): tags to apply to the experiment.Metadata(eval.Metadata): metadata to attach to the experiment.Update(bool): append to an existing experiment with the same name. Defaults tofalse.Parallelism(int): number of goroutines. Defaults to1.TrialCount(int): number of times to run each case. Defaults to1.Quiet(bool): suppress result output. Defaults tofalse.
eval.NewScorer
Creates a scorer from a function. A scorer measures how good the task’s output is, returning one or more named scores per case.
#skip-compile
eval.Scorer[I, R]. The score function receives an eval.TaskResult[I, R] (with Input, Output, Expected, and Metadata) and returns eval.Scores. Use eval.S to build a single score.
eval.NewClassifier
Creates a classifier from a function. Use a classifier to categorize output instead of scoring it numerically.
#skip-compile
eval.Classifier[I, R].
eval.TaskWithHooks
Creates a task function that receives *eval.TaskHooks, which gives access to parameters, metadata, tags, and the current spans. Use it when your task needs to read parameter values that were configured in the playground or passed via RunOpts.Parameters.
#skip-compile
eval.TaskFunc[I, R]. The hooks give access to Parameters, Metadata, Tags, TrialIndex, TaskSpan, and EvalSpan. Use eval.T instead when the task doesn’t need hooks.
Parameters
Parameters let you declare configurable options on an eval. When the eval runs from the Braintrust playground via a remote eval, each declared parameter becomes a control in the UI. For a local run, the task receives the declared defaults. Declare parameters witheval.ParameterSchema on the eval.Eval definition:
#skip-compile
eval.ParameterSchema is map[string]eval.ParameterDef. Each eval.ParameterDef has:
Type(string):"model"renders a model picker."prompt"renders a prompt editor."string","number","integer","boolean"render plain inputs. Use theeval.ParameterTypeModelandeval.ParameterTypePromptconstants for the two dedicated controls.Default(any): used when no value is supplied for this run. This is also what a local run sees.Description(string): shown alongside the control in the playground.
eval.Parameters (the resolved values, available as hooks.Parameters) has typed accessors that never panic on a type mismatch:
Parameters.String(name)→stringParameters.Int(name)→intParameters.Float64(name)→float64Parameters.Bool(name)→boolParameters.Get(name)→(any, bool)Parameters.Has(name)→bool
Remote evals
Remote evals let the Braintrust playground trigger your Go eval code on your own infrastructure. Theevalrunner package turns a Go binary into a target that the bt CLI can drive.
evalrunner.New and evalrunner.RegisterEval
Create a runner and register your evals. The runner reads the bt environment variables, dispatches the right eval, and streams results back.
#skip-compile
evalrunner.New accepts evalrunner.Option values:
evalrunner.WithLogger(l logger.Logger): custom logger. Logs go to stderr. Stdout is reserved for thebtprotocol.evalrunner.WithTracerProvider(tp *sdktrace.TracerProvider): shared OpenTelemetry provider. Supply one when instrumented code (LLM clients, custom spans) should appear in the same trace as eval spans. When nil, a per-run provider is created and shut down on exit.
evalrunner.RegisterEval[I, R any](r *Runner, ev *eval.Eval[I, R]) registers an eval by its Name. Registering two evals under the same name replaces the first. evalrunner.Main(r *Runner) dispatches and exits. Use evalrunner.Run(ctx, r) instead if you need to handle the error yourself.
r.Mode() returns the current evalrunner.Mode: ModeList, ModeEval, ModeBatch, or ModeInspect. Use it to skip expensive setup when bt only wants the list of registered evals:
#skip-compile
Datasets
A dataset is the set of cases an evaluation runs against. Define cases inline in memory, or manage datasets in Braintrust through the API client.eval.NewDataset
Groups cases into an in-memory dataset you pass to Evaluator.Run, as an alternative to loading one from Braintrust.
#skip-compile
eval.Dataset[I, R].
Each eval.Case[I, R] has an Input and optional Expected, Tags, Metadata, and TrialCount.
Attachments
When your traces involve binary content like images or PDFs, log it as an attachment so it appears in Braintrust instead of as an opaque blob. When you trace AI calls, Braintrust automatically converts base64 attachments in provider messages into uploaded attachments, so you rarely need the APIs below for instrumented calls. Reach for them when you’re attaching binary content to a span yourself.attachment.From*
Creates an attachment from bytes, a file, or a URL.
#skip-compile
attachment.FromBytes(contentType string, data []byte)→*attachment.Attachment: from raw bytes.attachment.FromFile(contentType string, path string)→(*attachment.Attachment, error): reads a file.attachment.FromURL(url string)→(*attachment.Attachment, error): fetches a URL and uses the response content type.attachment.FromReader(contentType string, r io.Reader)→*attachment.Attachment: from anio.Reader.
API client
For direct access to the Braintrust REST API, use theapi package. Reach for it to manage projects, experiments, datasets, and functions programmatically, beyond what the higher-level APIs above cover.
api.NewClient
Creates a REST API client from an API key.
#skip-compile
*api.API.
Namespaces:
client.Projects(): project management.client.Experiments(): experiment management.client.Datasets(): dataset management. Methods includeCreate,Insert,InsertEvents,Delete,Fetch, andQuery.client.Functions(): function management, includingInvoke(ctx, functionID, input)to call a deployed function.
Configuration
Configure the client with functional options passed tobraintrust.New, or with environment variables.
#skip-compile
braintrust.WithAPIKey(apiKey string): API key. Defaults toBRAINTRUST_API_KEY.braintrust.WithAPIURL(apiURL string): Braintrust API URL.braintrust.WithAppURL(appURL string): Braintrust app URL, used for permalinks.braintrust.WithOrgName(orgName string): organization name, useful when credentials can access multiple orgs.braintrust.WithProject(projectName string): project that receives exported spans.braintrust.WithProjectID(projectID string): project ID. Takes precedence over the project name.braintrust.WithBlockingLogin(enabled bool): log in synchronously duringNewinstead of in the background.braintrust.WithExporter(exporter trace.SpanExporter): supply a custom span exporter. Intended for testing.braintrust.WithEnableTraceConsoleLog(enabled bool): print spans to the console.braintrust.WithFilterAISpans(enabled bool): export only AI-related spans.braintrust.WithEnvironment(environmentType string, name ...string): set span-origin environment provenance. Overrides auto-detection from CI and server environment variables.
Environment variables
BRAINTRUST_API_KEY(required): Braintrust API key.BRAINTRUST_API_URL: Braintrust API URL. Defaults tohttps://api.braintrust.dev.BRAINTRUST_APP_URL: Braintrust app URL, used for permalinks. Defaults tohttps://www.braintrust.dev.BRAINTRUST_DEFAULT_PROJECT: project that traced spans route to. Defaults todefault-go-project.BRAINTRUST_DEFAULT_PROJECT_ID: project UUID. Takes precedence over the project name.BRAINTRUST_ORG_NAME: organization name, useful when credentials can access multiple orgs.BRAINTRUST_OTEL_FILTER_AI_SPANS: set totrueto export only AI-related spans.BRAINTRUST_ENABLE_TRACE_CONSOLE_LOG: set totrueto print spans to the console.BRAINTRUST_OTEL_ENABLE_BUILTIN_ADK_TRACES: set totrueto export spans from Google ADK’s built-in telemetry. Defaults tofalse.BRAINTRUST_AUTO_CONVERT_AI_ATTACHMENTS: scan spans for base64 attachments and upload them to object storage. Defaults totrue; set tofalseto disable.BRAINTRUST_DEBUG: set totrueto enable SDK debug logging. Defaults tofalse.BRAINTRUST_BLOCKING_LOGIN: set totrueto log in synchronously at startup.BRAINTRUST_ENVIRONMENT_TYPE: environment type for span-origin provenance (for example,ciorserver). Detected automatically from common CI and server runtimes when unset.BRAINTRUST_ENVIRONMENT_NAME: environment name for span-origin provenance (for example,github_actionsoraws_lambda). Detected automatically when unset.