MODULE 1  ·  How LLMs Work

Tokens:
What AI Actually Sees

When you type "Build me an app" into ChatGPT, you think the AI is reading 5 words. It's not. AI doesn't even have the concept of words — it reads something else entirely.

📅 Mar 2026
10 min read
🎯 Episode 1 of 98
Tokens BPE Tokenization AI Basics
In this episode
Core Concept
Tokens control everything
🧠 How smart your AI is  ·  📦 How much it can remember  ·  💰 How big your bill is

This is the most fundamental concept in AI engineering. Without understanding tokens, nothing else makes sense.

What Are Tokens?

Let's look at it directly. OpenAI has a tokenizer tool — whatever text you type in, it shows you exactly how AI breaks it down.

Live Example — "Hello, how are you?"
"Hello, how are you?"
Hello , how are you ?
5 words → 6 tokens. Simple so far.

Try I am building an application — depending on the model, "application" might be 1 or 2 tokens. "Artificial Intelligence" — 2 tokens. Easy.

Token #Text PieceType
1HelloWord
2,Punctuation
3howWord
4areWord
5youWord
6?Punctuation

Here's Where It Gets Interesting

Type the same sentence in Hindi: मुझे एक ऐप बनाना है

Same meaning. But count the tokens — almost double or triple compared to English. Bengali? Even more. Japanese? Almost every character becomes its own token.

Why non-English costs more

The tokenizer was trained on English text. English words are in its vocabulary. Hindi, Bengali, Japanese — the tokenizer has to break these down character by character. That's why non-English languages use significantly more tokens for the same meaning.

🇬🇧 English
"Build me a finance dashboard with React"
~8
tokens
$0.000020
cost
🇮🇳 Hindi
"React mein ek finance dashboard bana do"
~12
tokens
$0.000030
cost (+50%)

Same request. Hindi uses more tokens = more cost. A single chat? 500–1,000 tokens — cheap. But a coding agent making 100 API calls per session, each with 5,000–10,000 tokens? That's $600–1,500 per month. Understanding tokens = understanding your bill.

💡

Prices shown are GPT-4o input rates as of March 2026. Always check your provider's current pricing — rates change frequently.

How Was the Tokenizer Built? (BPE)

The algorithm behind tokenization is called BPE — Byte Pair Encoding. Sounds complex, but the concept is simple.

1
Start with individual characters

Every letter is one token. h-e-l-l-o = 5 tokens.

2
Find the most common pair

Which 2 characters appear together most? t + h → "the", "that", "this". Merge th into a single token.

3
Repeat & merge

th + e appear together a lot? Merge them. Now the is one token.

4
Keep going until vocabulary is full

ing → one token · tion → one token · Hello → one token

This ran on billions of English texts. That's why common English words = 1 token. But बनाना? Broken down character by character.

📊

GPT-4o vocabulary: ~200,000 tokens — 200,000 common subwords learned from training data. Mostly English. This is why English is inherently cheaper and more efficient to process.

Try It Yourself: Python Token Counter

Here's a simple script to count tokens and estimate API costs:

token_counter.py
python
# Install first: pip install tiktoken
import tiktoken

enc = tiktoken.encoding_for_model("gpt-4o")
text = input("Enter text: ")
tokens = enc.encode(text)

print(f"Text:      {text}")
print(f"Tokens:    {len(tokens)}")
print(f"Token IDs: {tokens}")

# Cost calculator (GPT-4o prices as of March 2026)
input_cost = (len(tokens) / 1_000_000) * 2.50
print(f"API cost (input): ${input_cost:.6f}")

Context Window: The Real Limit

When a company says "our model supports 128K tokens" — it means the model can hold a maximum of 128,000 tokens in one conversation.

Think of the context window as a room. 128K tokens = the size of the room. Everything — instructions, conversation history, AI response — must fit inside.

Input vs. output limits

Newer models (GPT-4o, Claude 3.5+) have separate input and output limits — for example, 128K input but only 4K–8K output. Always check both numbers.

Language1,000 tokens ≈128K context ≈Effective value
🇬🇧 English~750 words~384 pages (a full book)Full price
🇮🇳 Hindi~250–300 words~100–130 pages3× more expensive
💻 Code~200–400 lines~50,000 lines2× more expensive
⚠️

Nobody tells you this: Same model, same price — but Hindi users are effectively paying 3× more for less context. If you give AI a long Hindi document, the context fills fast. The model "forgets" earlier parts — not because it's dumb, but because the room is full.

This becomes critical in RAG (Retrieval Augmented Generation) — where chunking strategy depends entirely on this token math. Wrong chunk size = wrong results. We'll cover that in Module 4.

4 Practical Tips to Optimize Token Usage

Tip 01
Instructions in English, output in Hindi
Give AI its system instructions in English but ask for the response in Hindi. You save on input tokens since English is more efficient.
Tip 02
Use prompt caching
Both Anthropic and OpenAI offer prompt caching. Repeated identical prompts get a 90% discount on cached tokens — huge for production apps.
Tip 03
Check token count before sending
Use the Python script above, or paste your text on the tiktoken website. Know how many tokens you're sending before you hit enter.
Tip 04
Local models = free tokens
Running Ollama or llama.cpp locally? Tokens are free — no bill. Context window limits still apply, but at least you're not paying for it.
🚀

Next: Episode 2 — Transformers. In 2017, a paper called "Attention Is All You Need" changed the world. Next, we'll understand how. This is part of a 98-episode series covering AI engineering from tokens to production deployment.