How do I see token counts for each call to the Anthropic API?
Rius records input and output token counts on the span for each Anthropic messages.create call, and shows them in the trace waterfall, the span detail and the Spans tab. You install the Anthropic integration, call init(), and use your client as before. Cache reads and cache writes are counted too, and cost is computed from the model and those counts. For the wider picture of watching agents, see Monitor AI agents in production.
How it works
The Anthropic integration patches the client library for the whole process, so you do not change your call sites.
- One span per call. Each messages.create call becomes a span for a model call. It carries the model name (for example
claude-haiku-4-5-20251001), input and output token usage from the response including cache reads and writes, and the request and response messages. - Streams count too. Token usage is captured on streamed calls, because Anthropic reports it in the message lifecycle events.
- Cost comes from the counts. Rius computes cost on its side from the model and the tokens. You never send a cost value.
- Your own span is optional. The integration records the model call by itself. Wrapping your agent function in
observeadds a span for your own run around it, so the model call appears nested inside that run instead of as a standalone trace. - A call with no usage has no cost. If a call reports no token usage, its cost is blank rather than $0, so it does not look free.
The integration is on by default after a global init() when its package is installed. If you limit integrations with an explicit instruments list, include anthropic. The full list of integrations is on the Integrations page.
Set it up
- Install the instrumentation for Anthropic. The extra installs the instrumentation, not the
anthropicpackage, so your project must already haveanthropic.
pip install "glassflow-rius[anthropic]" anthropic- Initialize Rius once at startup, wrap your function in
observeif you want a run around the call, and call Anthropic as usual.
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?")- In TypeScript, install the instrumentation package instead. It must be version 0.2.7 or newer, because earlier versions drop both cache counts and make cost undercount calls that use prompt caching.
npm install @arizeai/openinference-instrumentation-anthropicAfter init(), await rius.ready resolves with the integrations that attached, so you can check that anthropic is listed. In a CommonJS app, require @anthropic-ai/sdk before init(), or the calls stay untraced.
- Run one call and open the Traces page in the console. Open the trace and read the counts in these places:
- In the waterfall, the span for the model call shows its token counts inline.
- Select the span and read the Model section: provider, requested and response model, input and output tokens, and cost.
- On the Spans tab, filter with the All kinds menu to LLM and sort by the Tokens header to find the heaviest calls.
- On a trace with several model calls, the context growth strip above the tree plots input tokens per call in order.
The trace list also shows a token total and a computed cost for each trace. Exploring traces covers these views in full.
What you get
- Input and output tokens for every Anthropic call, on the span for that call, with cache reads and writes included.
- A cost estimate for each call, in US dollars at list price, computed from the model and token counts.
- Token totals for each trace in the list and in the trace header, so you can compare runs.
- A per-call view of how the prompt grows across a run, from the context growth strip.
- Prompt and response content on the Input / Output tab, subject to your privacy controls. When content is stripped, the tokens and cost still show.
When something else fits
- Auto-instrumented Anthropic streams carry token counts but no time to first token. That value is not recorded by the Anthropic integration, so it does not appear for those calls.
- If a span shows no cost, either the call reported no token usage or the model is not in the price catalog. Check that the call returned a normal response with usage.
- For other providers or frameworks, the Integrations page lists what each one records.