Back to GuidesAgents
LlamaIndex LLM Cost Tracking
8 min readUpdated June 2026
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-4o-mini",
api_base="https://api.cloptima.ai/v1/ai",
api_key="clop_vk_dPXO67p…",
default_headers={"x-cloptima-app": "kb", "x-cloptima-feature": "rag"},
)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.
Capture workflow context
Attach index, collection, customer, workspace, session, and run metadata so you can see which knowledge workflows drive spend.
Review unit economics
Measure cost per answer, document, workspace, or customer segment to keep AI features aligned with margin.