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 Weights Biases Logger

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

Overview

WeightsBiasesLogger is a logging integration that records LiteLLM API events as trace trees in Weights & Biases (W&B) for experiment tracking and model observability.

Description

The module contains two main components. The OpenAIRequestResponseResolver class converts OpenAI-format request/response pairs into W&B WBTraceTree objects, handling three response types: edits, text completions, and chat completions. It extracts prompts, choices, and metadata to build structured trace spans with timing information. The WeightsBiasesLogger class wraps this resolver and provides a log_event method that initializes a W&B run, logs the trace tree, and finishes the run. The module requires the wandb package and its trace_tree data types to be installed.

Usage

Import and use WeightsBiasesLogger when you want to log LiteLLM completion events to Weights & Biases for experiment tracking, model performance analysis, and trace visualization. The wandb package must be installed.

Code Reference

Source Location

litellm/integrations/weights_biases.py

Signature

class OpenAIRequestResponseResolver:
    def __call__(self, request: Dict[str, Any], response: OpenAIResponse, time_elapsed: float) -> Optional[trace_tree.WBTraceTree]
    @staticmethod
    def results_to_trace_tree(request, response, results, time_elapsed) -> trace_tree.WBTraceTree

class WeightsBiasesLogger:
    def __init__(self)
    def log_event(self, kwargs, response_obj, start_time, end_time, print_verbose)

Import

from litellm.integrations.weights_biases import WeightsBiasesLogger

I/O Contract

Inputs

Parameter Type Description
kwargs dict The request parameters (model, messages, etc.) passed to the LLM call.
response_obj OpenAIResponse The response object from the LLM call, conforming to the OpenAI response protocol.
start_time datetime Start time of the API call.
end_time datetime End time of the API call.
print_verbose Callable Verbose logging function.

Outputs

Method Return Type Description
log_event None Logs a W&B trace tree to the active run; no explicit return value.
OpenAIRequestResponseResolver.__call__ Optional[WBTraceTree] A W&B trace tree object, or None if resolution fails.

Usage Examples

import litellm

# Add wandb as a success callback
litellm.success_callback = ["wandb"]

# Make a completion call - events are automatically logged to W&B
response = litellm.completion(
    model="gpt-3.5-turbo",
    messages=[{"role": "user", "content": "What is machine learning?"}],
)

Related Pages

Page Connections

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