RAG Cost Calculator
Retrieval-augmented generation multiplies your input tokens: every request re-sends the system prompt plus thousands of tokens of retrieved context. This calculator prices that pipeline per month — broken down by component, so you can see exactly where the money goes before the first invoice does.
RAG cost calculator
List prices for standard API calls — batch (−50%) and prompt-caching discounts can cut this further. † Anthropic's newest models include the ~30% tokenizer correction.
The RAG cost formula
monthly input tokens = requests/month × (system prompt + retrieved context + user prompt)monthly output tokens = requests/month × average output tokensmonthly cost = (input tokens × input price + output tokens × output price) ÷ 1,000,000
Worked example. 10,000 requests a month, each carrying a 300-token system prompt, 2,500 tokens of retrieved context and a 200-token user question, answered in 600 tokens. Input: 10,000 × 3,000 = 30M tokens; output: 10,000 × 600 = 6M tokens. On GPT-5.4 Mini that is 30 × $0.75 + 6 × $4.50 = $22.50 + $27.00 = $49.50 a month — and 83% of the input bill is retrieved context.
Where the money goes in a RAG pipeline
Two lines dominate. The first is retrieved context: those chunks are re-sent on every request, so at five 500-token chunks per query the worked example burns 25M of its 30M monthly input tokens on retrieval alone. The second is output: at $4.50 versus $0.75 per million, the 6M output tokens cost more ($27.00) than all 30M input tokens ($22.50) despite being a sixth of the volume. Everything else — embedding the query, the vector database lookup — is real infrastructure but rarely more than a few percent of the bill.
To compare providers on your RAG traffic, feed the totals into the LLM Token Cost Calculator: the example works out to 36M total tokens a month at a 5:1 input:output ratio, and the calculator prices that against every model — including the self-hosting comparison this page doesn't make.
Six ways to cut RAG costs
- Retrieve fewer, smaller chunks. Top-k and chunk size multiply: dropping from five 500-token chunks to four 400-token chunks cuts retrieved context from 2,500 to 1,600 tokens — a 36% reduction on the dominant input line.
- Rerank before you stuff. Fetch 20 candidates with cheap vector search, rerank, and send only the best 3–4 to the LLM. A reranking pass costs far less than the context tokens it saves.
- Cache the static prefix. The system prompt and tool definitions are identical on every request and cache at ~90% off; per-query retrieved chunks usually differ per request and don't. The prompt caching calculator puts a number on it.
- Route by difficulty. Grounded factual answers rarely need a frontier model. The worked example costs $49.50 on GPT-5.4 Mini and about $330 on GPT-5.6 Sol — route only the hard queries up.
- Cap output length. Trimming answers from 600 to 300 tokens saves $13.50 a month in the example — 27% of the total bill — and grounded answers usually read better shorter anyway.
- Measure real tokens per request. Conversation history, retries and prompt growth quietly inflate averages. Log actual input/output counts and reconcile monthly — the usage estimation guide shows what to watch.
Frequently asked questions
Related tools and guides
- LLM Token Cost Calculator — price your total volume against every model and self-hosting
- OpenAI API cost calculator — GPT-5.6 and GPT-5.4 presets for the same math
- Claude API cost calculator — Anthropic pricing with the tokenizer correction
- Prompt Caching Cost Savings Calculator — what caching the system prompt is worth
- How to estimate your monthly LLM token usage — get the requests-per-month number right first