CourseLarge Language Models: The Complete Course · Module 2: Tokens, Context, and Cost · part 19 of 103
Part 19 · Module 2: Tokens, Context, and Cost

Lab: Count, budget and price every call

30 min read·13 Oct 2026
Module 2 · Lab · About 50 minutes · Needs: lessons 1 to 4 of this module, and the Module 1 lab (or the cells in Step 1)

What you are building

TWO NEW FILES AFTER MODULE 2 supportdesk/tokens.py count_tokens, count_messages room_left, check_budget supportdesk/pricing.py PRICES, cost_usd usage, reply_cost, per task tests/ 7 tests, no key 3 real calls cost per usable label imports Module 1: llm.py (ask, MODELS) and data.py (36 tickets)
Two new files (blue) hold every count and every price, checked by keyless tests (green) and measured on three model calls (amber).

It is Thursday 18 June 2026, week 3. Yesterday Joel set the cap: one cent of model fees per ticket, on average. This week's lessons counted tokens, fitted requests into a window and priced calls, all in notebook cells that each defined their own counter and their own prices. This lab puts them in two files every later module imports. supportdesk/tokens.py holds the one counter and the budget gate. supportdesk/pricing.py holds the one price table and turns a reply's reported usage into dollars. With them you estimate a week of triage for all 36 tickets before sending anything, then measure three real calls and report the cost per usable label against Joel's cap. Only three calls go to the hosted model.

The rest of this course is yours to keep

This course is bought on its own, once, and stays readable afterwards, including the parts added to it later.