LlamaIndex cost tracking

Price every LLM call LlamaIndex makes, from query engines to agents, and split the cost by customer and feature with one event handler.

By Keyveve, Inc. · Updated 2026-10-23

LlamaIndex reports each finished LLM call to its instrumentation dispatcher. Veqen's event handler listens there, so every call is priced whichever LLM class made it, with no change to your indexes, query engines or agents.

Install

pip install "veqen[llamaindex]"

Record every call

import veqen
from llama_index.core.instrumentation import get_dispatcher
from veqen.integrations.llamaindex import VeqenEventHandler

veqen.init()  # reads VEQEN_API_KEY, an ingest key
get_dispatcher().add_event_handler(VeqenEventHandler(tags={"feature": "docs-search"}))

with veqen.tags(customer=org.id):
    answer = query_engine.query(question)

Register the handler once at startup, on the root dispatcher. Tags set with veqen.tags(...) around a query apply to every LLM call inside it.

What it reads

The usage in the provider's own response, which LlamaIndex keeps on each chat and completion response: OpenAI and OpenAI-compatible hosts, Anthropic, and Google GenAI, with cached input kept apart from fresh input. For an OpenAI-compatible host, name it so the call is priced and billed as that host's:

VeqenEventHandler(provider="together", tags={"feature": "rag"})

Responses that carry no usage, such as a stream with usage reporting off, are skipped rather than estimated. Embedding calls don't report token counts to LlamaIndex's events, so record those with veqen.record() or wrap the embedding client.

Next

  • Tags: customer, feature, user, project, environment and run.
  • Custom prices: models you host yourself behind LlamaIndex.

Veqen records what every AI request cost and who it was for, checks it against your provider bills and prepares the entries for your accounting system. Start free or read the quickstart.