Of the ten pieces in part 1, this is the only one invoked on every single interaction. Build just this and you have a product. Get its arithmetic wrong and none of the other nine will save your unit economics.

📚 Series "Build Your Own ChatGPT" — 9 parts

1. What's inside · 2. The brain ← you are here · 3. The eyes (OCR) · 4. The memory (documents) · 5. Images · 6. Video · 7. Voice · 8. Tools and agents · 9. Putting it together

The token: the unit you are buying

A language model reads neither letters nor words: it reads tokens, which are word fragments. "Computer" might be one token; an unusual proper noun might be five.

The working rule of thumb: 1 token ≈ 4 characters, or 1 word ≈ 1.3 tokens. One A4 page of prose is about 600 tokens. A 20-page contract, about 13,000.

🌐 Non-English text costs more

Models are trained predominantly on English, and the token vocabulary reflects that. The same text translated into Portuguese, Spanish or German typically costs 20% to 30% more tokens.

That is not a reason to write your prompts in English — understanding your domain matters more than the saving. But it matters when you estimate volume: take your English estimate and add a quarter.

Why the answer costs more than the question

Look at the table and notice that the two numbers are never the same:

ModelOpen modelContextInput (1M tokens)Output (1M tokens)
gpub-fastDeepSeek V4 Flash1,000,000R$ 0.49R$ 1.09
gpub-miniQwen 3.6 35B200,000R$ 0.59R$ 3.49
gpub-plusQwen 3.8 27B1,000,000R$ 0.69R$ 3.99
gpub-baseGLM 5.2250,000R$ 7.90R$ 17.90
gpub-maxKimi K31,000,000R$ 17.90R$ 84.90

Price per million tokens, in Brazilian reais (BRL), August 2026. Live table at gpubrazil.com/en/llm-api.html.

The gap is not commercial, it is physical. Input is read in one pass: the 10,000 tokens of your prompt enter the GPU together, in parallel, and the card does what it is best at.

Output is generated one token at a time. To write word 500 of the answer, the model must already have written the previous 499 and must make another full pass through all of its billions of parameters. Five hundred output tokens are five hundred sequential passes.

That is why output costs two to five times input at every model, at every provider on earth. And why the most profitable instruction you can put in your system prompt is "be concise".

The arithmetic of one conversation

An internal assistant; a typical question with retrieved document context:

ItemTokensWith gpub-fastWith gpub-plusWith gpub-max
System instruction400
Conversation history1,200
Retrieved passages2,500
User question80
Total input4,180R$ 0.00205R$ 0.00288R$ 0.0748
Generated answer450R$ 0.00049R$ 0.00180R$ 0.0382
Cost per messageR$ 0.0025R$ 0.0047R$ 0.113

At product scale — 40 people, 50 messages a day each, 22 working days, so 44,000 messages a month:

  • On the economy model: R$ 112 a month.
  • On the mid model: R$ 206 a month.
  • On the most capable model in the catalogue: R$ 4,973 a month.

Forty-four times the cost for the same product. This is where an architecture decision becomes a business decision — and the subject of part 9.

The trap that blows up budgets: history

This is the part most teams discover late. The model remembers nothing. On every message your application resends the entire conversation, because that is the only way the model can know what is being discussed.

Which means: on message 20 of a conversation, you are paying for message 1 for the twentieth time.

Message numberTokens sent in that messageCumulative tokens paid
1st500500
5th2,5007,500
10th5,00027,500
20th10,000105,000
40th20,000410,000

Notice the shape: doubling the length of a conversation quadruples what you have paid for it. A long support thread of 40 exchanges costs 410,000 input tokens — the equivalent of more than fifty short conversations.

✅ The three defences

Sliding window. Send the last 8 to 10 messages, not the last 40. In most products nobody notices the difference.

Rolling summary. When the thread passes N messages, ask the cheapest model for a 200-token summary of what came before and replace the old history with it. It costs a hundredth of what it saves.

Trim retrieved context. If you attach document passages to every question (part 4), send 3 well-chosen passages, not 15 for safety. It is the single biggest source of input bloat.

Context window: what actually fits

Context is the token ceiling of one call — input plus output. The catalogue models range from 200,000 to 1,000,000 tokens, which on paper is a great deal:

  • 200,000 tokens ≈ 300 pages ≈ a whole technical book.
  • 1,000,000 tokens ≈ 1,500 pages ≈ a medium-sized codebase.

Two honest caveats. First, fitting is not understanding: every model loses precision in the middle of very long contexts, and a fact buried on page 400 is retrieved less reliably than one on page 3. Second, a large context is expensive by definition, because context is input and input is billed. Stuffing 800,000 tokens into a simple question means paying R$ 14 for something good retrieval would answer for fractions of a cent.

A wide context is a safety net, not a strategy. The strategy is part 4.

Choosing between the five

If your task is...UseWhy
Classifying, extracting fields, tagging, moderatinggpub-fastShort, objective output; the cheapest model is just as accurate and you process high volume for almost nothing
Conversation, support, summarising, draftinggpub-plusThe best balance in the table — the default choice for most products
High volume of objective tasks with medium outputgpub-miniFast, cheap and sufficient when the answer is not long
Dense analysis, non-trivial code, complex documentsgpub-baseA genuine step up in quality without going to the top of the table
Long reasoning, whole codebases, the hard casegpub-maxThe most capable in the catalogue — use it as the exception, never as the default

⚠️ Do not leave the most expensive model as the default

This is cost mistake number one, and it is silent: everything works, nobody complains, and the bill arrives forty times larger at the end of the month.

Do the opposite: start with the cheapest and step up only where quality falls short. In practice, 80% to 90% of the calls in a real product are simple tasks the economy model handles. Part 9 shows how to route that automatically.

In practice: the code

The API is OpenAI-compatible, so any library, framework or tool you already use works by changing two lines — the base URL and the key.

curl https://gpubrasil.com.br/v1/chat/completions \
  -H "Authorization: Bearer gpub_live_yourkeyhere" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpub-plus",
    "messages": [
      {"role": "system", "content": "You are an internal company assistant. Be direct and brief."},
      {"role": "user", "content": "Summarise the refund policy in 3 bullets."}
    ],
    "max_tokens": 500
  }'

In Python, using the official OpenAI library pointed here:

from openai import OpenAI

client = OpenAI(
    base_url="https://gpubrasil.com.br/v1",
    api_key="gpub_live_yourkeyhere",
)

stream = client.chat.completions.create(
    model="gpub-plus",
    messages=[
        {"role": "system", "content": "Be direct and brief."},
        {"role": "user", "content": "Explain what a token is, for a non-technical reader."},
    ],
    max_tokens=400,
    stream=True,          # the answer arrives word by word
)

for chunk in stream:
    piece = chunk.choices[0].delta.content
    if piece:
        print(piece, end="", flush=True)

About stream=True

Not decoration: it is the difference between a product that feels fast and one that feels frozen. Without streaming, the user stares at a still screen for six seconds until the whole answer lands. With it, the first words appear in under a second and the perception of speed changes completely — even though the total time is identical.

It costs the same. Always turn it on.

Two defences worth having on day one

  • Always set max_tokens. It is your handbrake: without it, one badly phrased prompt produces a 4,000-token answer and you pay for it.
  • Never put the key in the browser. The call goes out from your server. A key in public-page JavaScript is a published key — and whoever finds it spends your balance.

So when is a dedicated GPU worth it?

It genuinely is — later than most people assume. The break-even depends on the size of model you want to serve, and there are two very different scenarios:

ScenarioMachine costComparable toBecomes cheaper above
Small model on a 24 GB card, running 24/7R$ 2.78/h ≈ R$ 2,030/monththe economy model in the table~800k messages/month
Large frontier-class model, multi-GPU, 24/7from ~R$ 15,700/monththe mid model in the table~5M messages/month

In other words: until your product passes the million-messages-a-month mark, a dedicated card is an expensive machine sitting idle overnight.

Beyond volume, a dedicated GPU still wins in two situations:

  1. A model fine-tuned to your domain — if you trained your own adapter, it only runs on your machine.
  2. An isolation requirement — when policy demands the processing happen on a dedicated instance of your own, with you controlling the model, the weights and the logs.

Outside those cases, starting per token and migrating later is almost always right — and it does not lock you in: because the API follows the OpenAI standard, moving to your own server later means changing the base URL.

Test before writing any code

The playground in the dashboard runs all five models side by side and shows the real cost of every answer. API keys are enabled after the first deposit.

See the token API →

Next: the eyes — making your assistant read images and PDFs.

Keep reading: part 4: the memory · token economics vs self-hosting · open model comparison 2026