LiteLLM Exporter

Installation

$pip install respan-exporter-litellm

Classes

RespanLiteLLMCallback

LiteLLM-native callback handler that sends completion logs to Respan.

1from respan_exporter_litellm import RespanLiteLLMCallback
ParameterTypeDefaultDescription
api_keystr | NoneNoneRespan API key. Falls back to RESPAN_API_KEY env var.
base_urlstr | NoneNoneAPI base URL. Falls back to RESPAN_BASE_URL.

Methods

MethodDescription
log_success_event(kwargs, response_obj, start_time, end_time)Log a successful LLM completion.
log_failure_event(kwargs, response_obj, start_time, end_time)Log a failed LLM completion.
async_log_success_event(kwargs, response_obj, start_time, end_time)Async version of success logging.
async_log_failure_event(kwargs, response_obj, start_time, end_time)Async version of failure logging.

Helper functions

FunctionDescription
register_litellm_callbacks(name)Register Respan callbacks on the LiteLLM instance.

NamedCallbackRegistry

Named registry for managing LiteLLM callbacks.

Usage

1import litellm
2from respan_exporter_litellm import RespanLiteLLMCallback
3
4# Register callback
5respan_callback = RespanLiteLLMCallback(api_key="your-api-key")
6litellm.callbacks = [respan_callback]
7
8# Use LiteLLM normally — all calls are automatically logged
9response = litellm.completion(
10 model="gpt-4o-mini",
11 messages=[{"role": "user", "content": "Tell me a joke"}],
12)
13print(response.choices[0].message.content)

Async usage

1import litellm
2from respan_exporter_litellm import RespanLiteLLMCallback
3
4litellm.callbacks = [RespanLiteLLMCallback(api_key="your-api-key")]
5
6response = await litellm.acompletion(
7 model="gpt-4o-mini",
8 messages=[{"role": "user", "content": "Tell me a joke"}],
9)