GENERATIVE AI • LESSON 4

What Is a Token?

A token is a small piece of text that an LLM processes. Tokens are the basic pieces used to turn human language into something a language model can work with.

CORE IDEA

A token is a piece of text that an LLM processes.

A token is not always one complete word. Depending on the tokenizer, a token can be a whole word, part of a word, punctuation, or another small piece of text.

01

Think of a Token as a Small Piece of Text

When you write a sentence, you see normal words. An LLM does not process the sentence exactly the same way a human reads it.

The text first goes through a process called tokenization.

YOUR TEXT I love Generative AI.
TOKENIZATION Text is split into pieces
TOKENS I · love · Generative · AI · .

The example above is only a simplified illustration. The exact tokens depend on the tokenizer used by the model.

02

One Word Does Not Always Mean One Token

This is one of the most important things to understand as a beginner.

You should not think:

❌ One word = one token

Instead, think:

✓ A token = a piece of text

A common or short word may be represented as one token, while a longer or less common word may be split into multiple pieces.

WORD unbelievable
CONCEPTUAL TOKENIZATION un · believ · able

This is an educational example, not an exact tokenizer output. Different models and tokenizers can split text differently.

03

How Does Text Become Something the LLM Can Process?

The important idea is that human text must be converted into a representation the model can process mathematically.

01 Your Text "What is AI?"
02 Tokenization Text is split into tokens
03 Token IDs Tokens become numerical IDs
04 LLM Model processes the input

You do not need to learn the mathematics behind this yet. For now, remember the simple pipeline:

Text Tokens Model Output Tokens Text
04

Input Tokens vs Output Tokens

When you use an LLM API, you need to understand two sides of token usage.

INPUT TOKENS What you send

Your prompt, instructions, conversation, documents, or other input data.

LLM
OUTPUT TOKENS What the model generates

The answer or other generated content returned by the model.

INPUT Explain Magento 2 simply.
LLM
OUTPUT Magento 2 is an e-commerce platform...
05

Practical Example — Using an LLM API

Imagine you are building a small Python application that asks an LLM a question.

from openai import OpenAI

client = OpenAI()

question = "What is Magento 2?"

response = client.responses.create(
    model="YOUR_MODEL",
    input=question
)

print(response.output_text)

The important thing is not the SDK syntax yet. Focus on what happens to the data.

STEP 1 Your Question What is Magento 2?
STEP 2 Tokenization Text → Tokens
STEP 3 LLM Processes Input Input Tokens → Model
STEP 4 Generated Output Output Tokens → Text
06

Why Do Tokens Matter?

Tokens become especially important when you start building real AI applications.

1. API Cost

Many LLM APIs measure usage using tokens. If your application sends much more text, it may use many more tokens and therefore increase your API cost.

SMALL INPUT 100 tokens Short question
LARGE INPUT 10,000 tokens Long history + documents

2. Context Limits

Models have limits on how much information they can process in a single request. Your prompt, conversation, retrieved documents, and generated response all consume part of that available context.

3. Application Performance

Sending unnecessary text can make an application less efficient. A good GenAI application sends the model the information it actually needs.

07

Real-World Example — Customer Support AI

Imagine an e-commerce website with an AI customer support assistant.

A customer asks:

Where is my order?

A bad implementation might send the customer's entire history every time:

Customer profile
100 previous emails
50 previous chat messages
20 documents
Previous order history

That can create a huge input.

BETTER APPROACH Retrieve only the information relevant to the customer's current question.

For example, if the customer asks about order status, the application can retrieve the current order details and send only the useful information to the LLM.

Customer "Where is my order?"
Backend Get order status
LLM Generate explanation
Customer "Your order is in transit..."

This idea becomes very important later when you learn about context management, RAG, and retrieval.

COMMON MISCONCEPTION

"One word always equals one token."

No. Tokenization depends on the tokenizer and the model. A word can be one token or multiple tokens. Punctuation can also be represented as tokens.

For development work, do not manually guess token counts when accuracy matters. Use the tokenizer or token-counting tools associated with the model you are working with.

REMEMBER THIS

Text goes into an LLM as tokens, not as ordinary human-readable words.

  • A token is a piece of text processed by an LLM.
  • One word does not always equal one token.
  • Input tokens are the information sent to the model.
  • Output tokens are generated by the model.
  • Tokens matter for cost, context limits, and application efficiency.
QUICK CHECK

Test Your Understanding

Which statement is correct?

A Every word always equals exactly one token.
B A token is a piece of text processed by an LLM.
C Only the model's answer contains tokens.
D Tokens are only used for programming code.
Answer: B

A token is a piece of text that the model processes. It can represent a whole word, part of a word, punctuation, or another piece of text depending on the tokenizer.

NEXT TOPIC

Context

Now that you understand what a token is, the next step is to understand exactly how text is split into tokens.