Lesson 02 ยท Foundations

Tokens, Context & the Cost of a Call

The three numbers behind every scoping conversation โ€” plus your first real API call.

FDE skill ยท size and price a solution before you build it
๐ŸŽง Listen to this lesson ยท ~6 min ยท narrated audiobook edition

Here's a moment you will live many times as an FDE: a customer describes a feature โ€” "summarize every support ticket as it comes in" โ€” and looks at you. Can we do it, what will it cost, will it be fast enough? Answering that on the spot takes exactly three numbers: input tokens, output tokens, and the context window. This lesson gives you all three, then you'll make your first real API call and read them off the meter yourself.

Tokens are the meter

From Lesson 01 you know the model reads and writes tokens โ€” chunks of text, usually part of a word. Rough rule for English prose: 1 token โ‰ˆ ยพ of a word, so 1,000 tokens is roughly 750 words.1 Everything is denominated in tokens: pricing, speed, and limits. Words don't matter; tokens do.

And tokenization isn't uniform. Code, JSON, and rare words split into more tokens per word than plain prose โ€” a config blob can cost triple what an equivalent-length sentence does. That's why an FDE never estimates from word counts: you count tokens (the API has a free endpoint for exactly this โ€” it's Part 1 of your lab).

What a call costs

Pricing is per million tokens, and here's the part people miss: output tokens cost about 5ร— more than input tokens. Reading is cheap; generating is expensive โ€” every output token is one pass of the next-token loop.1 Current Claude pricing2 as of mid-2026:

ModelTierInput $/1MOutput $/1MContext window
Claude Opus 4.8Most capable$5.00$25.001M tokens
Claude Sonnet 5Balanced$3.00$15.001M tokens
Claude Haiku 4.5Fast & cheap$1.00$5.00200K tokens
Worked example โ€” the scoping math Customer support bot on Opus 4.8: each conversation sends ~2,000 input tokens (system prompt + ticket + history) and generates ~500 output tokens.

Input: 2,000 ร— $5/1M = $0.010  ยท  Output: 500 ร— $25/1M = $0.0125  โ†’  ~2.3ยข per conversation.
At 10,000 conversations/day: โ‰ˆ $225/day โ‰ˆ $6,800/month. Now you can discuss whether Haiku at ~$1,350/month is good enough for this task. That conversation is FDE work.

The context window is the model's working memory

The context window caps how much the model can consider at once โ€” prompt plus answer. Modern Claude models take 1M tokens (~2,000 pages); Haiku takes 200K.2 Two practical consequences: anything the model must "know" has to fit, and since input tokens cost money, stuffing the window is a cost decision too. "Just paste in all 10 years of customer docs" is rarely the right answer โ€” that instinct is what leads to RAG, a few lessons from now.

Latency: the answer length is the clock

Reading input is fast and parallel; generating output happens one token at a time through the loop from Lesson 01. So response time is dominated by output length, not input length. Two levers every FDE uses: cap or prompt for shorter outputs, and stream the response so the user sees words immediately โ€” the time to first token is what a user feels, and streaming makes a 20-second answer feel instant.

๐Ÿงช Lab: your first API call

Time to touch the metal. The lab file is in your workspace at labs/0002-first-api-call.py. One-time setup, then run it:

# one-time setup (PowerShell)
pip install anthropic
$env:ANTHROPIC_API_KEY = "sk-ant-..."   # from console.anthropic.com

python labs/0002-first-api-call.py

Three parts, each proving something from this lesson with a tight feedback loop: Part 1 counts tokens on four strings โ€” watch JSON cost ~2ร— the tokens of prose. Part 2 makes a real call and reads response.usage โ€” the exact meter you'll use to price customer features โ€” then computes the dollar cost. Part 3 streams a response and measures time-to-first-token versus total time, so you see that generation, not reading, is the slow part. The whole lab costs under a cent.

Check yourself โ€” scope the feature

Same drill as Lesson 01: customer scenarios, and you diagnose from the mechanism. Don't scroll up. Wrong picks stay live.

Scenario A

A customer wants 100-page contracts summarized into one paragraph each. Costs are too high in the pilot. Which lever cuts cost the most?

Scenario B

Users complain the assistant "hangs" for 15 seconds on detailed answers, though short answers feel fine. What's the primary cause?

Scenario C

To save money, a team moves a workflow to Haiku and pastes an entire knowledge base (~350K tokens) into every prompt. Calls now fail. Why?

Primary source โ€” read this
The canonical book for this exact career path. Chapter 2 covers tokens, sampling, and the model-as-a-service economics behind this lesson. The companion repo (linked) is free; the book itself is worth owning for the whole journey.
Your one tangible win Give yourself the test: a customer wants ticket summarization at 50,000 tickets/month, ~1,500 input + 300 output tokens each. You can now estimate the monthly cost on two models, say which of input or output dominates, and check it fits the context window โ€” before writing a line of code. That's a scoping conversation you can lead.
I'm your teacher โ€” ask me anything. Lab won't run? API key trouble? Curious why output tokens cost more, or what "prompt caching" means on the pricing page? Ask in chat โ€” debugging your first API call together is exactly what I'm for.

References

  1. Chip Huyen, AI Engineering (O'Reilly, 2025) โ€” tokens, sampling, and inference economics.
  2. Anthropic, Claude models & pricing documentation โ€” model tiers, per-token pricing, and context windows (verified July 2026).