Skip to Content

LiteLLM

Trace calls routed through LiteLLM with Rius: one integration covers every provider behind the router.

This integration is Python only, as is the LiteLLM library itself. From TypeScript, calls to a LiteLLM proxy over its OpenAI-compatible endpoint are traced by the OpenAI integration, since you make them with the OpenAI client. The model recorded is the one you ask the proxy for, not whichever provider it routes to.

Setup

pip install "glassflow-rius[litellm]" litellm

The extra installs the instrumentation, not litellm itself, so the package is named here for a fresh environment. A project that already calls LiteLLM has it, and pip leaves it untouched. Without it, init() logs a DependencyConflict and this integration stays off.

import rius import litellm rius.init(api_key="ri_...", service_name="my-agent") response = litellm.completion( model="gpt-4o-mini", # or any provider LiteLLM routes to messages=[{"role": "user", "content": "hi"}], )

What gets captured

Each routed completion becomes an LLM-kind span with the model, token usage, and messages; cost is computed server-side from the model and tokens. Because LiteLLM normalizes providers behind one API, this single extra gives you model analytics across every provider you route to, and switching providers keeps your tracing unchanged.

LiteLLM calls OpenAI and OpenAI-compatible providers through the openai client library. If the openai extra is installed too, that client call is traced as a second LLM span under the LiteLLM span. Since glassflow-rius 1.0.2 the call is still counted once in tokens and cost, and the LiteLLM span still shows the run’s total. A few setups, such as streamed calls on some instrumentation versions, are still counted twice; see Still counted twice.

The model name is stored without LiteLLM’s routing prefix when the prefix names the provider (since 1.0.1), so openai/gpt-4o-mini lands as gpt-4o-mini with the provider openai. Update model filters that matched the prefixed form.

Verify

Run one completion, then open the trace in the console: the span shows the model, token counts, and a cost. Route the same call to a different provider and the comparison shows up in model analytics.

If you use LiteLLM as a proxy server rather than the Python library, the proxy is a separate process: instrument the proxy itself or send its OTel traces via the interoperability path.

Last updated on