Skip to Content
Rius

How does Rius count prompt cache tokens from the Anthropic API?

Rius prices the cache read and cache write tokens on each Anthropic call at their own rates, separate from regular input and output tokens. The Anthropic integration captures both counts from the response, and Rius multiplies each by its rate when the span arrives. The result is a list-price estimate in US dollars, stored on the span for that call.

How it works

  • Capture. Each messages.create call becomes a span with the model, input and output token usage, and the cache reads and writes from the response. Streamed calls report usage too.
  • Attributes. The cache counts travel as gen_ai.usage.cache_read.input_tokens and gen_ai.usage.cache_write.input_tokens, next to gen_ai.usage.input_tokens, gen_ai.usage.output_tokens and gen_ai.request.model. You never send a cost.
  • Input total. Rius reads input tokens as the whole prompt, cached tokens included. The uncached share is that total minus the cache reads and writes, so cached tokens are not billed twice at the input rate.
  • Price lookup. Rius looks up gen_ai.request.model in LiteLLM’s public model-price catalog and prices each count at its own rate:
cost = uncached input tokens × input price + cache read tokens × cache read price + cache write tokens × cache write price + output tokens × output price
  • Model names. Dated snapshots such as claude-sonnet-4-5-20250929, and the Amazon Bedrock and Google Vertex AI forms, resolve to the same price. A span that carries only gen_ai.response.model is not priced.
  • Fallback. If a model’s catalog entry has no separate cache rates, its cache tokens are charged the input rate.
  • Fixed at write time. Cost is set when the span is written. A later price change does not rewrite past calls.

Set it up

  1. Install the instrumentation. Python uses the anthropic extra, which does not install anthropic itself. TypeScript uses the OpenInference package for Anthropic:
pip install "glassflow-rius[anthropic]" anthropic npm install @arizeai/openinference-instrumentation-anthropic
  1. In TypeScript, use version 0.2.7 or newer of that package. Earlier versions report Anthropic’s cache-exclusive input count and drop both cache counts, so cost undercounts any call that uses prompt caching.
  2. Call init() once, then use your Anthropic client as before. The Anthropic integration page has the full Python and TypeScript setup, including the CommonJS ordering rule.
  3. Make a call that uses prompt caching, then open the trace in the console. The span detail shows the model, token counts and a cost for that call.
  4. If a call shows no cost, check that its model name is in the price catalog and that the span carried token usage. See Track LLM and agent cost for how pricing works.

What you get

  • A cost on each Anthropic call that reflects cache reads and writes at their own rates, not everything at the input rate.
  • The call’s tokens and cost in the span detail. The same cost rolls up into the trace list and header, each agent, each end user, and the workspace totals and cost by model on Usage and cost.
  • An empty cost, not $0, for a call whose model is not in the catalog or that reported no token usage. A total with nothing priced shows a dash in the console.
  • Cost alerts and MCP questions built on the same per-call figures, as described in Track LLM and agent cost.

When something else fits

  • Costs are list-price estimates at each model’s standard rates. Rius does not apply long-context tiers, batch, flex or priority pricing, or any discount you negotiated, so use Anthropic’s invoice when you need the billed amount.
  • Time to first token is not recorded by the Anthropic integration on streamed calls. If you need it, trace that call as a manual generation, as the Anthropic integration page describes.

Still stuck? Get help

Last updated on