Skip to Content

My Pydantic AI agent suddenly costs more. Why?

Rius prices each model request your Pydantic AI agent makes, so you can see whether a different model, a longer prompt or more calls drove the rise. Open the expensive traces, then look at the chat span for each model request: its model, tokens and cost point to the cause. A custom cost alert then flags the next spike as it happens.

How it works

Pydantic AI emits its own OpenTelemetry spans, and Rius reads them directly. Each agent run is a root span named invoke_agent <agent name>. Each model request is a span named chat <model> with its tokens and cost. Each tool call is a span named execute_tool <tool name>. Rius computes the cost from the requested model and the token counts, so you never send a price. For the full setup, see the Pydantic AI integration.

A cost rise has only a few possible causes, and each one shows up in a different place:

  • A pricier model. The chat spans carry a different model name, or a larger share of calls goes to an expensive one.
  • A bigger prompt. Input tokens per chat span grow, for example because the conversation history keeps growing or a system prompt got longer.
  • More model requests per run. A run has more chat spans than before, often because the agent loops through tool calls or retries.
  • More runs. The cost per trace is flat, but there are more traces.

Costs are list-price estimates in US dollars from LiteLLM’s public model-price catalog, so they track relative change well but will not match your invoice. A call with an unknown model or no token usage has an empty cost, not zero, so a model that is not priced never looks free. How pricing works is covered in Track LLM and agent cost.

Set it up

  1. Check that the agent is traced the way the integration expects. Call rius.init() and then switch Pydantic AI’s instrumentation on:

    import rius from pydantic_ai import Agent rius.init(api_key="ri_...", service_name="my-agent") Agent.instrument_all(True)
  2. Open Traces and set the time range to cover the jump, then filter to your agent. The list shows cost, tokens and span count for every trace, and the strip above it sums cost for the filtered set. Read a window before the rise and one after, and note whether cost per trace changed or only the trace count did.

  3. Switch to the Spans tab and pick LLM in the All kinds menu. Click the Cost header to sort. The model on the most expensive calls tells you whether a model change is the cause. Add a model filter to isolate one model. Exploring traces covers the filters and sorting.

  4. Open one expensive trace and check these in order:

    • The Context growth strip plots input tokens for each model call in order. A climbing bar pattern means the prompt grows during the run.
    • On a chat span, Since previous llm call in the Input / Output tab shows what each step added to the prompt, so a long tool result or a rewritten system prompt stands out.
    • A retry chain appears as one row, such as fetch_article · 3 attempts · recovered, so repeated execute_tool calls are easy to spot.
    • The Map tab has a cost lens that shows where the money went in that run.
    • Compare runs sets the trace against another run of the same agent and shows which steps changed or were added.
  5. Add a cost alert so the next spike reaches you. In a custom alert, cost is measured per trace over a rolling window of 5 minutes to 24 hours, and you can filter by service, agent or model:

    FILTERS Service = my-agent RULES p95(Cost) > $2.00 WINDOW 1 hour

    Choose a threshold that sits above your normal runs. The alert catches runs that got expensive, such as a prompt that grew or an agent stuck retrying.

What you get

  • A named cause for the rise: the model, the token counts per call, or the number of calls per run, each readable on the spans of your Pydantic AI runs.
  • Cost on every chat span, so you can sort individual model requests by cost and find the expensive ones directly.
  • A view of the run’s shape. The invoke_agent root, chat generations and execute_tool spans show how many requests one run made and which tool calls led to them.
  • A before and after comparison. On the Agents page you can compare two versions of the agent on cost per trace and tokens per trace, and the Drift charts show cost per trace over time. Usage and cost shows cost by model for the workspace.
  • An alert that fires when per-trace cost crosses your threshold. Firings show the share of the window that was priced, so you can tell a real high reading from a partly priced one.

For the broader routine of watching an agent after release, see Monitor AI agents in production. The integrations overview lists how the other frameworks are covered.

When something else fits

  • If you need the exact amount you were billed, use your provider’s billing page. Rius applies standard list prices and does not include batch or long-context pricing or negotiated discounts.
  • A total-spend or budget threshold for the whole workspace is not an alert metric today. Watch total spend on the Usage and cost page, and use the per-trace alert for runs that got expensive.

Still stuck? Get help

Last updated on