API walkthrough
The Braintrust REST API is available via an OpenAPI spec published at https://github.com/braintrustdata/braintrust-openapi. This guide walks through a few common use cases, and should help you get started with using the API. Each example is implemented in a particular language, for legibility, but the API itself is language-agnostic.
To learn more about the API, see the full API spec. If you are looking for a language-specific wrapper over the bare REST API, we support several different languages.
Running an experiment
Fetching experiment results
Let's say you have a human review workflow and you want to determine if an experiment has been fully reviewed. You can do this by running a Braintrust query language (BTQL) query:
To do this in Python, you can use the btql
endpoint:
Paginating a large dataset
Impersonating a user for a request
User impersonation allows a privileged user to perform an operation on behalf of another user, using the impersonated user's identity and permissions. For example, a proxy service may wish to forward requests coming in from individual users to Braintrust without requiring each user to directly specify Braintrust credentials. The privileged service can initiate the request with its own credentials and impersonate the user so that Braintrust runs the operation with the user's permissions.
To this end, all API requests accept a header x-bt-impersonate-user
, which you
can set to the ID or email of the user to impersonate. Currently impersonating
another user requires that the requesting user has specifically been granted the
owner
role over all organizations that the impersonated user belongs to. This
check guarantees the requesting user has at least the set of permissions that
the impersonated user has.
Consider the following code example for configuring ACLs and running a request with user impersonation.
Postman
Postman is a popular tool for interacting with HTTP APIs. You can load Braintrust's API spec into Postman by simply importing the OpenAPI spec's URL
Tracing with the REST API SDKs
In this section, we demonstrate the basics of logging with tracing using the
language-specific REST API SDKs. The end result of running each example should
be a single log entry in a project called tracing_test
, which looks like the
following: