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.
config.SpanCustomizer
Span customizers modify each span after it ends and before the SDK exports it to Braintrust. Register them with braintrust.WithSpanCustomizers. They run in registration order on every exported span, including spans you create with the OpenTelemetry API. See Span customizers for examples and behavior.
#skip-compile
config.SpanCustomizer fields:
OnSpanExport(func(span sdktrace.ReadOnlySpan) (sdktrace.ReadOnlySpan, error)): receives a completed span and returns it or a replacement that embedssdktrace.ReadOnlySpan.
- Don’t change the trace ID, span ID, parent trace ID, or parent span ID. Attributes can change.
- If a customizer returns an error, panics, returns
nil, or changes an ID, the SDK skips the remaining customizers for that span and exports it with its content stripped. Other spans in the batch export normally. See When a customizer fails. - Customizers run before the SDK converts and uploads attachments, so removing inline base64 data keeps the file out of Braintrust.
- The SDK can call customizers from background goroutines, so make them safe for concurrent use.
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], required): scoring functions applied to each case. To use classifiers, usebraintrust.NewEvaluatorinstead.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.Parameters(eval.Parameters): parameter values for this run, merged over the defaults inEval.ParameterSchemaand passed to the task throughhooks.Parameters. When unset, the task gets the declared defaults.NoSendLogs(bool): run the eval locally without sending anything to Braintrust. Cases still run and are scored, but no experiment is created and no eval spans are uploaded, so the result has no experiment ID or permalink. Defaults tofalse. Requires v0.17.2 or later.
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.NoSendLogs(bool): run the eval locally without sending anything to Braintrust. Cases still run and are scored, but no experiment is created and no eval spans are uploaded, so the result has no experiment ID or permalink. Defaults tofalse. Requires v0.17.2 or later.
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.
Workflow evaluations
A workflow evaluation is an evaluation whose task or scorers submit requests to an asynchronous provider API, such as the OpenAI Batch API, and collect the results later. The run saves its progress to a store, so your application can resume it by polling or from a webhook. With a shared store such as Redis, a different process can resume it. See Workflow evaluations for a complete OpenAI example.Requires Go SDK v0.18.0 or later. The Go SDK saves run state in its own format, so start and resume a run with the Go SDK.
braintrust.NewWorkflowEval
Attaches a client to an *eval.WorkflowEval definition, so its runs create an experiment and log results to Braintrust. Every process that starts or resumes a run that logs to Braintrust must use a definition attached this way.
Returns: *eval.WorkflowEval[I, R]. Defining an evaluation does not start a run. To start one, call Start.
eval.WorkflowEval[I, R] fields:
Name(string, required): evaluation name, used as the default experiment name and to identify the run’s records in the store.Store(eval.WorkflowEvalStore, required): persistence backend shared by every process that starts or resumes the run. See Workflow stores.Task(eval.WorkflowTaskDefinition[I, R], required): an ordinaryeval.TaskFunc[I, R]such as one built witheval.T, aneval.WorkflowTask, or aneval.WorkflowBatchTask. Task outputs are saved to the store, so they must be JSON-serializable. An ordinary task that returnseval.TaskOutputwithUserDatafails for that case. Use metadata instead.Scorers([]eval.Scorer[I, R]): ordinary scorers, which run in your process after a case’s task output is collected.WorkflowScorers([]eval.WorkflowScorerDefinition[I, R]): asynchronous scorers. Each is aneval.WorkflowScoreror aneval.WorkflowBatchScorer.Classifiers([]eval.Classifier[I, R]): classifiers, which run in your process after a case’s task output is collected.ParameterSchema(eval.ParameterSchema): declares parameters the evaluation accepts (see Parameters). Pass runtime values toStart.ProjectName(string): Braintrust project for this evaluation. Falls back to the client’s configured project.MaxConcurrency(int): how many of your callbacks the SDK runs at the same time during eachStart,Poll, orProcessSubmissionResultcall. Defaults to10. Must not be negative.
Scorers, WorkflowScorers, and Classifiers, and can’t be task. Keep the definition, including scorer names and order, unchanged while runs are active.
WorkflowEval methods
Each method returns (*eval.WorkflowResult, error) with the run’s current state.
Start(ctx, opts eval.WorkflowStartOpts[I, R]): creates the experiment, saves the dataset to the store, and submits the initial task work. It returns without waiting for the provider. With an ordinaryeval.TaskFunctask,Startruns the task and the ordinary scorers and classifiers for every case before it returns. If a callback fails after the run is saved,Startstill returns the run ID. Resume that run withPollinstead of starting a second one.Poll(ctx, runID string): checks each pending poll-mode submission once, collects the completed ones, and advances the run. It also retries submissions that failed to submit. Call it on a schedule until the run completes.ProcessSubmissionResult(ctx, ref eval.WorkflowSubmissionResult): collects one completed submission and advances its run. Call it after your application verifies a provider webhook. Repeated notifications for the same submission are harmless.Status(ctx, runID string): reads the run’s progress without submitting, polling, or collecting.
eval.WorkflowStartOpts[I, R] fields:
Dataset(eval.Dataset[I, R], required): test cases for this run. Inputs, expected values, and metadata must be JSON-serializable.Experiment(string): experiment name. Defaults toWorkflowEval.Name.ProjectID(string): identifies the project by ID instead of by name.Tags([]string): tags to apply to the experiment.Metadata(eval.Metadata): metadata to attach to the experiment.TrialCount(int): number of times to run each case. Defaults to1. A case’sTrialCountoverrides this value.Parameters(eval.Parameters): parameter values for this run, merged over the defaults inParameterSchema.NoSendLogs(bool): run without creating an experiment or logging results to Braintrust, so no client is required. Run state is still saved to the store. Tracing that your own callbacks do is not disabled.
eval.WorkflowSubmissionResult fields:
ExternalID(string): the provider’s ID for the completed operation, as returned byGetExternalID. Sufficient on its own unless the same ID belongs to several runs. In that case, also setRunID.RunID(string): the run that owns the submission.SubmissionID(string): the SDK’s submission ID. RequiresRunID. Use it instead ofExternalID.
eval.WorkflowResult fields:
RunID(string): run ID to pass toPoll,Status, orProcessSubmissionResult.Status(eval.WorkflowRunStatus):eval.WorkflowRunWaiting("waiting") while cases or submissions are outstanding, andeval.WorkflowRunCompleted("completed") once every case has finished, including failed cases.Completed(int): number of finished cases, including failed cases.Failed(int): number of cases with a failed task, scorer, or classifier. A completed run can have failures.PendingPollandPendingWebhook(int): number of submitted operations not yet collected, by completion mode.Scores(map[string]float64): average of the successful values for each score name.ExperimentIDandPermalink(string): the experiment and its URL. Empty forNoSendLogsruns.
metadata.workflow_eval records run_id, case_id, and trial_index, plus batch_submission_id when an eval.WorkflowBatchTask produced the output. case_id is the dataset case’s ID when set, otherwise an ID generated when the run starts. A failed task’s error appears in the row’s error field, and failed scorers and classifiers appear in metadata.scorer_errors and metadata.classifier_errors.
eval.WorkflowTask and eval.WorkflowScorer
eval.WorkflowTask and eval.WorkflowScorer each submit one asynchronous provider operation for each case and trial. Use eval.WorkflowTask for the task and eval.WorkflowScorer for a scorer.
eval.WorkflowTask and eval.WorkflowScorer fields:
Name(string, required,WorkflowScoreronly): scorer name.Submit(required): sends the request to the provider and returns ajson.RawMessagehandle, such as the provider’s job ID, that later callbacks receive. The handle must be valid JSON and must not contain clients or credentials. A task’sSubmitreceives aneval.WorkflowTaskItem[I, R], and a scorer’s receives aneval.WorkflowScorerItem[I, R].Completion(eval.WorkflowCompletion, required): how the SDK learns the operation finished. Seeeval.WorkflowCompletion.Collect(required): reads the finished operation from its handle. A task’sCollectreturns aneval.WorkflowTaskResult[R], and a scorer’s returnseval.Scores. IfCollectreturns an error, the case stays pending. The SDK callsCollectagain on the nextPoll, or for webhook completion, on the nextProcessSubmissionResultcall for that submission.
eval.WorkflowSubmissionContext with RunID and SubmissionID. SubmissionID is stable across retries, so use it as the provider’s idempotency key. A crash after the provider accepts a request but before the SDK saves the handle can call Submit again.
eval.WorkflowTaskItem[I, R] fields: ID (unique for each trial), CaseID (shared by a case’s trials), Input, Expected, Metadata, Tags, Parameters, and TrialIndex.
eval.WorkflowTaskResult[R] fields: Output, and optional Metadata and Tags. Tags replaces the case’s tags.
eval.WorkflowScorerItem[I, R] embeds eval.TaskResult[I, R] (with Input, Output, Expected, and Metadata) and adds ID, CaseID, Tags, and TrialIndex.
eval.WorkflowBatchTask and eval.WorkflowBatchScorer
eval.WorkflowBatchTask and eval.WorkflowBatchScorer group many cases into one provider operation, such as one OpenAI batch. They have the same Name (scorer only) and Completion fields as eval.WorkflowTask and eval.WorkflowScorer, plus:
Batching(eval.WorkflowBatching, required): batch size limits. See below.Submit(required): receives a slice ofeval.WorkflowBatchItemvalues, each with aCustomIDand theItem. SendCustomIDas the provider’s per-request ID, such as OpenAI’scustom_id. Treat it as opaque.Collect(required): reads the finished operation and calls itsyieldfunction once for each result with aneval.WorkflowBatchResult(CustomID,Result, and a per-itemError). Return immediately whenyieldreturns an error.
eval.WorkflowBatching fields:
MaxSize(int, required): maximum number of cases in a batch. Must be positive.MaxWait(time.Duration): batch scorers only. How long a partial batch can wait before it’s submitted. The SDK checks it only when the run advances, with no background timer. Defaults to0, which waits for a full batch or for the last remaining cases. A batch task submits immediately and rejects a nonzeroMaxWait.
Collect can run again, and results already saved are ignored. A duplicate or unknown CustomID is an error. Cases with no result when Collect succeeds are recorded as failed. Failed tasks skip their scorers and classifiers, and a failed scorer keeps the case’s other scores.
eval.WorkflowCompletion
Selects how the SDK learns that a submission finished. Set exactly one field:
Poll: checks the provider and returns aneval.WorkflowPollResultwith aStatusofeval.WorkflowPending,eval.WorkflowComplete, oreval.WorkflowFailed, and an optionalError.WorkflowEval.Pollcalls it.GetExternalID: returns the provider’s ID for the submission, which the provider’s webhook later delivers. Pass that ID toProcessSubmissionResultasExternalID.
Workflow stores
A store persists the run’s dataset, outputs, submission handles, and progress. Use the same store and key prefix for every call that starts or resumes a run.eval.NewWorkflowEvalMemoryStore()→*eval.WorkflowEvalMemoryStore: keeps state in memory for single-process runs. State is lost when the process exits.eval.NewWorkflowEvalRedisStore(command eval.WorkflowRedisCommand, prefix string, ttl time.Duration)→(*eval.WorkflowEvalRedisStore, error): stores state in Redis.commandruns a Redis command and returns its decoded result, so the SDK doesn’t depend on a Redis client. With go-redis, wrapclient.Do(ctx, args...).Result()and returnnil, nilforredis.Nil. The command must supportEVAL. An emptyprefixdefaults tobraintrust-eval:, and a zerottldefaults to seven days. Writes refresh the TTL and reads don’t, so set it longer than the full run and your webhook retry window. An expired run can’t be resumed.
eval.WorkflowEvalStore interface: Read, Write, GetOrSet, AddToSet, and GetSetSize. Read returns nil, nil for a missing key, and GetOrSet and AddToSet must be atomic.
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.Prompt(name)→(*prompt.Prompt, bool): returns the value fornameas a renderable prompt, and whether one was found. Use this for"prompt"parameters. Returnsfalsewhen the parameter is absent or cannot be converted.Parameters.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. It must write to stderr, because stdout is reserved for thebtprotocol. The default logger writes to stderr.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, ModeInspect, or ModeUnknown. ModeUnknown means bt requested a mode the runner doesn’t recognize, and evalrunner.Run returns an error. Use it to skip expensive setup when bt only wants the list of registered evals:
#skip-compile
Prompts
Prompts saved in Braintrust carry a template, a model, and parameters. The Go SDK loads them from the API, renders their variables, and returns a provider-agnostic result you hand to any LLM client. A prompt is fetched every time. Nothing is cached.client.LoadPrompt
Loads a prompt from Braintrust by slug and returns it ready to render. The client’s configured project is used when no project is specified in opts.
#skip-compile
(*prompt.Prompt, error).
prompt.LoadOpts fields:
Slug(string): prompt slug. Required unlessIDis set.Project(string): project name. Filled in from the client’s project when empty.ProjectID(string): project ID. Takes precedence overProjectwhen set.ID(string): load by Braintrust prompt ID instead of slug.Version(string): pin to a specific prompt version. Defaults to the latest.Environment(string): load the prompt deployed to an environment (for example,"production"). Ignored whenVersionis set.
prompt.LoadWithClient(ctx, apiClient, opts) with an *openapi.Client from openapi.NewClient, configured with a base URL and Authorization header (v0.19.0 or later). prompt.Load, which takes an *api.API, is deprecated but remains available for existing code.
prompt.Definition
Declares a prompt in Go code. Use it as the Default for a prompt eval parameter:
#skip-compile
prompt.Definition fields:
Model(string, required): model the prompt targets.Messages([]prompt.Message): chat messages. Mutually exclusive withPrompt.Prompt(string): completion template. Mutually exclusive withMessages.Params(map[string]any): model parameters such astemperatureormax_tokens.Tools([]prompt.Tool): tool definitions offered to the model. Chat prompts only.TemplateFormat(string):"mustache"(default) or"none".
prompt.Message: prompt.System(text), prompt.User(text), prompt.Assistant(text).
prompt.Prompt.Build
Renders the prompt’s template variables and returns a *prompt.Built ready to send to a model.
#skip-compile
(*prompt.Built, error). Build fails if the prompt has no body or no model, the template is malformed, or the format is not supported ("nunjucks" is not rendered locally).
For the OpenAI Go client, traceopenai.ChatCompletionParams(built) (from github.com/braintrustdata/braintrust-sdk-go/trace/contrib/openai) converts a chat prompt directly into openai.ChatCompletionNewParams.
prompt.Built fields:
Model(string): model to call.Messages([]prompt.Message): rendered chat messages, for a chat prompt.Prompt(string): rendered completion text, for a completion prompt.Params(map[string]any): model parameters.Tools([]prompt.Tool): rendered tool definitions.Metadata(*prompt.Metadata): prompt identity for tracing. Nil when the prompt has no Braintrust identity.
built.Map() returns the built prompt as an OpenAI-shaped map[string]any (model, messages or prompt, tools, and every model parameter at the top level) for clients this SDK has no adapter for.
Build options:
prompt.WithDefaults(defaults map[string]any): default model parameters, used for any parameter the prompt does not set.prompt.WithTemplateFormat(format string): override the template format saved on the prompt.prompt.WithStrict(): fail when the template references a variable that was not supplied. By default a missing variable renders as an empty string.
built.AnnotateSpan
Records the prompt’s identity and rendered variables on a span, linking the model call back to the prompt in Braintrust. Call it before ending the span that covers the model call.
#skip-compile
Metadata is nil (the prompt has no Braintrust identity) or the span is not recording.
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
Theopenapi package gives direct access to the Braintrust REST API. Its client, methods, and models are generated from the Braintrust OpenAPI specification. It covers projects, experiments, datasets, prompts, functions, project automations, function invocation, and other REST resources, beyond what the higher-level APIs above cover. Requires v0.19.0 or later.
openapi.NewClientWithResponses
Creates a REST API client for a base URL. The client doesn’t read environment variables or add authentication, so set the base URL and the Authorization header yourself.
#skip-compile
(*openapi.ClientWithResponses, error). Use openapi.WithHTTPClient to supply a custom *http.Client, for example with a timeout or transport.
Key rules:
- An HTTP error response isn’t a Go error. Check
StatusCode()and the decoded field for the expected status, such asJSON200, as well aserr.Bodyholds the raw response bytes, including error details. - Methods ending in
WithResponseread and close the response body. If you use the raw methods fromopenapi.NewClient, close each response body yourself. - List and fetch operations return one page. Pass the pagination parameters or fetch cursor to request the next page. The client doesn’t paginate automatically.
- Optional fields use pointers or
nullable.Nullable[T]. For a nullable field, the zero value omits the field,nullable.NewNullableWithValue(value)sends a value, andnullable.NewNullNullable[T]()sends JSONnull. The difference matters for PATCH requests.
api.NewClient (deprecated)
The
api package and Client.API() are deprecated as of v0.19.0. They remain available and keep their existing behavior, but they won’t cover new REST resources. Use the openapi package for new code.#skip-compile
*api.API.
Namespaces:
client.Projects(): project management.client.Experiments(): experiment management. Methods includeCreate,Register,List,Get,Delete, andInsertEvents(ctx, experimentID, events), which insertsexperiments.Eventrows (v0.18.0 or later). To update fields of an existing row instead of replacing it, set the event’sIDto the row’s ID andIsMergetotrue.client.Datasets(): dataset management. Methods includeCreate,Insert,InsertEvents,Delete,Fetch, andQuery.client.Functions(): function management, includingInvoke(ctx, functionID, input)to call a deployed function.client.Prompts(): prompt management. Methods includeQuery(ctx, params)to search for prompts andGet(ctx, id, params)to fetch one by ID.
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.WithSpanCustomizers(customizers ...config.SpanCustomizer): register span customizers that modify spans before export. Repeated calls append to the list.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.