Skip to Content

How do I get LLM cost with OpenLLMetry?

Rius computes LLM cost for OpenLLMetry spans itself, so you point the Traceloop exporter at Rius and send the model name and token counts. OpenLLMetry already records both, and Rius maps older attribute spellings onto the ones it prices at ingest. You set no cost attribute and no extra resource setting.

How it works

Rius computes cost on the server from two inputs on each model call span:

  • gen_ai.request.model, the requested model.
  • The gen_ai.usage.* token counts: gen_ai.usage.input_tokens, gen_ai.usage.output_tokens, gen_ai.usage.cache_read.input_tokens and gen_ai.usage.cache_write.input_tokens. Each is priced at its own rate.

A span needs the model and at least one count. Any count it leaves out is read as 0.

Does OpenLLMetry already set these? Yes. Current OpenLLMetry releases emit the OpenTelemetry GenAI (gen_ai.*) attributes directly. Older releases spell usage differently and flatten messages into gen_ai.prompt.* and gen_ai.completion.*. Rius normalizes all of those at ingest onto the canonical keys above, and a native gen_ai.* key always wins over a mapped one. So a Traceloop setup needs no attribute added by hand to get cost.

Costs are list-price estimates in US dollars, taken from LiteLLM’s public model-price catalog. They are not billed amounts. A span with no model, a model the catalog does not know, or none of the counts gets an empty cost, not zero. Never send a cost attribute. Send the model name and tokens.

Because Rius stores normalized values under the canonical keys, search and filter on gen_ai.usage.input_tokens, not on an older spelling. The full mapping is in the span attribute reference.

Set it up

  1. Point the Traceloop exporter at the Rius ingest endpoint with your API key. Create the key in the console first. It decides which workspace the traces land in. Use your workspace’s region in the host; eu is shown here.
from traceloop.sdk import Traceloop Traceloop.init( app_name="my-agent", api_endpoint="https://ingest.eu.console.rius-glassflow.com", headers={"Authorization": "Bearer <your API key>"}, )

OpenLLMetry exports OTLP over HTTP with protobuf by default, which is what the endpoint expects. The OpenLLMetry page covers the same setup, including configuring it through OpenLLMetry’s environment variables.

  1. Run one traced LLM call.

  2. Open Traces in the console and open the new trace. The model call span should show a model name, token counts and a cost.

  3. If the span shows a model and tokens but no cost, check the model name. A model the price catalog does not know gets an empty cost.

  4. If the span arrives without a model or tokens, attributes were probably dropped on the way. OpenTelemetry keeps at most 128 attributes per span by default and drops the rest silently. Older OpenLLMetry releases record one attribute per message field, so long agent runs pass that limit. Set OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT to 4096 in the environment of the process that runs Traceloop. A Collector attributes or transform processor that strips gen_ai.* keys causes the same symptom.

  5. For a call you trace in your own code rather than through OpenLLMetry’s instrumentation, set gen_ai.request.model and the gen_ai.usage.* counts on that span yourself. The attribute reference lists the exact keys. The Trace LLM calls with OpenTelemetry guide shows the other ways in.

What you get

  • A cost on every model call span that carries a model Rius can price and at least one token count.
  • Cache reads and cache writes priced at their own rates, not folded into the input price.
  • Cost totals and a per-model breakdown across your traces, in US dollars as list-price estimates.
  • The same cost analytics whether your OpenLLMetry release is current or older, because Rius maps the older spellings at ingest.
  • Prompt and completion content visible in trace inspection next to the cost.

When something else fits

  • If you want one setup that instruments the LLM libraries for you, use the Rius SDK. It sets the model and token attributes on its own, as the OpenTelemetry guide shows.
  • If you need custom model prices or negotiated, batch or other discounts, Rius does not offer them. Cost always comes from LiteLLM’s public list prices.

Still stuck? Get help

Last updated on