Tokens and the context window: how they're counted and what happens on overflow
Essence
A token is the unit in which a model reads and writes text, and in which the provider counts money and limits. The context window is the maximum number of tokens the model takes into account in a single request. It includes everything: the system prompt, the entire conversation history, attached files and images, tool descriptions and the model's own answer.
The rest of this answer, with code and interview follow-ups, is in the DevPrep app.
Read the full answer in DevPrep