Skip to Content

What does Rius record when my agent calls LiteLLM?

Rius records each LiteLLM completion as a span for the model call, with the model, token usage and messages, and computes the cost from the model and token counts. One extra covers every provider LiteLLM routes to, so switching providers leaves your tracing unchanged. The integration is Python only, and a few details about model names and repeated spans are worth knowing before you filter or total anything.

How it works

The litellm instrumentation in the Python SDK watches LiteLLM completions. With a global rius.init(), every installed integration turns on automatically, so you add no wrapper code around your calls.

Each routed completion becomes one span for the model call. It carries:

  • Model. The model name is stored without LiteLLM’s routing prefix when the prefix names the provider. openai/gpt-4o-mini lands as gpt-4o-mini with the provider openai. This applies from glassflow-rius 1.0.1, so update any model filter that matched the prefixed form.
  • Token usage. The token counts for the call.
  • Messages. The messages sent to and returned by the model.
  • Cost. You send no cost value. Rius computes cost on its side from the model and the token counts. It is a list-price estimate in US dollars, and a model Rius does not know gets an empty cost, not zero.

LiteLLM reaches 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 span for the model call 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.

Set it up

  1. Install the instrumentation and 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 keeps the version it has.
pip install "glassflow-rius[litellm]" litellm
  1. Call rius.init() before your first completion. Nothing else in your LiteLLM code changes.
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"}], )
  1. If you want to limit which integrations attach, pass instruments=["litellm"] to init(). A scoped client created with set_global=False does not auto-instrument, so pass instruments explicitly there.

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

If the extra is installed without litellm in the environment, init() logs a DependencyConflict and this integration stays off. For the other integrations and how they are installed, see Integrations. The full LiteLLM walkthrough is on the LiteLLM integration page.

What you get

  • A span for every routed completion, with the model, token usage and messages.
  • A cost per call, computed by Rius as a list-price estimate in US dollars, with no cost attribute for you to send.
  • Model analytics across every provider behind LiteLLM, from a single extra.
  • Token and cost totals that count a call once, even when the openai client underneath adds its own span, while the LiteLLM span still shows the run’s total.
  • Model names without the provider routing prefix, so openai/gpt-4o-mini is filterable as gpt-4o-mini.

Known limits:

  • The integration is Python only, as is the LiteLLM library.
  • Some streamed calls on certain instrumentation versions are still counted twice.
  • A LiteLLM proxy server is a separate process. The Python integration does not trace it from your application.

When something else fits

From TypeScript, calls to a LiteLLM proxy over its OpenAI-compatible endpoint are traced by the OpenAI integration, and the model recorded is the one you ask the proxy for, not the provider it routes to. If you run LiteLLM as a proxy server, instrument the proxy itself or send its OpenTelemetry traces to Rius through the interoperability path.

Still stuck? Get help

Last updated on