Usage
RegisterAgentXLiteLLMLogger via litellm.callbacks once at startup. Every subsequent litellm.completion() / litellm.acompletion() call - sync, async, or streaming, across any of the 100+ providers LiteLLM supports - is traced automatically with no per-call changes.
litellm.callbacks is process-global - set it once at startup, not per
request. It affects every LiteLLM call made afterward, regardless of which
provider or model each call targets.What gets traced
By default, eachcompletion() / acompletion() call produces its own trace. For a streamed call, LiteLLM reassembles the full response internally before invoking the logger, so streaming is traced the same way as a regular call - one trace with the complete output, not one per chunk.
The raw LiteLLM client has no built-in concept of “tool call” or “retrieval”; those only exist as plain Python code around your
completion() calls, so the logger can’t see them on its own. Use tracer.trace_tool_call() and tracer.trace_retrieval() to record them manually so they show up in the trace’s performance summary - see the Anthropic integration’s tool-use example for the same pattern.
Multi-call agentic loops
Wrap a multi-call loop inwith tracer.trace(...) to collapse every completion()/acompletion() call made inside it into one trace instead of one trace per call:
AgentXLiteLLMLogger checks tracer.current_span on every callback: if a span is active on the current thread, the call is attached to it as an "LLM Call N" step; otherwise it sends its own trace as usual.
AgentXLiteLLMLogger reference
AgentXLiteLLMLogger is a real litellm.integrations.custom_logger.CustomLogger - it can be combined with other LiteLLM callbacks in the same litellm.callbacks list without conflict.
Call
tracer.flush() before your process exits in scripts or one-shot jobs.
In long-running servers it is not required: traces drain automatically in the
background.
