Talking to an API · practice
Stop at the Rate Limit
A 429 response says “stop for now.” It does not tell this small command to hide the response behind retries.
Implement inspect_rate_limit(attempt, *, timeout=DEFAULT_TIMEOUT, session=None) as exactly one GET to /scenarios/rate-limit, with params={"attempt": attempt}, the fixed header, and the explicit timeout.
Inspect status 429 before the generic status check. Decode that one error body and require error.code == "practice_rate_limited". Require Retry-After to be a non-empty decimal
{
"status": 429,
"retry_after": retry_after,
"code": "practice_rate_limited",
}
For a non-429 response, call raise_for_status() before json() and return the decoded success document. Any other unsuccessful status raises. Catch nothing.
Attempts 1 and 2 are deterministic 200 responses. Attempts 3 through 10 are deterministic 429 responses with Retry-After: 1. The server is stateless: the attempt query sleep, retry adapter,
Notice what this
What should this project do after one valid 429 response?
Task
Implement inspect_rate_limit as exactly one fixed internal GET. For 429, validate the exact error code and decimal Retry-After, then return the exact three-field stop