Eight parts, nine pieces. One thing left: putting them together without the cost getting away from you. This part closes the series with the full architecture, the mechanism that saves the most money, and the monthly bill of three products that genuinely exist.
📚 Series "Build Your Own ChatGPT" — 9 parts
1. What's inside · 2. The brain · 3. The eyes (OCR) · 4. The memory (documents) · 5. Images · 6. Video · 7. Voice · 8. Tools and agents · 9. Putting it together ← you are here
The complete architecture
┌─────────────────┐
user request ─────▶│ ORCHESTRATOR │ (your code — not a model)
└────────┬────────┘
│ classifies intent and routes
┌────────────────────────┼─────────────────────────┐
│ │ │
┌────▼─────┐ ┌───────▼────────┐ ┌───────▼────────┐
│ RETRIEVAL│ │ BRAIN │ │ SPECIALISTS │
│ your docs│─chunks──▶│ per token │◀──────▶│ on demand │
│ (Qdrant) │ │ 5 models │ │ OCR · image │
└──────────┘ └───────┬────────┘ │ video · voice │
▲ │ └────────────────┘
│ ▼ start · run · stop
always on streamed answer
(small) ┌────────────────┐
│ TOOLS │
│ live data, │
│ APIs, agents │
└────────────────┘
The rule that organises the whole bill
The entire series reduces to one line: separate what must be running from what only needs to exist when called.
| Category | Pieces | Cost model | How to pay |
|---|---|---|---|
| Always on | Vector database, orchestrator, your app | Fixed monthly cost — keep this list short | Small machine, yours or rented |
| Per call | Brain, classification, moderation, rewriting | Proportional to usage, no floor | Per token |
| Bursty | OCR, indexing, image, video, voice | Proportional to work, zero when idle | GPU by the hour, only while the queue has work |
The most expensive structural mistake — and the most common — is putting the brain in the first row. It is the highest-frequency, least predictable piece: exactly the worst candidate for a machine running 24 hours a day.
⚠️ The "always on" column decides whether your product works financially
A small card running all month costs ~R$ 780. A mid-range one, ~R$ 2,030. Those figures appear on your statement even in a month with no users at all.
Hence the recommendation: keep only the vector database and your application in "always on" — both run fine on a modest machine, often one you already have. Everything else belongs in "per call" or "bursty".
The model router: where the money is made
In part 2 we saw the same product costing R$ 112 or R$ 4,973 a month depending on model choice. The router is what lets you sit near the first number while delivering quality close to the second.
The idea: the overwhelming majority of calls in a real product are simple work — classify, extract, rephrase, answer a direct question. Only a small slice needs hard reasoning.
SIMPLE = ("classify", "extract", "summarise", "translate",
"rewrite", "correct", "moderate", "title")
def choose_model(task: str, text: str, attempt: int = 0) -> str:
# 1) Mechanical task declared by your code: always the cheapest.
if task in SIMPLE:
return "gpub-fast"
# 2) Reprocessing: if the first answer failed validation, step up.
if attempt > 0:
return "gpub-base"
# 3) Conversation: a cheap heuristic on length and type of request.
hard = len(text) > 4000 or any(
w in text.lower() for w in ("why", "compare", "analyse", "code", "error")
)
return "gpub-base" if hard else "gpub-plus"
💡 Start cheap and escalate on failure
The pattern that beats any input heuristic: call the economy model, validate the answer with your own rule (is the JSON valid? are required fields present? does it cite a source?) and only reprocess on the larger model when validation fails.
You pay for the expensive model only in the cases where it was genuinely needed — and you discover, by measuring, that this slice is far smaller than fear suggested.
Three products, with the bill closed
Product A — Internal assistant for 40 people
Chat over the company document base, with PDF reading. 44,000 messages a month, 2,000 scanned pages a month.
| Piece | Volume | Runs on | Cost/month |
|---|---|---|---|
| Routed text (85% economy, 12% mid, 3% high) | 44,000 messages | Per token | R$ 174 |
| OCR + structuring | 2,000 pages | GPU 0.7 h + tokens | R$ 2 |
| Indexing new documents | weekly burst | GPU ~1 h | R$ 5 |
| Vector database + application | 24/7 | Modest machine | your infrastructure |
| Total AI cost | R$ 181/month |
For comparison: the same product using only the most capable model everywhere would cost R$ 4,980. The router accounts for 96% of the difference.
Product B — Customer support
5,000 conversations a month, 8 messages each, with retrieval over the help base and input moderation.
| Piece | Volume | Cost/month |
|---|---|---|
| Answers with sliding window and retrieved passages | 40,000 messages | R$ 131 |
| Input moderation | 40,000 calls | R$ 8 |
| Classifying and tagging conversations | 5,000 calls | R$ 3 |
| Total | R$ 142/month |
That is R$ 0.028 per conversation handled. And the detail worth more than the table: without the sliding window, resending the whole thread every time, the same operation would cost R$ 379 — nearly three times more, for identical answer quality.
Product C — Content studio
3,000 images, 20 videos of 30 seconds and 200 minutes of narration a month.
| Piece | Volume | Runs on | Cost/month |
|---|---|---|---|
| Prompt rewriting, scripts and captions | ~3,300 calls | Per token | R$ 1.20 |
| Image generation | 3,000 images | GPU 1.8 h | R$ 5 |
| Video generation | 120 clips of 5 s | Large GPU, 16 h | R$ 113 |
| Narration | 200 minutes | GPU 0.3 h | R$ 1 |
| Total | R$ 120/month |
August 2026 prices, single GPU, no scheduled interruption. Prices are in Brazilian reais (BRL), the billing currency. The catalogue moves — check the live one before committing to a number.
Notice the distribution: video is 94% of the bill with only 20 pieces a month. If that product grows, video is the piece that needs attention — not the rest.
The five mistakes that blow the budget
- The expensive model as the default. 20 to 45 times the cost for the same delivery. Always mistake number one.
- The whole history on every message. Triples the cost of long conversations and degrades answer quality on top.
- The whole document in context. Up to 95 times more expensive than retrieving the right passages (part 4).
- A GPU left on, waiting. R$ 780 to R$ 2,030 a month of idleness — it disappears on its own once the queue starts the machine.
- An agent with no ceiling. A stuck loop runs all night burning balance. Always set maximum steps and tokens.
Three honest things before you go live
- Measure from day one. Log tokens, model, latency and cost per call. Without it you cannot tell which feature is consuming what — and you will optimise the wrong thing.
- Keep a model plan B. Because the API follows the OpenAI standard, switching models is switching a string. Make it configuration, not something buried in code.
- Talk to us before launch if volume will be large. There is a per-account ceiling on concurrent calls, sized for normal usage. An application with hundreds of simultaneously active users needs that ceiling raised before going live — it is a five-minute conversation, and far better had in advance than discovered on launch day.
The whole path, in one table
| Week | What to build | Piece | Cost to start |
|---|---|---|---|
| 1 | A working chat with your prompt | Brain | cents per day |
| 2 | Your documents indexed and cited | Memory | a few reais of indexing |
| 3 | PDF and image reading in the flow | Eyes | cents per batch |
| 4 | Two or three read-only tools | Hands | cents |
| Later | Image, voice and video — when someone asks | Specialists | GPU by the hour, on demand |
Nine pieces, none of them closed, every one with a mature open equivalent. What was a multi-million project three years ago is now a matter of assembling the pieces in the right order and paying for each one with the cost model that suits it.
Start with the brain, today
Five open models behind an OpenAI-compatible API, billed per token, no subscription and no machine to administer. When a piece needs a card, it deploys in one click, runs and shuts down.
See the token API →Back to the start: part 1 — what is actually inside these platforms.
Keep reading: part 2: the brain · serverless vs dedicated GPU · deploying to production