The `braintrust-api` library is the official Python client for interacting with the Braintrust REST API. It provides convenient access to log, trace, and evaluate AI applications. The library includes type definitions for all request parameters and response fields, supporting both synchronous and asynchronous clients. It is actively maintained with frequent updates, with the current version being 0.6.0.
pip install braintrust-apiVerified import paths — ran on the pinned version, not inferred.
Initializes the Braintrust API client using an API key from an environment variable and creates a new project. This demonstrates basic client initialization and a synchronous API call.
For direct REST API access, `pip install braintrust-api` and `from braintrust_api import Braintrust`. For AI logging/evaluation, `pip install braintrust` and `from braintrust import Eval` or `init_logger`.
Set the `BRAINTRUST_API_KEY` environment variable (e.g., `export BRAINTRUST_API_KEY='bt_your_api_key_here'`) or use a `.env` file with `python-dotenv`.
For async operations, import `AsyncBraintrust` and always use `await` with its methods. For sync operations, use `Braintrust` and call methods directly without `await`.
Verify that `BRAINTRUST_API_KEY` is correctly set in your environment and contains a valid Braintrust API key. You can generate API keys in your Braintrust organization settings.
Ensure you have installed `braintrust-api` (`pip install braintrust-api`) and are importing from `braintrust_api`: `from braintrust_api import Braintrust`.
Double-check the official documentation for the correct API client initialization and method signatures for your installed version. Ensure your client object is correctly assigned and that you are calling a valid method (e.g., `client.projects.create(...)`).