Log inBook a Demo
BuildMidBackendAuto-graded

Add backoff to a client that hammers upstream

Make a retry wrapper wait longer between attempts, give up after a set number of tries and never retry permanent errors.Your service calls a flaky LLM API through retry(). The API team says your service keeps hitting them while they throttle it, requests that fail with a 400 or a ValueError show up in their logs again and again, and a call that keeps failing never gives up. Make retry() retry only RetryableError, wait base_delay * 2 ** attempt between tries, and stop after exactly max_attempts calls and re-raise the last error.
30 min
python

You're done when

  • A call that always fails is made exactly max_attempts times before retry() gives up.
  • An error that isn't a RetryableError is raised on the first call, with no retry and no sleep.
  • Each wait between attempts is longer than the one before.
  • The waits start at base_delay and grow exponentially, each about double the last.

What it measures

Backoff designSpacing retries out so a throttled API has time to recover.
Attempt countingMaking the number of calls and sleeps match `max_attempts` exactly.
Error classificationRetrying only transient errors and failing fast on everything else.

Your environment

Terminal + editorA full shell in the browser
Coding agentAlready signed in, no API key to set up
Isolated workspaceOnly yours, wiped when you finish

Start this lab

30 min
Start labYou'll need to sign in to Anthropos first. The lab opens in a private cloud workspace with your coding agent ready to use.
AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo