← Master Index
Vol. 13 Module 13.4 Lecture

Usage Quotas

Price & Cost Control (added)

How This Lesson Fits the Module & Volume

Usage quotas are longer-horizon ceilings—daily/monthly tokens, dollars, or requests—beyond per-minute rate limits. They are how orgs enforce budgets as product policy.

Pairs with spend alerts next; quotas are the hard stop, alerts are the early warning.

Related foundations: recount tokens with tiktoken (Vol. 12) and keep payloads inside the context window (Vol. 11).

Learning Objectives

By the end of this lesson, students should be able to:

  • Distinguish quotas from rate limits.
  • Set quotas in tokens and/or USD.
  • Implement soft vs hard quota behaviors.
  • Scope quotas by org, project, and API key.
  • Reset and carry-over policies intentionally.
  • Expose remaining quota to developers/users.
Definition

Usage quotas are maximum allowed consumption over a billing or calendar period (tokens, requests, or dollars), enforced independently of short-term rate limits.

ScopeExampleOwner
AccountProvider monthly capCloud admin
Project$5k LLM COGS / moEng + finance
API key / envStaging 2M tokens/dayPlatform
End customerPlan tier allowanceProduct

Code: Soft then Hard Quota

class TokenQuota: def __init__(self, limit, soft_ratio=0.8): self.limit = limit self.used = 0 self.soft = int(limit * soft_ratio) def authorize(self, tokens: int) -> str: if self.used + tokens > self.limit: return "hard_block" if self.used + tokens > self.soft: self.used += tokens return "soft_warn" self.used += tokens return "ok" q = TokenQuota(1_000_000) print(q.authorize(1000), q.used)

Rate limit

  • Per minute/second
  • Smooths bursts
  • Resets quickly

Quota

  • Per day/month
  • Enforces budget
  • Resets on schedule

Both

  • Needed together
  • Different UX errors
  • Different dashboards

Strengths

  • Predictable maximum spend
  • Multi-tenant fairness
  • Clear upgrade paths

Tradeoffs

  • Hard blocks anger users if opaque
  • Token vs $ quotas diverge with price changes
  • Reset cliffs cause rushes
Common Misconception

“RPM limits already protect our monthly budget.” A low RPM sustained 24/7 can still exhaust monthly dollars. Quotas close that gap.

Knowledge Check

  1. Short Answer: How do quotas differ from rate limits? Answer: Quotas are period budgets; rate limits are short-term throughput caps.
  2. True/False: Quotas can be denominated in USD. Answer: True.
  3. Multiple Choice: Soft quota typically: (a) warns, (b) formats disks, (c) changes embeddings. Answer: (a).
  4. Short Answer: Name a quota scope. Answer: Account, project, API key, or customer plan.
  5. True/False: Sustained low RPM cannot blow a monthly budget. Answer: False.
  6. Multiple Choice: Staging keys often need: (a) infinite quota, (b) tight quotas, (c) no logging. Answer: (b).
  7. Short Answer: Why expose remaining quota? Answer: So clients can shed load or upgrade before hard block.
  8. Short Answer: What meter from 13.3 feeds token quotas? Answer: Input/output token usage counts.
  9. Multiple Choice: Hard block should return: (a) silent success, (b) clear error/upgrade path, (c) random 200. Answer: (b).
  10. True/False: Price changes can desync token quotas from dollar budgets. Answer: True.

Key Takeaways

  • Quotas enforce period budgets; RPM does not.
  • Prefer soft warn then hard block.
  • Scope by project and customer tier.
  • Show remaining quota in APIs/UI.
  • Next: Spend Alerts & Budgets.
Trainer’s Guide

Lab: Design quota tiers for free/pro/enterprise; define soft% and hard actions.

Discussion: Token quota vs dollar quota—which for a multi-model gateway?

Recap: Quotas are the monthly walls around token spend. Continue with Spend Alerts & Budgets.