Why does my Claude Agent SDK agent suddenly cost more?
Rius shows the cause of a cost jump on the span for each Claude Agent SDK turn, which records the model, token counts and cost, so you can see which of those changed. Open the Spans tab, sort by cost, and compare an expensive turn with an older cheaper one. Then add a cost alert so the next jump reaches you as it happens. Costs are list-price estimates in US dollars, so read them as a trend rather than an invoice.
How it works
The Claude Agent SDK runs the Claude Code runtime in a separate process, so Rius records it with two explicit pieces: an observe root that makes each task an AGENT span, and one generation per turn that you fill from the run’s result. See the Claude Agent SDK integration for the full setup. Rius computes cost from the requested model and the token counts, with cache reads and writes at their own rates. Each task is one trace:
handle-task AGENT 5.0s
└─ claude_agent_turn LLM 5.0s claude-haiku-4-5, tokens + costBecause cost is a product of model and tokens, a rise has a short list of causes, and each one shows on that generation span:
- A different model. The price follows the requested model, so a change of model id changes the price per token.
- More tokens. Input, output or cache tokens per turn grew, for example from a longer prompt or more work inside the turn. The runtime’s tool calls and sub-turns produce no spans of their own, so extra internal work appears only as larger totals on the turn.
- More tasks. Cost per trace is flat, but there are more traces.
- A change in what is priced. Rius leaves the cost empty, not zero, when the model is unknown to the price table. A generation that used an alias such as
haikuinstead of a full model id had no cost. Switching to the full id makes it appear, which looks like a jump. Likewise, passing the cache counts from the result message adds those tokens to the input total, and cache-heavy runs then cost more than they appeared to before.
More on how Rius prices a call is in Track LLM and agent cost.
Set it up
- Open Traces and set the time range to cover the jump. Read cost per trace in the list and the summary strip, and note when it changed. Whether the jump is a few expensive runs or all runs tells you whether to look at tokens or at the model. Exploring traces covers the list and filters.
- Switch to the Spans tab, filter the kind to LLM with the All kinds menu, and click the Cost header to sort. Filter by model to see whether a new model id appears in the expensive rows.
- Open the most expensive generation and read the Model section: requested and response model, input and output tokens, and cost. Open a cheaper generation from before the jump and compare. If tokens are similar but cost differs, the model changed. If the model is the same, tokens grew.
- Use Compare runs on a trace to compare it with another run of the same agent. Paste a session ID in the Spans search box to list every span of one conversation, if you scope tasks with
rius.session(). - Check your generation code for the two settings that move cost. Use a full model id for the generation, keep
provider="anthropic", and pass the result message’s cache counts as they are:
with rius.start_as_current_generation(
"claude_agent_turn", model=MODEL, provider="anthropic", input=task
) as gen:
...
gen.set_usage(
input_tokens=usage.get("input_tokens"),
output_tokens=usage.get("output_tokens"),
cache_read_input_tokens=usage.get("cache_read_input_tokens"),
# Anthropic's payload still calls the write count "cache creation"
cache_write_input_tokens=usage.get("cache_creation_input_tokens"),
)- Create a custom alert on cost per trace, scoped to your service, so the next jump fires. Cost is measured per trace, over a window from 5 minutes to 24 hours:
FILTERS Service = my-agent
RULES p95(Cost) > $2.00
WINDOW 1 hourSet the threshold just above your normal p95. If you also wrap a call that an active integration already records, it is counted twice, so see Integrations for which layer to keep.
What you get
- The model, tokens and cost of every turn, so you can say whether a rise came from price per token, tokens per turn or the number of tasks.
- A sortable list of your most expensive turns, with the trace and session each belongs to.
- Cost per agent over time in Drift and side by side by version in Compare, which show whether the jump lines up with a release. Cost by model on Usage and cost shows a model switch at a glance.
- A cost alert that fires when p95 cost per trace crosses your threshold. Firings show how much of the window was priced, so you can tell a real rise from partial pricing.
- If you tag end users with
user.id, the Users page sorts by cost to find whether one customer drives the spend.
When you monitor the whole agent, Monitor AI agents in production shows how these views fit together.
When something else fits
- Rius cannot show what the Claude Code runtime did inside a turn. If totals grew but the model did not change, compare the prompts on the Input / Output tab and your task settings, since only turn totals are recorded.
- A total-spend or budget threshold for the whole workspace is not an alert metric. Watch it on Usage and cost, and use cost per trace for alerts.