Skip to Content

How do I alert on LLM cost per request?

Rius alerts on cost per request with a custom alert on the Cost metric, which is measured per trace, so a max(Cost) rule fires when any single run costs more than your limit. You can narrow the rule with filters for service, agent, step, model, span kind, operation, session and instance. A single LLM call inside a run cannot be targeted by an alert, so use the trace views for that.

How it works

A request to your agent is one trace, and the Cost metric in a custom alert is the cost of each trace in the rolling window. The aggregations are avg, min, max, p50, p95 and p99. Pick the one that matches the question you are asking:

  • max(Cost) fires when the most expensive single run in the window crosses your limit.
  • p95(Cost) fires when the costliest 5% of runs cross it, which ignores one-off outliers.
  • avg(Cost) is the average cost per trace, not the workspace total.

Filters select which spans feed the rule before anything is aggregated. You can filter by service, agent, step (the span name), model, span kind, operation, session and instance. Text filters offer =, ≠, in and not_in, and the builder suggests values from your workspace’s live data. Rules combine with AND only and share one window between 5 minutes and 24 hours.

Cost comes from the model and token counts on each LLM span, priced from LiteLLM’s public catalog in US dollars. The numbers are list-price estimates, so a threshold is a guide, not your invoice. See Track LLM and agent cost for how a call is priced.

Set it up

  1. Decide what a request is for your agent. If one user message produces one trace, a per-trace rule is a per-request rule.
  2. Create a custom alert and add the rule. This one fires when any single run of the checkout agent costs more than $2.00 within a 15 minute window:
FILTERS Service = checkout-agent RULES max(Cost) > $2.00 WINDOW 15 minutes
  1. Narrow it further if you need to. Add a Model filter to watch one model, or an Agent filter to watch one agent inside a service. A Session or Instance filter scopes the rule to one session or one process. Cost lives on model-call spans, so a Step or Span kind filter that selects a tool, chain or agent span measures no cost. Filter Step to an LLM span name, or use Service, Agent or Model.
  2. Add a second rule to the same alert if you want both conditions to hold. Rules combine with AND, so for either-or behavior create a second alert.
  3. Attach a channel (webhook, email or Slack) and choose whether the alert renotifies, off or every N minutes.
  4. If you work through an MCP client, ask it to set the same rule up. It uses create_alert_rule.

If your model names have no price in the catalog, the rule has nothing to measure, so check that your models are priced before you rely on it.

What you get

  • An alert that catches the runs that got expensive, such as a prompt that grew or an agent stuck retrying.
  • Firings that record the observed value of every rule against its threshold, so you see which condition tripped.
  • A pricing coverage figure on each firing, so you can tell a high reading from a partly priced one. A rule whose models are mostly unpriced can stay quiet without firing, because coverage is attached only to firings.
  • A way to look at the expensive runs afterward. In Exploring traces, the trace list shows cost per trace, the map view has a cost lens, and the Spans tab sorts individual calls when you click the Cost header.

What the alert cannot do:

  • Target one LLM call. Cost is measured per trace, so the rule cannot watch a single call inside a run.
  • Filter by end user. User is not an alert filter. Sort the Users page by cost to find your most expensive customers.
  • Alert on total spend. A workspace budget threshold is not an alert metric. Watch total spend on Usage and cost.

When something else fits

  • To find one expensive call, open the trace and use the cost lens on the map view, or sort the Spans tab by cost.
  • To watch spend for the whole workspace or by customer, use Usage and cost and the Users page. If you run one workspace per customer, the workspace total is that customer’s cost.
  • If you want the alert on a ratio or a count rather than dollars, such as error rate or LLM calls, those are separate metrics in the same custom alert builder.

Still stuck? Get help

Last updated on