Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:BerriAI Litellm Braintrust Logger

From Leeroopedia
Attribute Value
Sources litellm/integrations/braintrust_logging.py
Domains Logging, Observability, Evaluation, Integrations
Last Updated 2026-02-15 16:00 GMT

Overview

The BraintrustLogger sends LLM success events (completions, embeddings, image generations) to the Braintrust evaluation and observability platform.

Description

BraintrustLogger extends CustomLogger to post LLM call data as spans to the Braintrust project logs API (/project_logs/{project_id}/insert). It supports both sync and async logging, automatic project creation, project ID caching, span hierarchies (via span_id, root_span_id, span_parents metadata), custom span names, tags from langfuse_default_tags, and token usage metrics. The logger also supports a mock mode for testing (controlled by the BRAINTRUST_MOCK environment variable).

Usage

Import and register BraintrustLogger when you need to send LLM telemetry to Braintrust for evaluation, tracing, or monitoring. Requires BRAINTRUST_API_KEY in the environment or passed directly.

Code Reference

Source Location

litellm/integrations/braintrust_logging.py

Signature

class BraintrustLogger(CustomLogger):
    def __init__(
        self, api_key: Optional[str] = None, api_base: Optional[str] = None
    ) -> None

Import

from litellm.integrations.braintrust_logging import BraintrustLogger

I/O Contract

Inputs

Parameter Type Required Description
api_key Optional[str] No Braintrust API key. Falls back to BRAINTRUST_API_KEY env var.
api_base Optional[str] No Braintrust API base URL. Falls back to BRAINTRUST_API_BASE env var or "https://api.braintrustdata.com/v1".

Key Methods

Method Returns Description
log_success_event(kwargs, response_obj, start_time, end_time) None Synchronous success event logging.
async_log_success_event(kwargs, response_obj, start_time, end_time) None Asynchronous success event logging.
get_project_id_sync(project_name: str) str Get or create project by name (sync), with caching.
get_project_id_async(project_name: str) str Get or create project by name (async), with caching.

Outputs

Output Type Description
Side effect HTTP POST Posts span events to /project_logs/{project_id}/insert on the Braintrust API.

Usage Examples

import litellm

# Set the callback
litellm.success_callback = ["braintrust"]

# Make a completion call - events are automatically logged
response = litellm.completion(
    model="gpt-4",
    messages=[{"role": "user", "content": "Hello"}],
    metadata={
        "project_name": "my-project",
        "span_name": "user-query",
    },
)
# Direct instantiation
from litellm.integrations.braintrust_logging import BraintrustLogger

logger = BraintrustLogger(api_key="my-braintrust-key")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment