How do I see retries and fallbacks for calls to the Anthropic API?
Rius records each Anthropic messages.create call as its own span, so every retry or fallback attempt you make appears as a separate model call in the trace. A span around your retry logic groups the attempts, and the trace page shows a run that recovered as recovered. A failed call records its error class in error.type.
How it works
Two layers show retries and fallbacks, and they come from different places.
What the integration records. With the Anthropic integration on, each messages.create call becomes an LLM-kind span. It carries:
- the model, for example
claude-haiku-4-5-20251001 - input and output token usage, including cache reads and writes
- the request and response messages
- a cost that Rius computes from the model and tokens
A failed call records error.type as the error class, such as anthropic.NotFoundError. If your code calls messages.create again after a failure, each attempt is a separate span with its own error or result. A fallback to a second model is a separate span too, and its model field shows which model answered.
What needs your own span. The integration sees individual calls. It does not know that three calls were one logical request, or that you switched models on purpose. To show that, wrap the retry loop and the single call in observe. The loop becomes a parent step, and each attempt nests under it.
Where it shows in the trace. The trace page reads the result from the spans:
- A trace is
failedwhen any span has an error status. If the root span finished without an error of its own, the trace is badged recovered. The child spans errored, you retried or fell back, and the run completed clean. - Back-to-back calls of the same step with the same input collapse into one row such as
fetch_article · 3 attempts · recovered, when every attempt but the last failed. Expand the row to see the individual attempts. Repeated calls that succeeded stay separate rows. - Failed spans are highlighted along the path from the root to the error in the waterfall view.
Set it up
-
Turn on the Anthropic integration. Install the extra and the library, then call
init()once. The Anthropic integration page covers TypeScript, and Integrations covers the other libraries.pip install "glassflow-rius[anthropic]" anthropic -
Wrap the single model call and the retry loop with
rius.observe. Replace the model names and attempt counts with your own.import anthropic import rius rius.init(api_key="ri_...", service_name="my-agent") claude = anthropic.Anthropic(max_retries=0) # retry in the loop below instead PRIMARY = "claude-haiku-4-5-20251001" FALLBACK = "your-fallback-model" @rius.observe def call_model(query: str, model: str) -> str: response = claude.messages.create( model=model, max_tokens=200, messages=[{"role": "user", "content": query}], ) return response.content[0].text @rius.observe def ask(query: str) -> str: for model, attempts in [(PRIMARY, 3), (FALLBACK, 1)]: for _ in range(attempts): try: return call_model(query, model) except Exception: continue raise RuntimeError("all models failed")The Anthropic client retries rate limits, server errors and timeouts by itself (
max_retries, 2 by default) inside onecreate()call, so those attempts make one span.max_retries=0leaves the retrying to your loop, where each attempt is its own span. Eachcall_modelrun is a step with the model call nested inside it. Retries on the same model repeat the same input, and the fallback uses a different model. -
Run a request that triggers a retry, then open the trace on the Traces page. Read the retry row, the recovered badge and the model on each LLM span.
-
To find these calls across many traces, open the Spans tab. Choose LLM in the All kinds menu, filter by status to see only failed calls, and add a filter on the model to see how often the fallback model answers. Pasting a session ID in the search box lists every span of that session. See Exploring traces for filters and saved searches.
The Monitor AI agents in production guide covers how to keep watching this after launch.
What you get
- One span per Anthropic call, each with its model, tokens, a cost estimate and an error class when it fails. Costs are list-price estimates in US dollars.
- A parent step that groups the attempts, so a retry loop reads as one event.
- A recovered badge on traces where child calls failed but the run finished clean. The errors are still counted, and only the verdict changes.
- Collapsed retry rows with an attempt count, which you can expand to inspect each failed call.
- The Context growth strip above the tree for traces with several LLM calls, plotting input tokens per call in order.
- A Since previous llm call view on each LLM span’s Input / Output tab, showing what each attempt added or changed in the prompt. Content shows only when your privacy controls allow it.
When something else fits
- If you only need the outcome of each call, the integration alone is enough. Every
messages.createcall already appears as its own span with tokens and cost. - If your retries run inside a framework that Rius has its own integration for, such as LangChain or LiteLLM, read that integration’s page. It describes which spans it records.