Skip to Content
Rius

What does Rius record when my agent calls the Anthropic API?

Rius records each Anthropic messages.create call as its own span with the model, token usage including cache reads and writes, the request and response messages, and a cost. You get this without changing your call sites, because the Anthropic integration instruments the client library for you. Streamed calls carry token usage but no time to first token. The full setup is on the Anthropic integration page.

How it works

With a global init, Rius turns on the Anthropic instrumentation if it is installed and instruments the client library process-wide. From then on, every messages.create call produces a span for that model call. Here is what each span holds:

  • Model. The model you requested, for example claude-haiku-4-5-20251001.
  • Tokens. Input and output token usage from the response, including cache reads and cache writes. Rius uses these counts, together with the model, to compute cost.
  • Cost. Rius computes it on its side from the model and the token counts. You never send a cost value. Costs are list-price US dollar estimates from LiteLLM’s public model-price catalog, with cache reads and writes at their own rates. A model the catalog does not know gets an empty cost, not zero.
  • Messages. The request and response messages, reassembled into the GenAI message shape. Text blocks become text parts. Tool calls become tool_call parts. Any other block, such as an image or a reasoning block, is kept as a text part holding the serialized block, so nothing is lost.
  • System prompt. Anthropic takes it as a separate system parameter. Rius records it as the leading system message of gen_ai.input.messages, where the console and context attribution read it.
  • Errors. A failed call records error.type as the error class, such as anthropic.NotFoundError.

Prompt and response content follows your privacy controls, exactly as manual generations do. Setting RIUS_CAPTURE_CONTENT to false strips content at export, and the structure, model, tokens and cost stay.

When a wrapper such as LangChain or LiteLLM sits over the Anthropic call, Rius counts the call once in token and cost totals. The wrapper span still shows the run’s total.

Set it up

  1. Install the instrumentation. The Python extra installs the instrumentation, not anthropic itself, so a project that already calls Anthropic keeps its own version. In TypeScript, install the OpenInference package for Anthropic and use version 0.2.7 or newer.
pip install "glassflow-rius[anthropic]" anthropic npm install @arizeai/openinference-instrumentation-anthropic
  1. Call init() before you create the client, then use the Anthropic client exactly as before. The installation and init steps are on the Anthropic page, and the Integrations overview covers how every integration is enabled.
  2. In TypeScript, check that the integration attached. await rius.ready resolves with the names that attached, so confirm anthropic is in the list. In a CommonJS app, require @anthropic-ai/sdk before init(), or the calls stay untraced even though anthropic is listed. On a pnpm app deployed to a file-tracing host such as a Vercel function, pass the modules you import with instrumentModules if anthropic is missing from the list.
  3. Run one call and open the trace in the console. The span shows the model, token counts and a cost. Wrap the call in observe to see it nested inside your agent’s run.

In Python, if anthropic is not installed in the environment, init() logs a DependencyConflict and leaves this integration off.

What you get

  • A span for every Anthropic model call, with model, input and output tokens, cache read and write tokens, and a computed cost.
  • Request and response messages, including the system prompt and tool calls, readable in the trace.
  • The error class on failed calls, so you can filter and alert on them.
  • Calls nested inside your agent’s run when you wrap the surrounding function in observe.
  • Token usage on streamed calls, because Anthropic reports it in the message lifecycle events.

Known limits:

  • No time to first token on auto-instrumented Anthropic streams. The OpenInference packages, in Python and TypeScript, do not record it. To get it for a call that matters, trace that call as a manual generation and use record_first_token().
  • Cost undercounts with old TypeScript packages. Versions of the TypeScript instrumentation before 0.2.7 report Anthropic’s cache-exclusive input count and drop both cache counts, so any call that uses prompt caching is undercounted.
  • A few setups still count a call twice. This happens when more than one instrumented layer wraps the same call.

When something else fits

If you use the Claude Agent SDK, Rius traces it manually with an observe root and a generation filled from the run result, so follow its own integration page. If you need time to first token on Anthropic streams, a manual generation records it where auto-instrumentation does not.

Still stuck? Get help

Last updated on