Skip to Content
Launching the open-source gateway

LiteLLM (tracing)

LiteLLM  provides a unified Python interface for calling 100+ LLM providers using the OpenAI format. Respan’s LiteLLM instrumentation registers a native LiteLLM callback and sends completion spans through respan-tracing, with optional gateway routing through the OpenAI-compatible Respan endpoint.

Set up Respan

Create an account at platform.respan.ai  and grab an API key .

Paste this into your coding agent:

Help me set up Respan tracing with the LiteLLM integration. Follow https://www.respan.ai/docs/integrations/litellm.md

Setup

Install packages

Terminal
pip install respan-ai respan-instrumentation-litellm litellm

Set environment variables

Terminal
export OPENAI_API_KEY="YOUR_OPENAI_API_KEY" export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"

OPENAI_API_KEY (or any provider key) is used for LLM requests. RESPAN_API_KEY is used to export traces to Respan.

Initialize and run

Initialize Respan with the LiteLLM instrumentor. Requests go directly to providers; the callback emits canonical chat spans to Respan.

Python
import os import litellm from respan import Respan from respan_instrumentation_litellm import LiteLLMInstrumentor respan = Respan( api_key=os.environ["RESPAN_API_KEY"], app_name="litellm-service", instrumentations=[LiteLLMInstrumentor()], ) response = litellm.completion( model="gpt-4.1-nano", messages=[{"role": "user", "content": "Say hello in three languages."}], ) print(response.choices[0].message.content)

View your trace

Open the Traces page  to see your LiteLLM completions across providers as auto-traced spans.

Configuration

Respan

ParameterTypeDefaultDescription
api_keystr | NoneRESPAN_API_KEY env varRespan API key used for trace export.
base_urlstr | NoneRESPAN_BASE_URL env varRespan API base URL.
app_namestr"respan"Service name shown on exported spans.
instrumentationslist[]Include LiteLLMInstrumentor() to activate LiteLLM tracing.

LiteLLMInstrumentor

ParameterTypeDefaultDescription
include_contentboolTrueCapture request messages and assistant response content on chat spans.

Attributes

Set defaults on Respan(...), or override attributes per request with propagate_attributes.

Python
with respan.propagate_attributes( customer_identifier="user-123", thread_identifier="conv_abc_123", trace_group_identifier="litellm-support-flow", metadata={"plan": "pro"}, ): response = litellm.completion( model="gpt-4.1-nano", messages=[{"role": "user", "content": "Hello!"}], )
AttributeDescription
customer_identifierIdentifies the end user in Respan analytics.
thread_identifierGroups related messages into a conversation.
trace_group_identifierGroups related traces for search and filtering.
metadataCustom key-value pairs attached to the span.

Async usage

The callback supports async completions automatically.

Python
import litellm from respan import Respan from respan_instrumentation_litellm import LiteLLMInstrumentor respan = Respan(instrumentations=[LiteLLMInstrumentor()]) response = await litellm.acompletion( model="gpt-4.1-nano", messages=[{"role": "user", "content": "Tell me a joke"}], )

Multiple providers

LiteLLM’s unified interface means all providers are logged with the same callback.

Python
import litellm from respan import Respan from respan_instrumentation_litellm import LiteLLMInstrumentor respan = Respan(instrumentations=[LiteLLMInstrumentor()]) litellm.completion(model="gpt-4.1-nano", messages=[...]) litellm.completion(model="claude-sonnet-4-5-20250929", messages=[...]) litellm.completion(model="together_ai/meta-llama/Llama-3-70b", messages=[...])

Gateway

See LiteLLM gateway setup to route this integration through the Respan gateway.