Retry logic repeats a failed operation under explicit limits and delays. It is useful for temporary API or service failures, but every retry should be bounded, observable, and validated. section 4.1.1 section 12.3.4
A practical retry policy specifies:
- Which failures qualify, such as request timeouts or narrowly scoped API exceptions. section 4.1.1 section 12.3.4
- How many attempts are allowed: three for a NumbersAPI request, or two for an expensive extraction call. section 4.1.1 section 12.3.4
- How long to wait between attempts, with the example API workflow using five seconds. section 4.1.1
- What operators can observe through console messages and file logging for processing, success, timeout, and error states. section 4.1.1
Retrying a NumbersAPI request
A Python function processes each number, prints its progress, and loops while attempts remain and success is false. It sends the request with a timeout, records successful results, and logs failures. A prompt-driven implementation uses at most three attempts with a five-second pause between timeout retries. section 4.1.1
Retrying structured extraction
An extraction function can use a two-attempt decorator restricted to OpenAI API errors. The smaller budget reflects the higher cost of extraction and avoids repeating calls caused by invalid input. section 12.3.4
























