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.
The LiteLLM wrapper is currently available in the Python SDK only. TypeScript applications using the LiteLLM proxy can instrument its OpenAI-compatible endpoint with
wrapOpenAI.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
Python
completion and asynchronous acompletion functions are patched, covering blocking and streaming calls.
Completion API
Span name:"litellm-chat", SpanKind: LLM
Python
- 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
Python
completion and asynchronous acompletion with the same PandaProbe setup. The wrapper records 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.
Token usage mapping
LiteLLM normalizes every provider’s usage into the OpenAI shape, so the mapping is the identity: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.
Python
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.
