How do I track LLM cost per agent?
Rius splits LLM cost per agent for you: it prices each model call at ingest and rolls the cost up under the agent that produced the trace. Each LLM span needs the requested model and its token counts, and the process needs an agent name, which defaults to the service name. You read the split on the Agents page in the console, or over MCP with agent_traces_summary. Costs are list-price estimates in US dollars.
How it works
Two things on your spans decide the split.
Cost needs the model and the token counts. Rius looks up the requested model (gen_ai.request.model) in LiteLLM’s public model-price catalog and multiplies each token count by its rate. The counts come from gen_ai.usage.input_tokens, gen_ai.usage.output_tokens, and the cache attributes gen_ai.usage.cache_read.input_tokens and gen_ai.usage.cache_write.input_tokens. A span that carries only gen_ai.response.model is not priced. You never send a cost attribute, and one you send is ignored. See Track LLM and agent cost for how a call is priced.
The agent name decides where the cost lands. Rius names an agent from the first of these that is set:
gen_ai.main_agent.nameon the resourcerius.main_agent.nameon the resourcegen_ai.agent.nameon the resourcegen_ai.agent.nameon the span- the service name (
service.name)
The Rius SDKs set the main-agent keys for you. With a plain OpenTelemetry SDK, set gen_ai.main_agent.name and gen_ai.main_agent.id as resource attributes yourself. A trace that arrives without a root span gets an inferred root, so it still counts toward the right agent.
A model with no catalog price gets an empty cost, not zero, so an unpriced call never reads as $0. Totals add up the calls that were priced.
Set it up
- Give each agent its own name. Set
agent_nameininit(orRIUS_AGENT_NAME). If you skip it, the service name is the agent name, so two agents that share a service name show up as one. The other steps of installing the SDK are in Installation and configuration.
import rius
client = rius.init(
api_key="ri_...",
service_name="checkout-agent",
agent_name="checkout-agent",
heartbeat_interval=15,
)
# ... run your agent ...
client.shutdown() # sends the final `stopped` heartbeat- Make sure every model call carries the requested model and its input and output token counts. If you use a plain OpenTelemetry SDK, check that those spans carry
gen_ai.request.modeland thegen_ai.usage.*counts listed above. - Optionally tag versions with
RIUS_MAIN_AGENT_VERSION(the agent definition) andRIUS_SERVICE_VERSION(the build). This lets you see cost per trace by version. - Run the agent, open Agents in the console, and check that it appears with a cost. Trace figures count only finished traces, so a run shows up once every span of it has ended.
To read the split over MCP, connect the Rius MCP server and ask, for example, “What did my agents cost this week, and which service is spending the most?”
What you get
- Agents list. The Agents page shows total cost for each agent over the selected window (15m, 1h, 1d, 7d or 30d). Rows with problems come first, so an agent whose cost is climbing is easy to spot.
- Agent page. The Cost tile shows total cost and average cost per trace for that agent.
- Drift. A chart of cost per trace over time shows when an agent started costing more.
- Compare. With two or more versions, cost per trace sits side by side with the change. Rius warns when either side has fewer than 20 traces, since the difference can be noise.
- Workspace view. Usage and cost shows the workspace total, cost by model, and the most active agents, so you can set one agent against the whole.
- Over MCP.
agent_traces_summaryreturns the summary for one agent or service, optionally per time bucket.workspace_metrics_overviewreturns the workspace total and cost by model.compare_agent_versionscompares versions of an agent. - Alerts. Cost is a metric in custom alerts, measured per trace and filterable by agent, for example p95 cost per trace above a limit.
Costs are list-price estimates from standard model rates. They do not include negotiated discounts, batch pricing or long-context tiers, so expect your provider invoice to differ.
When something else fits
If you need cost per customer rather than per agent, use Users with user.id, or one workspace per customer. If you need a total-spend budget alert for the whole workspace, watch it on Usage and cost, because it is not an alert metric today.