Tokens and costing

Inspect a recorded model call and separate reusable context from the information that changes on every tick.

  • Distinguish input, output, cached, and total tokens where the provider exposes them.
  • Identify context that grows each tick and decide what belongs in persistent incident state instead.
  • Record model IDs and provider-reported runtime tokens; the course accepts the group’s report on the honor system.
  • Inspect the recorded stable prefix and per-tick tail supplied by the instructor to see where prompt caching can apply.

Seeing token boundaries

Ordinary text splits into surprising pieces: subwords, leading spaces, an emoji, and punctuation. Try your own text at the tokenizer playground.

"The quick brown fox jumps over the lazy dog"it's standard text, but tokenizers see much more! 🦊 #NLP_101

Token hygiene in Claude Code

A bloated context costs money on every turn and makes the model worse. Three commands show what fills the window, trim it, and track your limits (costs docs):

  • /context shows what your session is carrying. Run it after a long working block and see how much is still earning its place. The Padlet is full of your /context screenshots from the skills session - open it and compare: what fills a window varies wildly between two people doing the same task.
  • /compact summarizes the conversation so far. Running it yourself gives you an exact point where you can afford the model losing detail, instead of letting it happen mid-task.
  • /usage shows how close you are to your plan limits. For a per-session and per-day breakdown from your local logs, run npx ccusage.

The # shortcut is the counterpart for keeping context lean across sessions: start a message with # and Claude offers to save the learning to memory, so bulky notes live in a file instead of being retyped into every session (memory docs).

Usage vs Context Limits

You will hit two different ceilings; do not confuse them:

  • Context window caps one request, denominated in tokens: everything the model reads plus writes in a single call. It is the LLM’s short-term reasoning window - the only “memory” it has while thinking; anything outside it may as well not exist. Hit it and the call fails or gets compacted. Money cannot raise it.
  • Usage limit caps your spending over time, denominated in dollars: your plan or API budget across all calls. Hit it and you wait or pay. Trimming one prompt barely moves it.

A lean context serves both: fewer tokens per call keeps you under the window, and tokens times calls is exactly what the dollar meter counts.

Token Pricing

Tokens only become cost once you know the per-token price, and prices vary by orders of magnitude across models. Compare them before you commit a model to a loop: the OpenCode Go model list covers the runtime models your agent calls, and OpenRouter lists prices across most providers.

The most important takeaway of this is there is a huge variety of models to choose from, at many different price-points.

Lab Frontier Flagship Mid-tier Cost-efficient Laptop-grade Toaster-grade
Anthropic (Claude) Fable 5
$10.00 / $50.00
Opus 5
$5.00 / $25.00
Sonnet 5
$2.00 / $10.00
Haiku 4.5
$1.00 / $5.00
- -
OpenAI (GPT) 5.6 Sol
$5.00 / $30.00
5.6 Terra
$1.00 / $6.00
5.6 Luna
$0.10 / $0.60
- gpt-oss-20b
Orca 2 13B*
$0.01 / $0.15
-
Moonshot (Kimi) K3
$2.90 / $14.00
K2.7 Code
$0.70 / $3.50
K2.6
$0.58 / $3.40
K2.5
$0.38 / $2.03
- -
Alibaba (Qwen) 3.8 Max
$2.00 / $6.00
3.7 Max
$1.48 / $4.43
3.7 Plus
$0.32 / $1.28
3.7 Flash
$0.03 / $0.13
3.6 35B A3B
Sky-T1 32B*
$0.01 / $0.15
3 4B
$0.00 / $0.03
Google (Gemini) - 3.1 Pro Preview
$2.00 / $12.00
3.6 Flash
$1.50 / $7.50
3.5 Flash-Lite
$0.30 / $2.50
Gemma 4 12B
$0.01 / $0.15
Gemma 4 E2B
$0.00 / $0.03
Z.ai (GLM) - 5.2
$0.60 / $1.50
5
$0.60 / $1.92
4.7 Flash
$0.06 / $0.40
4.7 Flash
$0.01 / $0.15
Edge 1.5B
$0.00 / $0.03
DeepSeek - V4 Pro
$0.44 / $0.87
V3.2
$0.21 / $0.31
V4 Flash 0731
$0.09 / $0.18
R1 Distill 14B*
$0.01 / $0.15
R1 Distill 1.5B*
$0.00 / $0.03

Prices are $ per million tokens, input / output. Columns are capability tiers, not price bands. Kimi K3 shown here is an INT4 route, against $3.00 / $15.00 on Moonshot’s full-precision API. Sonnet 5 at $2.00 / $10.00 is introductory and reverts to $3.00 / $15.00 after 2026-08-31.

The cheap extreme is self-hosting: laptop-grade (runs on a consumer laptop) and toaster-grade (4B params or under, runs on embedded systems) are open weights you run yourself. GLM 4.7 Flash appears twice on purpose: cheaper to self-host. * are popular third-party distillations.

Tiers: artificialanalysis.ai; prices: openrouter.ai; as of 2026-08-09.

How to pick a model

For our class, the candidate runtime models are:

  • intake: DeepSeek V4 Flash or MiMo V2.5
  • dispatch: MiniMax M3, MiMo V2.5 Pro, DeepSeek V4 Pro, or Qwen 3.7 Plus.

A tremendous source of wastage in AI utility design is over-specifying models relative to their utility - a frontier model on a job a cheap one does as well burns budget on every single call.

Part of this class is deciding if the expensive pick actually earns its price on your task, by benchmarking it on data.

Token and caching strategies

Prefix caching Providers cache already-processed requests; a following call that begins with a byte-identical prefix pays only a re-read price (typically about 10% of the fresh-read price) until the cache expires from inactivity (typically 5 minutes, but up to an hour on a Claude subscription).

An agent loop resends the whole conversation on every call, so in an ongoing session nearly all input tokens are cheap cache reads. You can see this with npx ccusage, which breaks down the usage by cached and new reads.

new input, full price cache read, 10% of input price "current time: 14:32" in the system prompt

Stable first, volatile last: the prefix survives

turn 1
system + tools + rules 40k6k
$0.092
turn 2
cache hit 46k6k
$0.021
turn 3
cache hit 52k6k
$0.022
turn 4
cache hit 58k6k
$0.024
turn 5
cache hit 64k6k
$0.025

A clock in the system prompt: nothing survives

turn 1
system + tools + rules + state 46k
$0.092
turn 2
everything re-read 52k
$0.104
turn 3
everything re-read 58k
$0.116
turn 4
everything re-read 64k
$0.128
turn 5
everything re-read 70k
$0.140

Here we show you what that looks like when you run a 40k-token prefix and 6k of new tokens per turn at Sonnet 5 prices ($2.00 / M input, $0.20 / M cache read). The pale bar is cached, costing $0.20/M tokens. The dark bar is a fresh read, costing $2.00/M tokens. When the cache is used properly and the prefix is stable, five turns cost $0.18. If we make a small mistake (such as including a clock in the system prompt), the whole read is billed anew and five turns cost $0.58.

By the time this conversation extends to 200k tokens the price difference is huge: $0.40 vs $5.60.

You will exploit exactly this in Stage 1: dispatcher to cut the time and cost of your dispatch bot: its per-tick calls should share a long stable prefix, depending on how you design the prompt.