Skip to Content

My LlamaIndex agent suddenly costs more. Why?

Rius shows a cost jump in your LlamaIndex agent on the spans for each model call, with model, token counts and cost, so you can see which step grew. Start with the most expensive LLM spans and the input tokens per call in the slow or costly trace. Then add a cost alert so the next jump reaches you as it happens.

How it works

With the LlamaIndex integration on, each query becomes a nested trace of typed spans. Retrieval steps are RETRIEVER spans, embedding calls are EMBEDDING spans, and synthesis model calls are LLM spans carrying model, token usage and messages. Rius computes the cost of each LLM call from the requested model and its token counts. You never send a cost.

That gives you a short list of reasons a bill rises, and each one looks different in the spans:

  • Bigger prompts. More retrieved text or a longer history raises input tokens on the LLM spans. The retriever span’s output shows what the model was given.
  • More calls per query. The agent loops or retries, so a trace has more LLM spans than before.
  • A different model. The model on the LLM spans changed to one with a higher price.
  • Calls counted twice. If the openai extra is installed alongside LlamaIndex, a chat call is traced as a second LLM span under the LlamaIndex span. From glassflow-rius 1.1.1 the call is counted once in tokens and cost. On earlier versions, or on instrumentation versions outside the supported range, it is counted twice. Calls from MultiModalLLM models, embedding models and retrievers are not nested, so their OpenAI span starts a trace of its own.

Costs are list-price estimates in US dollars. Cost is fixed on the span when it is written, so a later price change does not rewrite past calls. A call with an unknown model or no token usage has an empty cost, not zero, so it never looks free.

Set it up

  1. Make sure the integration is on. Install it and call init() before you build indexes and query engines. The LlamaIndex integration page has the full setup, and Integrations lists the other supported libraries.

    pip install "glassflow-rius[llama-index]" llama-index
    import rius rius.init(api_key="ri_...", service_name="my-agent")
  2. Open the Spans tab on the Traces page. Set the time range to cover the jump, pick LLM in the All kinds menu, and click the Cost header to sort. If the top spans share one model or one step name, that is where the money goes. Filter by model to check whether the model changed.

  3. Open one expensive trace. For a trace with several LLM calls, the context growth strip above the tree plots input tokens per call in order. A climbing bar means the prompt or history is growing. The Map tab’s cost lens shows which span in the run cost the most.

  4. Select an LLM span and open Since previous llm call on the Input / Output tab. It marks each message as added, removed or changed, so you see what each step added to the prompt. Check the retriever span before it to see how much text it returned.

  5. Compare against a normal run. Compare runs on the trace page sets the open trace beside another run of the same agent and shows which steps were added or dropped and where the cost moved. On the Agents page, Compare puts two versions side by side on cost per trace and tokens per trace, and Drift charts cost per trace over time.

  6. If cost per trace is high but the spans look normal, check for double counting. See whether each model call appears once or as two nested LLM spans, and confirm your glassflow-rius version is 1.1.1 or later.

  7. Add a cost alert. In custom alerts, cost is measured per trace with avg, min, max, p50, p95 and p99 over a rolling window of 5 minutes to 24 hours:

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

    Use your own service name and a threshold above your usual p95. This catches a prompt that grew or an agent stuck retrying. Add a channel (webhook, email or Slack) so the alert reaches you.

What you get

  • The step, model or prompt that drives the extra cost, found from per-call spans rather than a single total.
  • A clear split between more calls, larger prompts, a model change and double counting.
  • A side-by-side view of a costly run and a normal one, and cost per trace over time for the agent.
  • A p95 cost alert that fires on the next jump. Firings show the share of the window that was priced, so you can tell a high reading from a partly priced one.

For the full picture of how Rius prices calls and where cost appears, see Track LLM and agent cost. For the wider routine of watching agents in production, see Monitor AI agents in production.

When something else fits

  • The integration is Python only. For LlamaIndex.TS, the OpenAI integration traces provider calls and manual generations cover the pipeline around them.
  • A whole-workspace spend or budget threshold is not an alert metric. Watch total spend on the Usage and cost page instead.
  • Rius cost is a list-price estimate, so expect your provider invoice to differ.

Still stuck? Get help

Last updated on