← Master Index
Vol. 13 Module 13.4 Lecture

Per-Token Pricing

Price & Cost Control (added)

How This Lesson Fits the Module & Volume

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 $).
Definition

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 ideaMeterNotes
Chat / completionIn + out tokensCore app traffic
EmbeddingsInput tokensUsually cheaper; no generation
Cached inputDiscounted inputSee prompt caching lesson
BatchDiscounted asyncSee batch discounts lesson

Code: Cost From Usage

# Example rates -- replace with your provider's current card PRICE = { "gpt-4o-ish": {"in_per_m": 2.50, "out_per_m": 10.00}, } def cost_usd(model: str, prompt_tokens: int, completion_tokens: int) -> float: r = PRICE[model] return (prompt_tokens * r["in_per_m"] + completion_tokens * r["out_per_m"]) / 1_000_000 print(round(cost_usd("gpt-4o-ish", 3_000, 800), 6))

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
Common Misconception

“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

  1. Short Answer: What does per-token pricing multiply? Answer: Token counts by a $/token (usually $/1M) rate.
  2. True/False: Input and output often have different rates. Answer: True.
  3. Multiple Choice: Best local counter for OpenAI-class text: (a) tiktoken, (b) bathroom scale, (c) DPI. Answer: (a).
  4. Short Answer: Why pin rates in config? Answer: Provider price cards change; code must track versions.
  5. True/False: Embedding SKUs usually bill output tokens like chat. Answer: False—typically input only.
  6. Multiple Choice: Larger context window dumps mainly increase: (a) freebies, (b) billed tokens/cost, (c) CSS. Answer: (b).
  7. Short Answer: Where do prompt_tokens come from after a call? Answer: The API usage object (reconcile with local counts).
  8. Short Answer: Name one discounted meter you will study next. Answer: Cached input or batch (either).
  9. Multiple Choice: Unit economics should use: (a) only RPM, (b) tokens × rates, (c) font size. Answer: (b).
  10. 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.
Trainer’s Guide

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.