AI and automation8 min read

LLM application development: architecture, API costs and evaluation, a practical guide

Getting a model to answer from your documents is easy. Getting it right, at a cost per query that holds up, is the actual work.

A stack of frosted glass sheets with small glowing fragments rising towards a crystal prism
Retrieval-augmented generation (RAG)
A technique that pairs a language model with search over a document collection, so each answer is grounded in passages retrieved at query time. The term comes from a 2020 research paper describing models that combine the model's built-in knowledge with an external, searchable memory.

What does LLM application development involve?

It involves everything around the model rather than the model itself: the instructions, the data it can see, the tools it can call, the interface, and the checks that tell you whether it works. Very few startups train their own models; almost all build on APIs from providers such as OpenAI, Anthropic, Google or Mistral, so the engineering effort goes into context, cost and quality.

Prompting, RAG or fine-tuning: which approach do you need?

Start with prompting, add RAG when the model needs knowledge it does not have, and consider fine-tuning only to change behaviour that prompts cannot fix. Our rule of thumb, summarised:

Three ways to adapt an LLM to your product (MPN Group comparison)
PromptingRAGFine-tuning
What it changesInstructions and examples sent with each requestThe facts the model can see at answer timeThe model's default behaviour, style or format
Good forClassification, extraction, drafting with clear rulesAnswering from manuals, contracts, help centres, product docsConsistent tone or output format at high volume
Keeps knowledge freshOnly what fits in the promptYes, update the index when documents changeNo, retraining needed
Main cost driverInput tokens per requestInput tokens (retrieved chunks) and indexingTraining runs and evaluation

There is a fourth option for small knowledge bases: put everything in the prompt. In its post on Contextual Retrieval, Anthropic suggests this for knowledge bases under 200,000 tokens, roughly 500 pages, using prompt caching to keep costs down.

How does a RAG pipeline work?

A RAG pipeline has a preparation stage, run once and refreshed when documents change, and a query stage, run on every question.

  1. Chunk documents into passages of a few hundred words, keeping headings and context.
  2. Embed each chunk, turning it into a vector of numbers that captures its meaning, and store it in an index.
  3. Retrieve at query time by embedding the question and finding the closest chunks, often combined with keyword search.
  4. Generate by sending the question and the retrieved chunks to the model, instructed to answer only from them and cite its sources.
  5. Log the answer, the sources used and the cost of the request.
Five small glass modules in a row, linked by a lilac thread, representing the stages of a RAG pipeline
The stages of a RAG pipeline: chunk, embed, retrieve, generate, log.

How much do LLM APIs cost?

LLM APIs bill per token, with one rate for input and a higher one for output. Below is a selection from the official pricing pages of OpenAI, Anthropic and Google. Prices change often, so use them to reason about orders of magnitude and check again before you commit.

API prices per million tokens, standard tier, in US dollars (official pages, checked 19 October 2026)
Provider and modelInputOutputNotes
OpenAI gpt-6-astra$10$50Cached input $1
OpenAI gpt-6.1-sol$2$10Cached input $0.10
OpenAI gpt-6-luna$0.10$0.50Cached input $0.01
Anthropic Claude Opus 5.5$4$20Cache reads $0.20
Anthropic Claude Sonnet 5.5$2$10Cache reads $0.10
Anthropic Claude Haiku 5.5$0.10$0.50Prompts up to 100,000 tokens; above that $0.50 and $2.50
Google Gemini 4 Argon$2 until 30 Nov 2026, then $4$10, then $20Not on the free tier
Google Gemini 3.8 Flash$0.75 until 31 Dec 2026, then $1.50$3.75, then $7.50Free tier exists, but content is used to improve Google's products
OpenAI text-embedding-3-small$0.02—Embedding model for indexing

50%

discount on OpenAI's Batch API compared with synchronous requests, with results returned within 24 hours; Anthropic and Google offer the same discount on batch jobsSource: OpenAI, Batch API documentation

How do you estimate the cost of an LLM feature?

Add two parts: indexing, paid once and again on each update, and cost per query, paid every time. Here is an example we built on hypothetical volumes using the prices above.

Worked example (MPN Group)

  1. Indexing

    10,000 pages of documentation. Using Anthropic's ratio of 200,000 tokens to about 500 pages, that is roughly 4 million tokens. At $0.02 per million with text-embedding-3-small: about $0.08. Indexing barely registers.

  2. One query

    1,500 tokens of instructions, a 100-token question and five retrieved chunks of 500 tokens: about 4,100 input tokens. An answer of about 400 output tokens.

  3. Cost per query

    On gpt-6.1-sol: 4,100 × $2 / 1M + 400 × $10 / 1M ≈ $0.012. On gpt-6-luna: ≈ $0.0006.

  4. Monthly cost

    At 10,000 queries a month: about $122 on gpt-6.1-sol, about $6 on gpt-6-luna. Add hosting, the vector store and monitoring on top.

The real driver is the trade-off between input tokens and quality: more chunks cost more and do not always produce a better answer, which makes retrieval quality a cost lever as well. If the feature is an agent making several model calls per request, multiply accordingly; our breakdown of AI agent development cost covers that case.

How do you cut LLM API costs?

Mostly by matching the model to each step and never paying full price twice for the same text. The main levers:

  • The smallest model that passes your evals. Within a single provider the price gap per token can reach a hundred times.
  • Prompt caching. Repeated content such as instructions and examples costs far less when read from cache: Anthropic bills cache reads at 10% of the input price by default, 5% on Opus 5.5 and Sonnet 5.5.
  • Batch for anything that can wait. Overnight summaries, classification, re-indexing: OpenAI's Batch API runs at half price with results within a day, and Anthropic and Google offer the same discount.
  • Fewer, better chunks. Precise retrieval lets you send less context per question.
  • Output limits. Shorter answers cost less and are often easier to read.

How do you evaluate an LLM application?

Evaluate the two halves separately: retrieval (did it find the right passages?) and generation (did it use them faithfully?). If retrieval fails, no model can rescue the answer; if retrieval works and the answer does not, the problem is in the instructions or the model. Anthropic's own tests show how much retrieval matters: combining contextual embeddings, keyword search and reranking cut top-20 retrieval failures by 67%, from 5.7% to 1.9%, without changing the model. Those are vendor-reported results on the vendor's own datasets.

OpenAI's evaluation guide notes that human judgement gives the highest-quality evals but is slow and expensive, while model-graded evals are cheaper and scale better, and that no strategy is perfect. Anthropic's documentation adds a practical bias: favour many automatically graded cases over a few graded by hand. A workable set-up looks like this:

  • a list of real user questions, each mapped to the documents that hold the answer;
  • for retrieval, the share of questions where the right passage appears among those retrieved;
  • for answers, correctness, faithfulness to sources and citations, graded by a second model and spot-checked by a person;
  • the whole suite rerun on every change to chunking, index, prompts or model.

Which mistakes push up cost and error rates?

  • Chunks that are too big or stripped of context. The model gets noise, or sentences cut off from their heading.
  • No eval set before launch. Without real questions you cannot tell whether a change helped.
  • Stale documents in the index. The answer matches the source, but the source is out of date.
  • Free tiers with customer data. Some let the provider use your content; see our guide to GDPR and LLM apps.
  • No cost dashboard. Track cost per query weekly, the way you track latency.

If the model also needs to act, opening tickets or updating a CRM, you are building an agent: start with what AI agents are and how to build an AI agent for business. Still choosing where AI fits? How startups can use AI helps you pick the first use case.

Frequently asked questions

What is LLM application development?

It is the work of building a product feature around a large language model: prompts, data access, tools, interface, cost control and evaluation. Most teams build on provider APIs rather than training their own models.

Which LLM is best for app development?

There is no single best model. Shortlist two or three, run them against your own eval set and keep the cheapest one that meets your quality bar. Design the app so you can switch providers, because prices and models change often.

RAG or fine-tuning?

For fresh, citable knowledge, RAG is usually the better fit. Fine-tuning, meaning additional training of the model, is more about changing style or output format, and it still needs to be evaluated against the same test set.

Do I need a dedicated vector database?

Not always. At modest volumes, a database you already run, such as PostgreSQL with the right extensions, can handle similarity search. A dedicated service makes sense as volume or latency requirements grow.

How do I stop the model making things up?

Instruct it to answer only from the retrieved passages and cite them, improve retrieval, and define a fallback when sources are insufficient. Then measure it: without an eval set you do not know how often it happens.

Sources

  1. Lewis et al., Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks (arXiv 2005.11401, 2020) (19 October 2026)
  2. Anthropic, Introducing Contextual Retrieval (19 settembre 2024) (20 October 2026)
  3. Anthropic, Pricing (documentazione ufficiale dei prezzi API) (19 October 2026)
  4. OpenAI, API Pricing (19 October 2026)
  5. Google, Gemini Developer API pricing (19 October 2026)
  6. OpenAI, Batch API (documentazione) (20 October 2026)
  7. OpenAI, Evaluation best practices (documentazione) (19 October 2026)
  8. Anthropic, Define success criteria and build evaluations (documentazione) (19 October 2026)

Figures and definitions checked on the dates shown.

Building a startup?

Let's talk