Tokens, cost, and rate limits
Notebook· 01.06· 90–120 min· Lesson 15 of 129
The notebook opens in your lab, in a new tab. If your server is stopped, it starts first (a few seconds).
By the end you can
- Read
usage_metadata(input, output, reasoning and cached tokens) and explain which ones you pay for. - Aggregate usage across many calls and models with
get_usage_metadata_callback, and estimate cost with the course price table (mastery.pricing). - Read Groq's rate-limit headers and explain RPM/RPD/TPM/TPD.
- Throttle requests with
InMemoryRateLimiter, and explain what it cannot do. - Handle HTTP 429: what the built-in retries do (you'll read the SDK code),
with_retry, and exponential backoff with jitter that respectsretry-after.
Before you start
Lessons 01.01–01.05 (especially batching).
Python in this lesson
Python guideNew hereself and instance attributes__init__super()textwrapYour own exception classes
