Skip to Content

My CrewAI agent suddenly costs more. Why?

Rius shows a CrewAI cost jump on the span for each model call, which carries the model, the token counts and the cost, so you can tell whether more calls, bigger prompts or a different model drove it. Sort the Spans tab by cost, open the most expensive trace and read its calls in order. A custom alert on cost per trace then flags the next jump as it happens.

How it works

The CrewAI integration records every model call a crew makes as a generation span, named ChatCompletion, with the model, input and output tokens, cost and time to first token. The calls are captured through the openai instrumentation, or through litellm when LiteLLM is installed.

Rius prices each call when it arrives, from the requested model and its token counts, and adds the calls up per trace and per agent. See Track LLM and agent cost for how pricing works. Costs are list-price estimates in US dollars, so expect your provider invoice to differ.

A higher cost per run comes down to one of three things, and each one is visible in the spans:

  • More model calls per run. The trace has more ChatCompletion spans than before, for example because the agent loops on a tool.
  • Bigger prompts per call. Input tokens grow from one call to the next as the conversation or history accumulates.
  • A different model. The requested model on the spans changed, and the new one has a higher price.

Crews and tasks produce no spans of their own, so the trace shows the calls and tools but not which task a call belongs to. If you need that, wrap per-task entrypoints with observe.

Set it up

  1. Make sure the calls and tools are traced. Install the integration and initialize Rius once. Details are on the CrewAI page.

    pip install "glassflow-rius[openai]" crewai
  2. Trace your tools as tools. A tool wrapped with the TOOL kind shows up as a tool span, so you can count and filter tool calls and the Tool Loop alert can see them. A bare observe makes a chain span instead, which neither the Tool kind filter nor Tool Loop sees.

    import rius from crewai.tools import tool from rius import SpanKind rius.init(api_key="ri_...", service_name="my-agent") def lookup(email: str) -> str: return "active" # replace with your own account lookup @tool("account_status") @rius.observe(kind=SpanKind.TOOL) def account_status(email: str) -> str: """Fetch a customer's account standing by email.""" return lookup(email)
  3. Find the expensive calls. Open the Spans tab on the Traces page, choose LLM in the All kinds menu, set the time range to cover the jump and click the Cost header to sort. The request model on each span shows whether the expensive calls come from a model you did not expect.

  4. Read one expensive trace. Open it and check the context growth strip above the tree, which plots input tokens per call in order. A rising line means the prompt grows with every step. Open Since previous llm call on a span’s Input / Output tab to see what each step added. The Map tab has a cost lens that shows where the money went in that run, and Compare runs sets it beside a cheaper run of the same agent.

  5. Count the calls. Compare the span count and the number of ChatCompletion spans in an expensive trace with a normal one. If a tool was retried, back-to-back failed attempts collapse into one row such as account_status · 3 attempts · recovered.

  6. Compare versions. Set RIUS_MAIN_AGENT_VERSION to your release, so the Agents page can compare cost per trace and tokens per trace between two versions. A comparison needs at least 20 traces per side to be free of the small-sample warning.

  7. Catch it next time. Create a custom alert on the Cost metric, which is measured per trace, scoped to your service:

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

    Pick a threshold above your normal p95. Cost alerts depend on pricing coverage, so check on the Usage and cost page that your models are priced.

What you get

  • A cause you can name: more calls, larger prompts or a different model, read from the spans instead of guessed.
  • The most expensive individual calls on one sortable list, and the most expensive runs on the trace list with cost per trace.
  • A before and after view per agent version, once you set a version.
  • An alert that fires when cost per trace crosses your threshold, so the next increase reaches you within the alert window instead of with the invoice.
  • One caution: a call with an unknown model or no token usage shows an empty cost, not zero. Streamed calls need usage enabled on the underlying client to carry token counts, so a missing figure means a gap in coverage, not a free call.

When something else fits

  • If you need to know which crew task spent the money, wrap per-task entrypoints with observe, because the integration records no spans for tasks.
  • If you want a total-spend or budget limit across the whole workspace, watch it on the Usage and cost page. It is not an alert metric today.
  • For the wider picture of watching runs, see Monitor AI agents in production, and for other frameworks see Integrations.

Still stuck? Get help

Last updated on