LiteLLM Python SDK
Install LiteLLM and the OpenTelemetry packages:
python -m pip install -U litellm opentelemetry-sdk opentelemetry-exporter-otlp-proto-http
Set the destination and its key. The callback sends OTLP over HTTP to /v1/traces with Bearer authentication in both setups.
| Destination | LENS_URL | LENS_TRACING_KEY |
|---|---|---|
| Standalone Lens | Lens base URL, such as http://localhost:4318 | Dedicated Lens tracing key |
| LiteLLM Gateway connected to Lens | Gateway base URL, such as http://localhost:4000 | LiteLLM virtual key for that gateway |
Keep any path prefix, but leave off the /v1/traces suffix. For standalone Lens, for example:
export LENS_URL="http://localhost:4318"
export LENS_TRACING_KEY="YOUR_LENS_TRACING_KEY"
Tracing configuration does not change where model calls go. This example calls OpenAI directly and uses OPENAI_API_KEY.
import litellm
litellm.callbacks = ["lens"]
with litellm.trace_agent("support_triage"):
category = litellm.completion(
model="gpt-4.1-mini",
messages=[{"role": "user", "content": "Classify this ticket: I can't reset my password."}],
).choices[0].message.content
litellm.completion(
model="gpt-4.1-mini",
messages=[{"role": "user", "content": f"Suggest a next step for this ticket category: {category}"}],
)
In Lens, open Agents and select support_triage. Each execution of the block appears as one run with two model calls. Calls outside the block still appear in Traces, without a named agent run. In async code, use async with litellm.trace_agent(...) with await litellm.acompletion(...).