All guides

LlamaIndex LLM Cost Tracking

Attribute LlamaIndex retrieval, indexing, embedding, and generation costs to apps, teams, and customer workflows.

8 min read Updated June 2026Connect your AI stack
On this page
  1. 01Point LlamaIndex at Cloptima
  2. 02Separate retrieval and generation costs
  3. 03Capture workflow context
  4. 04Review unit economics

01

Point LlamaIndex at Cloptima

Set the OpenAI-compatible api_base to Cloptima for both the LLM and the embedding model, so generation and retrieval both flow through governed, attributed access.

python
from llama_index.llms.openai import OpenAI

llm = OpenAI(
    model="gpt-5.4-mini",
    api_base="https://api.cloptima.ai/v1/ai",
    api_key="clop_vk_dPXO67p…",
    default_headers={"x-cloptima-app": "kb", "x-cloptima-feature": "rag"},
)

02

Separate retrieval and generation costs

RAG mixes embeddings, retrieval, reranking, and generation. Tag each step with a distinct x-cloptima-feature (for example embed vs generate) so the final cost picture is actually useful.

03

Capture workflow context

Attach index, collection, customer, workspace, session, and run metadata so you can see which knowledge workflows drive spend.

04

Review unit economics

Measure cost per answer, document, workspace, or customer segment to keep AI features aligned with margin.

Put This Guide Into Practice

Cloptima automates the strategies described in this guide.

No credit card required
5-minute setup
Free trial