Qaynaq LABS · TOOLS

LLM COST · MISTRAL · RETRIEVAL-AUGMENTED GENERATION (RAG)

Codestral: $3.20/mo

At 10.00M input tokens ($2.00) and 2.00M output tokens ($1.20) per month, on retrieval-augmented generation (rag) workload.

Pricing: $0.2/M input · $0.6/M output · 32,000 token context

How this workload behaves

In retrieval-augmented generation (RAG) workloads, the dominant cost driver is typically the input tokens consumed by the model to process retrieved context. These systems often fetch large chunks of documents, codebases, or knowledge bases, which are then passed as context to the LLM for reasoning or generation. Output tokens, while still significant, are usually smaller in volume compared to the input, especially when the model is used for summarization, extraction, or structured responses rather than free-form generation. Codestral’s pricing structure—$0.20 per million input tokens and $0.60 per million output tokens—reflects this asymmetry, making it well-suited for RAG pipelines where input-heavy processing is the norm.

Compare against 5 alternatives

ModelVendorMonthly costvs primaryΔ
Mistral LargeMistral$32.0010.00×+$28.80
Mistral SmallMistral$3.201.00×+$0.0000
GPT-4o miniOpenAI$2.700.84×$0.50
Claude Haiku 4.5Anthropic$20.006.25×+$16.80
Gemini 1.5 FlashGoogle$1.350.42×$1.85

Recommendation

For this RAG workload, **Gemini 1.5 Flash** is the clear cost leader, delivering the lowest total cost at $1.35/month while maintaining strong performance for retrieval-heavy tasks. It outperforms Codestral by $1.85/month (42% cheaper) and offers a 32,000-token context window, which is ideal for RAG applications. While GPT-4o mini is slightly cheaper at $2.70/month, the savings are marginal compared to Codestral, and its smaller context window (128k vs. 32k) may limit flexibility. Mistral Small matches Codestral’s cost but lacks the performance benefits of newer models. Stick with Codestral only if you require Mistral-specific features or have strict vendor constraints.

Cost-saving tactics for this workload

  • Enable prompt caching for repeated RAG queries—store retrieved context in a cache and reuse it across sessions to reduce input token costs.
  • Use a two-stage retrieval approach: first fetch a small set of relevant documents with a lightweight model (e.g., Mistral Small), then pass only the top results to Codestral or Gemini 1.5 Flash for reasoning.
  • Compress retrieved context by truncating or summarizing documents before passing them to the LLM, reducing input token volume without sacrificing critical information.
  • Batch API calls for RAG pipelines where multiple queries share the same context (e.g., processing a codebase or document set in bulk).
  • Monitor and optimize your retrieval strategy—fewer, higher-quality documents retrieved per query directly reduce input token costs.

About LLM API cost planning

LLM API costs scale linearly with token volume, but the right model for your workload depends on three axes: intelligence, speed, and price. Picking the cheapest model can mean paying for outputs that don't meet quality thresholds; picking the most expensive can mean burning budget on tasks a smaller model would have solved.

The Qaynaq Labs LLM Cost Calculator combines deterministic pricing math with workload-aware recommendations across 20+ models from Anthropic, OpenAI, Mistral, Google, Meta (via Groq), Cohere, DeepSeek, and xAI. Plug in your monthly token volume, pick your workload, and see exact monthly cost plus alternatives ranked by total.

Frequently asked

Why is input token cost so much higher than output in RAG?

RAG systems typically retrieve large chunks of text (e.g., entire documents or code snippets) to provide context for the LLM. This results in high input token volumes. Output tokens are usually smaller because the model is generating concise answers, summaries, or structured outputs rather than free-form text.

Can I use a smaller model for the retrieval step to save costs?

Yes. Use a lightweight model like Mistral Small for the initial retrieval phase to fetch relevant documents, then pass only the top results to a more capable model (e.g., Codestral or Gemini 1.5 Flash) for reasoning. This reduces input token costs while maintaining accuracy.

How does prompt caching help in RAG?

Prompt caching stores frequently used context (e.g., retrieved documents or code snippets) in the model’s cache, allowing subsequent queries to reuse the cached content without reprocessing it. This reduces input token costs for repeated or similar queries.

Is there a trade-off between context window size and cost in RAG?

Yes. Larger context windows (e.g., 128k or 200k tokens) allow you to process bigger documents or more context, but they may come with higher costs or slower performance. For most RAG use cases, a 32k–64k token window is sufficient and more cost-effective.

Should I always choose the cheapest model for RAG?

Not always. While cost is critical, model performance matters too. If the cheaper model (e.g., GPT-4o mini or Gemini 1.5 Flash) struggles with your specific RAG task (e.g., complex reasoning or niche domains), the savings may not justify the drop in quality. Test thoroughly before switching.