> ## Documentation Index
> Fetch the complete documentation index at: https://inference-docs.cerebras.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Started with Braintrust

> Learn how to set up logging, evaluation, and tracing for Cerebras Inference models using Braintrust.

## What is Braintrust?

Braintrust is the AI observability platform helping teams measure, evaluate, and improve AI in production. Learn more at [https://www.braintrust.dev/](https://www.braintrust.dev/?utm_source=cerebras\&utm_campaign=braintrust)

## Prerequisites

Before you begin, ensure you have:

* **Cerebras API Key** - Get a free API key [here](https://cloud.cerebras.ai/?utm_source=3pi_braintrust\&utm_campaign=integrations).
* **Braintrust API Key** - Visit [Braintrust](https://braintrust.dev/?utm_source=cerebras_docs\&utm_medium=integration_page\&utm_campaign=3pi_braintrust) and create an account or log in.
  * Go to **Settings** > **AI Providers** and add your Cerebras API key. Then generate a Braintrust API key.
* **Python 3.7 or higher**

## Configure Braintrust

<Steps>
  <Step title="Install required dependencies">
    Run the following:

    ```bash theme={null}
    pip install autoevals braintrust openai
    ```
  </Step>

  <Step title="Configure environment variables">
    Create a `.env` file in your project directory:

    ```bash theme={null}
    CEREBRAS_API_KEY=your-cerebras-api-key-here
    BRAINTRUST_API_KEY=your-braintrust-api-key-here

    # Optional: If self-hosting Braintrust
    # BRAINTRUST_API_URL=your-braintrust-api-url
    ```
  </Step>

  <Step title="Initialize the client">
    Set up the Cerebras client with Braintrust wrapping:

    ```python theme={null}
    import os
    import openai
    import braintrust

    # Wrap the OpenAI client to enable automatic tracing
    client = braintrust.wrap_openai(
        openai.OpenAI(
            api_key=os.getenv("CEREBRAS_API_KEY"),
            base_url="https://api.cerebras.ai/v1",
            default_headers={"X-Cerebras-3rd-Party-Integration": "braintrust"}
        )
    )
    ```
  </Step>

  <Step title="Start logging">
    Initialize a logger to automatically track all your model calls:

    ```python theme={null}
      import os
      import openai
      import braintrust

      # Wrap the OpenAI client to enable automatic tracing
      client = braintrust.wrap_openai(
          openai.OpenAI(
              api_key=os.getenv("CEREBRAS_API_KEY"),
              base_url="https://api.cerebras.ai/v1",
              default_headers={"X-Cerebras-3rd-Party-Integration": "braintrust"}
          )
      )

      # Initialize logger for your project
      braintrust.init_logger("My Cerebras Project")

      # Make a simple completion call
      response = client.chat.completions.create(
          model="gpt-oss-120b",
          messages=[
              {"role": "system", "content": "You are a helpful assistant."},
              {"role": "user", "content": "What is the capital of Nevada?"},
          ],
          extra_headers={
              "X-Cerebras-3rd-Party-Integration": "braintrust"
          }
      )

      print(response.choices[0].message.content)
    ```

    All calls are automatically logged to Braintrust with metrics like latency, token usage, and time to first token.
  </Step>

  <Step title="View your logs">
    * Open the Braintrust dashboard
    * Navigate to your project
    * View detailed logs with metrics
    * Reproduce and tweak prompts directly in the UI

          <img src="https://mintcdn.com/cerebras-inference/1rXdXjxTf-5D8qFt/images/braintrust/viewlogs.png?fit=max&auto=format&n=1rXdXjxTf-5D8qFt&q=85&s=f325cb2d5b05acbcdda10997d8f63e5f" alt="view logs" width="2450" height="1496" data-path="images/braintrust/viewlogs.png" />

          <img src="https://mintcdn.com/cerebras-inference/1rXdXjxTf-5D8qFt/images/braintrust/tweakprompt.gif?s=1febec9afb399d7e774fd72c2901f930" alt="tweak the prompt" width="800" height="489" data-path="images/braintrust/tweakprompt.gif" />
  </Step>

  <Step title="Run evaluations">
    Create evaluations to test your model's performance:

    ```python theme={null}
      import os
      import openai
      from braintrust import wrap_openai, Eval
      from autoevals import Factuality

      # Wrap the OpenAI client to enable automatic tracing
      client = wrap_openai(
          openai.OpenAI(
              api_key=os.getenv("CEREBRAS_API_KEY"),
              base_url="https://api.cerebras.ai/v1",
              default_headers={"X-Cerebras-3rd-Party-Integration": "braintrust"}
          )
      )

      Eval(
          "My Cerebras Project",
          data=[
              {"input": "What is 100-94?", "expected": "6"},
              {"input": "What is the square root of 16?", "expected": "4"},
          ],
          task=lambda input: client.chat.completions.create(
              model="gpt-oss-120b",
              messages=[
                  {
                      "role": "system",
                      "content": "You are a helpful assistant. Provide only the answer.",
                  },
                  {"role": "user", "content": input},
              ],
          ).choices[0].message.content,
          scores=[
              Factuality(
                  model="gpt-oss-120b",
                  api_key=os.environ["CEREBRAS_API_KEY"]
              )
          ],
      )
    ```

    You can check these evaluations in the Braintrust dashboard:

    <img src="https://mintcdn.com/cerebras-inference/1rXdXjxTf-5D8qFt/images/braintrust/dashboard.gif?s=212569738a0db8588e2a73df9e20b2ca" alt="dashboard" width="679" height="470" data-path="images/braintrust/dashboard.gif" />
  </Step>
</Steps>

## Available Models

Cerebras offers several high-performance models for your Braintrust evaluations:

| Model            | Parameters | Best For                                                         |
| ---------------- | ---------- | ---------------------------------------------------------------- |
| **gpt-oss-120b** | 120B       | Largest model for the most demanding tasks                       |
| **zai-glm-4.7**  | 357B       | Advanced 357B parameter model with strong reasoning capabilities |

Simply change the `model` parameter in your API calls to switch between models.

## Next Steps

* Explore the [Braintrust documentation](https://braintrust.dev/docs?utm_source=cerebras_docs\&utm_medium=integration_page\&utm_campaign=3pi_braintrust)
* **Migrate to GLM4.7**: Ready to upgrade? Follow our [migration guide](https://inference-docs.cerebras.ai/resources/glm-47-migration) to start using our latest model
* Try out different Cerebras models
* Set up custom evaluation metrics
* Build production monitoring dashboards

## Troubleshooting

### API Key Issues

* Verify your keys are correctly set in environment variables
* Check that Cerebras key is added to Braintrust's AI providers

### Import Errors

* Ensure all packages are installed: pip install autoevals braintrust openai
* Use a virtual environment to avoid conflicts

### Connection Issues

* Verify the base URL: [https://api.cerebras.ai/v1](https://api.cerebras.ai/v1)
* Check your network connection and firewall settings
