How can I see token counts for each call for my AI agent?
Rius shows token counts for every model call once the span for that call carries the model name and its input and output token counts. In the trace view, the waterfall shows tokens inline on each LLM span, and the span details show input and output tokens in the Model section. The SDK sets these attributes for you on auto-instrumented calls.
How it works
Rius reads token counts from the span for each model call, which is a span of kind LLM that Rius calls a generation. These are the attributes it reads:
gen_ai.request.model, the model that was requested.gen_ai.usage.input_tokensandgen_ai.usage.output_tokens, the counts for the call.- Optionally
gen_ai.usage.cache_read.input_tokens,gen_ai.usage.cache_write.input_tokensandgen_ai.usage.reasoning.output_tokens, when the provider reports them.
Token counts are metadata, not content. If you strip prompts and completions with the SDK’s privacy controls, the token counts still arrive and still show. Rius also adds prompt-cache reads and writes back into the total when a provider reports input tokens without them, so a total means every token the call processed.
You never send cost. Rius computes it from the model and these counts. A call that reported no token usage shows a blank cost, not $0. If a call shows no tokens, check that its span carries the usage attributes above.
Where the numbers appear:
- Waterfall: LLM spans show their token counts inline. The trace header shows total tokens and cost for the whole run.
- Span details: select a span and the Model section lists provider, requested and response model, input and output tokens, and cost.
- Trace list: each row has a token total column.
- Spans tab: one row per span, with a Tokens column you can sort.
- Map view: a lens for tokens shows where they went across the trace.
- Context growth strip: for a trace with several LLM calls, it plots input tokens per call in order.
Set it up
- Send spans that carry token usage. With the Rius SDK, auto-instrumentation records the model and token counts on each call to a supported library, so you add no attributes yourself. This Python example traces an Anthropic call. Install and
initare covered in full in SDK installation and the quickstart, so this is the short version:
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?")- If you send traces without the SDK, set
gen_ai.request.model,gen_ai.usage.input_tokensandgen_ai.usage.output_tokenson the span for each model call, withgen_ai.operation.nameset tochat. Do not send a cost attribute. - Open Traces in the console and click a trace. In the waterfall, find the spans badged llm. Each shows its token counts inline.
- Select one LLM span. In the detail panel, read input tokens, output tokens and cost in the Model section. Use the previous and next buttons, or
]land[l, to step from one LLM span to the next. - To compare calls across many runs, open the Spans tab, pick LLM in the All kinds menu, and click the Tokens header to sort. See Exploring traces for the filters and the keyboard shortcuts.
- To spot a prompt that keeps growing, look at the context growth strip above the tree. Click a bar to select that call.
What you get
- Input and output tokens on every model call, inline in the waterfall and in full in the span’s Model section.
- Total tokens and cost for the whole trace in its header, and a token total on each row of the trace list.
- A sortable Tokens column on the Spans tab, so you can find the heaviest calls across runs.
- A tokens lens on the map view and an input-token strip per call, so you see where tokens went inside one run.
- Token counts that keep flowing when you strip prompt content, so privacy settings do not cost you usage numbers.
- Cost per call computed by Rius from those counts, as a list-price estimate in US dollars.
For how to find traces, filter them and read them in the other views, the Monitor AI agents in production guide gives the wider picture.
When something else fits
- If you trace Claude Code or Codex (beta) sessions, the plugin reports tokens and cost. Cursor (beta) sessions carry no token counts or cost, because Cursor’s hooks do not report usage.
- For totals across many traces rather than one call, use the usage and cost views in monitoring instead of the trace view.