wrap_litellm instruments the module-level litellm.completion / litellm.acompletion functions so every call — to OpenAI, Anthropic, Gemini, or any other supported provider — is traced automatically as an LLM span.
Installation
- pip
- uv
Setup
Unlike the other wrappers, LiteLLM’s entry points are module-level functions, not a client instance — sowrap_litellm patches the litellm module rather than an object. It is idempotent (a second call is a no-op) and returns the module.
- Patch the module
- Import and patch
completion and asynchronous acompletion functions are patched, covering blocking and streaming calls.
Completion API
Span name:"litellm-chat", SpanKind: LLM
- Input:
messagesarray, captured directly (LiteLLM already speaks the universal OpenAI schema) - Output: assistant message from
choices[0].message - Model name (from the response body — the resolved provider model)
- Token usage:
prompt_tokens,completion_tokens,total_tokens, plus detail fields (for examplereasoning_tokensfromcompletion_tokens_details) - Model parameters:
temperature,top_p,max_tokens,max_completion_tokens,reasoning_effort,thinking,response_format,stop, and other safe parameters only - Reasoning: LiteLLM’s normalized
reasoning_contentis stored in span metadata asreasoning_summary
Any provider, one call
LiteLLM routes to the target provider based on themodel string — the wrapper and trace shape are identical regardless of which provider serves the request. Set the matching provider API key in your environment.
Streaming
completion_start_time on the first chunk for time-to-first-token tracking, and reduces chunks to a single response for the span output. Pass stream_options={"include_usage": True} so LiteLLM emits token usage on the terminal chunk — otherwise streamed spans have no usage totals.
Async
The async entry point is the module-levellitellm.acompletion, instrumented by the same wrap_litellm call — no separate client. It supports both blocking and streaming, mirroring completion.
Token usage mapping
LiteLLM normalizes every provider’s usage into the OpenAI shape, so the mapping is the identity:| LiteLLM Field | PandaProbe Field |
|---|---|
prompt_tokens | prompt_tokens |
completion_tokens | completion_tokens |
total_tokens | total_tokens |
completion_tokens_details.reasoning_tokens | reasoning_tokens |
Using the LiteLLM proxy
If you run LiteLLM as a proxy server instead of the embedded SDK, it exposes an OpenAI-compatible endpoint. Point theopenai client at the proxy base URL and trace it with wrap_openai — no LiteLLM-specific wrapping is needed.
Wrappers work seamlessly with manual instrumentation. If a
litellm.completion call happens inside a pandaprobe.start_trace() or @pandaprobe.trace context, the LLM span is automatically nested as a child span.
