Skip to main content
The Braintrust API allows you to interact with all aspects of the Braintrust platform programmatically. You can use it to:
  • Create and manage projects, experiments, and datasets
  • Log traces and metrics
  • Manage prompts, tools, and scorers
  • Configure access control and permissions
  • Retrieve and analyze results
The API is defined by an OpenAPI specification published at braintrust-openapi on GitHub.

Base URL

The base URL depends on your organization’s data plane region: You can find your API URL in Settings > Data plane.

Authentication

Authenticate requests with your API key in the Authorization header:
Create API keys in Settings > API keys.

SDKs

While you can call the API directly, we recommend using one of our official SDKs:

TypeScript SDK

Official TypeScript/JavaScript SDK

Python SDK

Official Python SDK

Go SDK

Official Go SDK

Ruby SDK

Official Ruby SDK

Java SDK

Official Java SDK

C# SDK

Official C# SDK

API resources

The API is organized around REST principles. Each resource has predictable URLs and uses HTTP response codes to indicate API errors. Project resources
  • Projects: Organize your AI features and experiments
  • Experiments: Run and track evaluation experiments
  • Datasets: Manage test data for evaluations
  • Logs: Store and query production traces
  • Prompts: Version control your prompts
  • Functions: Manage tools, scorers, and workflows
  • Evals: Configure and run evaluations
  • Scores: Define custom scoring functions
  • Tags: Organize and filter project resources
  • Automations: Configure automated workflows
  • Views: Create and manage custom data views
Organization resources
  • Organizations: Manage your organization settings
  • Users: Manage team members
  • Groups: Organize users into teams
  • Project groups: Organize projects into groups
  • Roles: Define permission levels
  • ACLs: Configure fine-grained access control
  • API keys: Manage authentication credentials
  • Service tokens: Generate service-level authentication tokens
Configuration resources
  • AI secrets: Securely store API keys and credentials
  • Environment variables: Manage environment-specific configuration
  • MCP servers: Configure Model Context Protocol servers
  • Proxy: Configure proxy settings for API requests

Response format

All API responses are returned in JSON format. Successful responses will have a 2xx status code, while errors will return 4xx or 5xx status codes with error details.

Rate limits

The API uses rate limiting to ensure fair usage. Rate limits are applied per endpoint and are scoped to an organization, a project, or both. If you exceed the rate limit, you’ll receive a 429 Too Many Requests response. See system limits for the limits that apply to all deployments, or Set inbound request rate limits to configure them on a self-hosted deployment.

Query data

Query your logs, experiments, and datasets with SQL through the /btql endpoint. For a full reference, see Query by SQL.

Filter experiments by metadata

Filter experiments by metadata field equality using the metadata query parameter on GET /v1/experiment. Pass a JSON-serialized object to match experiments where all specified fields are equal, including nested paths:

Invoke functions

Call prompts, tools, or scorers via the /v1/function endpoint:
Parameters
  • project_name or project_id: Project containing the function
  • slug: Function slug
  • input: Function input parameters
  • version (optional): Pin to a specific version
  • environment (optional): Use environment-specific version
  • stream (optional): Enable streaming responses
Response

Write and manage data

Run experiments

Create and run experiments programmatically:

Log programmatically

Insert logs via the API:

Delete logs

Mark logs for deletion by setting _object_delete:

Impersonate users

To make API requests using another user’s identity and permissions, authenticate with a personal API key or service token and set the x-bt-impersonate-user header to the target user’s email or user ID. Braintrust requires that:
  • The authenticating user or service account must have the Owner role in every organization the target user belongs to, through a direct role grant or membership in a permission group with that role. The Manage settings permission alone is not sufficient.
  • The target user must belong to at least one organization.
For service tokens, Braintrust checks the service account’s permissions, not the permissions of the person who created the token. To configure access, see Manage permissions, including service account permission groups. To grant a role through the API, see Create ACL. To list projects as the target user, set BRAINTRUST_API_KEY to your personal API key or service token, and USER_EMAIL to the target user’s email. For self-hosted deployments, replace https://api.braintrust.dev with your deployment’s Universal API URL:
The response lists projects accessible to the impersonated user.

Next steps

Support

Need help with the API?