How do I get an alert on my agent’s cost per trace?
Rius alerts on cost per trace through a custom alert that uses the Cost metric with the avg aggregation over a rolling window. Add a threshold in US dollars, optionally scope it to your agent’s service, and attach a channel. When the average cost per trace in the window crosses the threshold, Rius opens a firing and delivers it to every channel on the alert.
How it works
A custom alert is one or more rules evaluated over one shared rolling window. For cost per trace you need a single rule on the Cost metric.
- Aggregation. Numeric metrics use per-trace semantics, so
avg(Cost)is the average cost per trace in the window, not the workspace total. Cost also offers min, max, p50, p95 and p99. Use avg to watch the typical trace, and p95 or max to catch a few expensive runs that an average hides. - Unit. Cost is in US dollars. Rius prices spans from the model and token counts, so values are list-price estimates, not billed amounts.
- Filters. Filters apply before aggregation. Filter on Service (
service.name), Agent, Model, Step and more, so the alert watches one agent rather than the whole workspace. - Window. The window runs from 5 minutes to 24 hours and is shared by all rules.
- Evaluation. Rules are evaluated every minute while there is no open firing, and every five minutes while one is open.
Cost is only as complete as pricing coverage. A span whose model has no known price carries no cost, but per-trace averages still divide by every trace, so partial pricing coverage pulls the average down. A rule held under its threshold by low coverage stays quiet, so check which models are priced on the Usage and cost page before you rely on the alert.
Set it up
Configuring alerts is an admin action. Members can see alerts and acknowledge firings.
- Open the Alerts page and start a new custom alert in the Custom alerts section.
- Optionally add a Service filter, for example
Service = checkout-agent, so only your agent’s spans feed the rule. - Add one rule: metric Cost, aggregation avg, operator
>, and a dollar value above what a normal trace costs for that agent. - Set the window. A 15 minute window is the example in the rule grammar and reacts quickly. Choose a longer window if your agent runs few traces, so one expensive trace does not trip the alert alone. Choose a shorter one, down to 5 minutes, to react faster.
- Attach one or more distribution channels (webhook, email or Slack).
- Set Renotify. Off, the default, sends one notification per firing. Every N minutes, from 5 to 1440, repeats it until someone acknowledges the firing or it resolves.
- Read the plain-language preview in the builder. That sentence becomes the alert’s description. Then save.
The rule you build looks like this:
FILTERS Service = checkout-agent (optional, applied before aggregation)
RULES avg(Cost) > $0.50
WINDOW 15 minutes (shared by all rules)The $0.50 here comes from the grammar example. Set your own value from what your agent normally costs. If you also want a spike detector, create a second alert with p95(Cost), because rules in one alert combine with AND only and there is no OR.
What you get
- A firing when the condition matches. The firing opens the first time the average cost per trace crosses your threshold and stays open while it keeps matching.
- Delivery to every attached channel. The firing page lists one row per channel with the outcome of each attempt, and each renotify repeat appears as another row.
- The observed value against the threshold. Firings record the observed value of every rule next to its threshold, so you see how far over the limit the cost went.
- A coverage ratio. Firings on Cost show how much of the data had a price, so you can tell a real reading from a partly covered one.
- Affected traces. The firing page links the traces behind it, and View all in Traces opens the trace list filtered to the firing’s time window.
- Acknowledgment. Acknowledging records who saw it and stops further notifications. The firing resolves on its own after the condition has stopped matching for two hours. If the cost climbs again later, that is a new firing.
Saving a change to the alert resolves its open firings and starts evaluating afresh, so a condition that still holds opens a new firing under the new settings. Read more on the Alerts page.
When something else fits
- If you want a summary of cost rather than a trigger, read the same metrics on the Usage and cost page.
- If you care about total spend in a period rather than the cost of each run, note that avg(Cost) is per trace. The Cost metric offers no sum aggregation, so use the Usage and cost page for totals.
- If the problem is a recurring error, a swallowed error or a loop, the pre-defined alerts cover those without any rule to build.