Step-by-step answer
Stretch 60–75 min7 stepsA circuit breaker with deadlines in front of a flaky mock
A FastAPI mock of the Messages API with switchable failure modes (529s, 429 with and without retry-after, the spend cap, 400, slow responses and a mid-stream error event), a classifier for every failure, a deadline- and budget-aware retry wrapper, and a circuit breaker, all driven through the real anthropic SDK. In the 60-second overload the breaker cuts wasted calls from about 120 to about 25, at the cost of a few seconds' slower recovery.
Back to the exercise