Module 13.4 converts token discipline into money discipline. Per-token pricing is how cloud LLM APIs charge: a rate times tokens (usually per million).
You inherit counts from Module 13.3 and tiktoken; here you multiply by published rates and design for change.
Learning Objectives
By the end of this lesson, students should be able to:
- Read a price card as $/1M input and $/1M output tokens.
- Compute request cost from usage fields.
- Track that list prices change; pin rates in config.
- Separate inference price from embedding/other SKUs.
- Explain why tokens—not requests alone—drive variable cost.
- Connect pricing to context size (more tokens → more $).
Per-token pricing bills model usage proportional to the number of tokens processed, typically as separate rates for input and output (and sometimes cached) tokens.
| SKU idea | Meter | Notes |
|---|---|---|
| Chat / completion | In + out tokens | Core app traffic |
| Embeddings | Input tokens | Usually cheaper; no generation |
| Cached input | Discounted input | See prompt caching lesson |
| Batch | Discounted async | See batch discounts lesson |
Code: Cost From Usage
Per-token
- Tracks true work
- Variable bill
- Needs counting
Per-request flat
- Simple UX tiers
- Cross-subsidizes heavy users
- Rare for raw LLM APIs
Subscription seat
- Predictable SaaS
- Still back with token COGS
- Pass-through risk
Strengths
- Fair metering of heavy prompts
- Aligns eng with COGS
- Transparent unit economics
Tradeoffs
- Rates change without code changes noticing
- Easy to forget output premium
- Multi-SKU apps need matrices
“We pay per API call, so prompt length does not matter.” On token-priced APIs, a 100k-context dump can cost orders of magnitude more than a short chat—same “one call.”
Knowledge Check
- Short Answer: What does per-token pricing multiply? Answer: Token counts by a $/token (usually $/1M) rate.
- True/False: Input and output often have different rates. Answer: True.
- Multiple Choice: Best local counter for OpenAI-class text: (a) tiktoken, (b) bathroom scale, (c) DPI. Answer: (a).
- Short Answer: Why pin rates in config? Answer: Provider price cards change; code must track versions.
- True/False: Embedding SKUs usually bill output tokens like chat. Answer: False—typically input only.
- Multiple Choice: Larger context window dumps mainly increase: (a) freebies, (b) billed tokens/cost, (c) CSS. Answer: (b).
- Short Answer: Where do prompt_tokens come from after a call? Answer: The API usage object (reconcile with local counts).
- Short Answer: Name one discounted meter you will study next. Answer: Cached input or batch (either).
- Multiple Choice: Unit economics should use: (a) only RPM, (b) tokens × rates, (c) font size. Answer: (b).
- True/False: One HTTP request always costs the same. Answer: False under per-token pricing.
Key Takeaways
- LLM cloud COGS are token-metered.
- Maintain a versioned price matrix.
- Compute from usage; verify with tiktoken estimates.
- Long contexts are a cost decision, not free capacity.
- Next: Input vs Output Pricing Tiers.
Lab: Build a tiny price table for 2 models; cost 5 sample traffic shapes.
Discussion: How do you communicate token-priced COGS to a PM used to per-seat SaaS?
Recap: Per-token pricing is the currency of Modules 13.3–13.4. Continue with Input vs Output Pricing Tiers.