How do I alert on cost per trace for a single model?
Rius lets you alert on cost per trace for one model with a custom alert that has a Model filter and a rule on the Cost metric, such as avg(Cost) > $0.50. The filter picks the spans that feed the rule, and Cost is aggregated per trace over a rolling window. You build it in the custom alert builder, which shows a plain-language preview of when the alert fires.
How it works
A custom alert has three parts: optional filters, one or more rules, and one shared window. Rules combine with AND only, and there is no OR.
- The filter this needs. Model matches
gen_ai.request.model. Filters apply before any aggregation, so only spans for the model you pick feed the rule. Each filter matches a span’s own value, so any span that carries that model value is selected, not only the root span. Model offers=,≠,inandnot_in, and values are suggested from your workspace’s live data. Useinto cover several model names with one alert. - How Cost aggregates. Cost is a numeric metric in USD with avg, min, max, p50, p95 and p99. Numeric metrics aggregate per trace, so
avg(Cost)is the average cost per trace in the window, not the workspace total. With the Model filter in place, that average is over the spans of the model you selected. - Per-call metrics. Time to first token, Context usage and LLM calls are the exception. They are measured per LLM call, so their aggregations run over calls, not traces. An LLM call is an inference call, the kind of span the trace view badges as LLM. Agent, tool, retrieval and embedding spans never count, even when they carry a model.
- Pick the aggregation for your goal. Use avg to watch the typical trace, and p95 or p99 to catch the few expensive traces that an average hides.
- Limits. An alert takes up to 10 filters with up to 50 values each, up to 10 rules, and a window from 5 minutes to 24 hours.
Set it up
- Open the custom alert builder and add a filter with the field Model. Choose
=for one model, orinfor a list, and select the model name from the suggestions. - Add a rule: metric Cost, an aggregation such as avg or p95, an operator from
<,<=,>,>=and==, and a value in USD. - Set the window. A shorter window reacts faster, and a longer one smooths out single expensive traces. Every rule in the alert shares this window.
- Optionally add more rules. They combine with AND, so the alert fires only when all of them hold. For example, add a rule on a per-call metric to require both a high cost per trace and slow first tokens.
- Attach the channels you want, such as webhook, email or Slack, and set Renotify to off or every N minutes.
- Read the preview sentence. It becomes the alert’s description on its details page, so check that it names the model and the threshold you meant.
The alert reads like this:
FILTERS Model = claude-haiku-4-5-20251001
RULES avg(Cost) > $0.50
WINDOW 15 minutesFor the full builder, see Custom alerts. For how alerts fire, renotify and reach channels, see Alerts.
What you get
- An alert that watches cost per trace for the model you choose, and ignores spans from other models.
- A firing record that shows the observed value of every rule against its threshold, so you can see which condition tripped.
- Coverage on each firing. Cost exists only for spans whose model has a known price, and a firing shows the coverage ratio so you can tell a full reading from a partly covered one. A rule held under its threshold by low coverage stays quiet, so check that your model is priced on the Usage and cost page before you rely on the alert.
- Costs in USD that are list-price estimates from LiteLLM’s public model-price catalog, not billed amounts. Set thresholds with that in mind.
- A custom alert you can edit later, and delete when you no longer need it. Deleting it removes its firing history after you confirm.
When something else fits
- If you need either-or conditions, create a second alert, because rules within one alert combine with AND only.
- If you want a one-off look at cost by model rather than a trigger, the Usage and cost page shows cost by model as a summary instead of an alert.
Related
Last updated on