Building with AILesson 3 of 80

Module 1 · The call underneath everything

Tokens, language and the context budget

In this lesson

  • 10 min read
  • 5 reading sections
  • Knowledge check
  • Lesson 3 of 10 in this chapter

This chapter’s goalSend the same request to a hosted model and to a model running on your own machine, read every field of the response including token counts and stop reason, and predict within a factor of two what a proposed feature will cost per thousand users before you write it.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmNot availableNot available
Full audiobookNot availableNot available
Two strings under cl100k_baseEnglish13Hindi in Devanagari52tokens for the printed stringLocal plain-text counts with tiktoken 0.14.0 for the exact English and Hindi strings printed above.API message formatting and generated output are excluded. The ratio describes this example andencoding.
Local plain-text counts with tiktoken 0.14.0 for the exact English and Hindi strings printed above. API message formatting and generated output are excluded. The ratio describes this example and encoding.

Figure

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 6Free · no account needed
Lesson steps

Text becomes tokens

Before a text model processes a request, a tokenizer maps the text to token IDs. The divisions depend on its vocabulary, algorithm and preprocessing. A token may cover a word, part of a word, punctuation or whitespace. Capitalization and surrounding spaces can change the result. Different tokenizers use different methods. For example, tiktoken uses byte-pair encoding, while Hugging Face supports BPE, Unigram, WordPiece and other models. Tokenizer methods.

For a rough English estimate, one token is about four characters or three quarters of a word. That makes 500 words roughly 667 tokens. Actual counts vary, so measure the text that your application will send. English estimates and counting.

Measure the languages your users use

The same meaning can produce different counts across languages and encodings. This example counts two specific strings using the named cl100k_base encoding. Install tiktoken before running it. The encoding is an example for comparison. Select the tokenizer for your production model when estimating its inputs. tiktoken documentation.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Every lesson here is open. Your progress is recorded once you pass the Python, from Zero, for AI exam.

Stuck on something?Ask Sayali, your AI tutor

How to cite: Addaly (2026) ‘Tokens, language and the context budget’, in Building with AI. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/building-with-ai/tokens-and-the-context-window (Accessed: 29 November 2026).