How do I measure what my AI agent costs to run?
Rius prices every LLM call from its model and token counts, then rolls that cost up per trace, per agent, per end user and per workspace. You send the model name and token usage your instrumentation already records, and Rius computes the cost. Watch the average cost per trace and the p95 of cost per trace, and use cost by model to see where the money goes.
How it works
Rius prices each LLM span when it arrives. It looks up the requested model (gen_ai.request.model) in LiteLLM’s public model-price catalog and multiplies each token count by its own rate. Cost is in US dollars.
cost = uncached input tokens × input price
+ cache read tokens × cache read price
+ cache write tokens × cache write price
+ output tokens × output price- Cost per call. Open a span to see its provider, model, input and output tokens, and its cost.
- Cost per trace. The trace list, the summary strip and the trace header show the cost of one whole run.
- Averages. Usage and cost shows total cost for the window with per-trace and per-1k-token averages, and compares them with the previous period. Agent and user pages show total cost and average cost per trace.
- Percentiles. Cost is a metric in custom alerts, measured per trace, with avg, min, max, p50, p95 and p99 aggregations over a rolling window of 5 minutes to 24 hours.
- Cache tokens. Cache reads and writes are priced at the provider’s cache rates. Input tokens are read as the total prompt, so the uncached share is the total minus cache reads and writes.
Costs are list-price estimates. Rius applies each model’s standard rates, so long-context tiers, batch, flex or priority pricing and negotiated discounts are not reflected. Expect your invoice to differ.
If a model is not in the catalog, or a span reports no token usage, its cost stays empty, not zero. Totals add up only the priced calls, and averages per trace divide by every trace, so partial pricing lowers both. A span that carries only gen_ai.response.model is not priced.
Set it up
- Install the SDK with the extra for your provider. This example uses Anthropic.
pip install "glassflow-rius[anthropic]" anthropic- Initialize Rius and wrap your agent’s entry point. Every Claude call inside it is traced with its model and token usage, and Rius adds the cost.
import anthropic
import rius
rius.init(api_key="ri_...", service_name="my-agent")
claude = anthropic.Anthropic() # reads ANTHROPIC_API_KEY
@rius.observe
def handle(query: str) -> str:
response = claude.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=200,
messages=[{"role": "user", "content": query}],
)
return response.content[0].text
handle("What should I check when a collector drops spans?")- Never send a cost value. Rius ignores a cost attribute and computes its own from the model and tokens.
- Open Usage and cost and pick a window from 15 minutes to 30 days. Read total cost, the average per trace, and the average per 1k tokens.
- Open a trace and use the cost lens on the map view to see which steps spent the money in that run. The Spans tab sorts individual calls by cost.
- Add a cost alert for the tail. This rule fires when the p95 cost per trace in the last hour passes two dollars.
FILTERS Service = checkout-agent
RULES p95(Cost) > $2.00
WINDOW 1 hour- To see cost per customer, set
user.idon your spans and sort the Users page by cost. If you run one workspace per customer, the workspace total is that customer’s cost. The Track LLM and agent cost guide covers both.
What you get
- A cost on every priced LLM call, and a total on every trace, so you can compare a typical run with an expensive one.
- The average cost per trace and per 1k tokens for the window, with the change against the previous period.
- Cost by model, with how many LLM calls were priced, so you can see which model accounts for most of your spend.
- Token counts split into input, output, and cache reads and writes, so you can see whether a rising cost comes from a longer prompt, longer output or fewer cache hits.
- A p95 or p99 view of cost per trace through alerts, which catches runs that got expensive, such as a prompt that grew or an agent stuck retrying.
- Alerts that show the share of the window that was priced, so you can tell a high reading from a partly priced one.
Where the money goes in your own agent depends on its models and prompts. Cost by model, the cost lens on a trace and the Spans tab sorted by cost show you.
When something else fits
- If you need a budget or total-spend threshold for the whole workspace, watch it on Usage and cost, because workspace spend is not an alert metric today.
- If you need exact billed amounts, use your provider’s invoice. Rius shows list-price estimates.
- If you use custom model prices or negotiated discounts, Rius does not apply them, so reconcile against your provider’s billing.
Related
Still stuck? Get help