01Chapter 1: What a token isThis chapter assumes you can read basic Python and have called an LLM through a chat or completion API at least once. You should also be comfortable with simple arithmetic and unit conversion, such as converting "per million" prices to a per-call cost. You do not need to know how a model works inter6 min read
02Chapter 2: How text is split into tokensThis chapter assumes you can read basic Python, you know that an LLM API takes text in and returns text, and you know from the previous chapter that a token is the unit a model reads and bills. Here we look at where token boundaries come from and why they sometimes look strange.6 min read
03Chapter 3: Counting tokensThis chapter assumes you can read basic Python, have called an LLM through a chat or completion API, and know what a token is (a chunk of text the model reads as one unit). You also need to be comfortable with simple arithmetic. By the end you will be able to count tokens locally with a tokenizer li6 min read
04Chapter 4: The context windowThis chapter assumes you can read basic Python and have called a chat or completion API before. It also assumes you know a token is a chunk of text, usually a word or part of one, and that you can count tokens with a tokenizer library. Here you will learn what the context window is, what fills it, a7 min read
05Chapter 5: Output limits and the combined token budgetThis chapter assumes you can read basic Python, have called an LLM through a chat or completion API, and are comfortable with simple arithmetic. You should already know what a token is and what a context window is. Here we focus on a detail that trips up many developers: the output has its own limit7 min read
06Chapter 6: Why long conversations get expensiveThis chapter assumes you can read basic Python and have called a chat API before. You should know what a token is, how a context window limits a request, and how input and output tokens are priced. The goal here is to predict how the bill grows as a conversation gets longer, and to see why that grow7 min read
07Chapter 7: How providers price tokensThis chapter covers how providers turn token counts into a bill. It assumes you can read basic Python, have called an LLM through a chat or completion API, and are comfortable with simple arithmetic and unit conversion. It builds on the earlier chapters on what a token is and on the context window.7 min read
08Chapter 8: Reading usage from API responsesThis chapter assumes you can read Python, have called a chat or completion API before, and know the earlier chapters' terms: input tokens, output tokens, context window, and per-million-token pricing. Here you will learn where the real token counts appear in an API response, how the field names diff6 min read
09Chapter 9: Estimating what a call costsThis chapter assumes you can read basic Python, have called an LLM through a chat or completion API, and are comfortable with unit conversion. It builds on the earlier chapters about tokens, the context window, output limits, per-token pricing, and usage data. Here you combine them into a cost estim6 min read
10Chapter 10: Reasoning tokens and hidden outputThis chapter assumes you have read the earlier chapters on output limits and per-token pricing. You should know that input and output tokens are billed at different rates. You should also know that a context window has to hold the prompt and the reply together. The code uses basic Python.7 min read
11Chapter 11: Keeping context within budgetEarlier chapters showed that every call must fit inside the context window and that the whole history is resent on each turn. This chapter covers what to do when a conversation or document set grows past what you want to send. It assumes you can read basic Python, have called a chat API, and know th6 min read
12Chapter 12: Prompt cachingThis chapter assumes you have read the earlier chapters on per-token pricing, usage data, and conversation history growth. You should also be comfortable reading short Python functions. Prompt caching is the main way to reduce the cost of resending the same tokens on every call.7 min read
13Chapter 13: Practical ways to lower costThis chapter assumes you can read basic Python, have called a chat or completion API, and know the earlier chapters' ideas. Those ideas are tokens, the context window, per-million-token pricing, usage data, and history growth. Here you turn that knowledge into changes that shrink a bill.7 min read