Run an experiment
Fetch 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:btql endpoint:
Fetch specific child spans based on trace-level metadata
Let’s say you want to retrieve child spans based on trace-level metadata. You can do this via the API by first filtering the spans you want to look at by whatevermetadata you are interested in, and then iterating through those spans to find the one(s) you are interested in.
The example below shows how you can calculate how long a given child span took to run that are in traces having a metadata key of “orgName” set to “qawolf”.
Paginate a large dataset
If you’re using the Python or TypeScript SDK, pagination is handled automatically. Only use this code if you’re developing with other tools.
Delete logs
To delete logs, you have to issue log requests with the_object_delete flag set to true.
For example, to find all logs matching a specific criteria, and then delete them, you can
run a script like the following:
Impersonate 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 headerx-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 importing the OpenAPI spec’s URL.
Trace 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 calledtracing_test, which looks like the
following:
