Skip to main content
  1. Sign up — Create an account at platform.respan.ai
  2. Create an API key — Generate one on the API keys page
  3. Add credits or a provider key — Add credits on the Credits page or connect your own provider key on the Integrations page

What is Braintrust?

Braintrust is an AI evaluation and observability platform. Use respan-exporter-braintrust to export Braintrust log records (including nested spans) to Respan Traces. You can keep using Braintrust’s logger APIs; the exporter installs itself as Braintrust’s background logger and forwards records to Respan.

Setup

1

Install packages

pip install braintrust respan-exporter-braintrust
2

Set environment variables

.env
RESPAN_API_KEY=your-respan-api-key
# Optional (default: https://api.respan.ai/api)
RESPAN_BASE_URL=https://api.respan.ai/api
3

Run Braintrust with the Respan exporter

import os
import time
import braintrust
from respan_exporter_braintrust import RespanBraintrustExporter

def main():
    with RespanBraintrustExporter(raise_on_error=True):
        logger = braintrust.init_logger(
            project="Respan Braintrust Quickstart",
            project_id="respan-braintrust-quickstart",
            api_key=braintrust.logger.TEST_API_KEY,
            async_flush=False,
            set_current=False,
        )

        with logger.start_span(name="respan-braintrust-parent", type="task") as root_span:
            with root_span.start_span(name="respan-braintrust-child", type="chat") as child_span:
                time.sleep(0.25)
                child_span.log(
                    input=[{"role": "user", "content": "Hello from Braintrust quickstart"}],
                    output="Hello from Respan!",
                    metrics={"prompt_tokens": 5, "completion_tokens": 7},
                    metadata={"model": "gpt-4o-mini"},
                )

        logger.flush()

if __name__ == "__main__":
    main()
4

View your trace

Open the Traces page in the Respan dashboard.

Examples

Braintrust + OpenAI

If you’re using Braintrust’s OpenAI wrapper (wrap_openai), you can still export everything to Respan:
import os
from braintrust import init_logger, wrap_openai
from openai import OpenAI
from respan_exporter_braintrust import RespanBraintrustExporter

with RespanBraintrustExporter() as exporter:
    logger = init_logger(project="Email Classifier")
    client = wrap_openai(OpenAI())

    response = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": "Hello from Braintrust"}],
    )

    logger.log(
        input={"prompt": "Hello from Braintrust"},
        output=response.choices[0].message.content,
    )

    logger.flush()

Observability

With this integration, Respan auto-captures:
  • Braintrust spans — root and child spans
  • LLM calls — model, input/output, token usage
  • Custom metadata — any metadata attached to spans
  • Errors — failed calls and error details
View traces on the Traces page.