Record the task before the first send
After an AI API error, decide whether to correct the request, wait before another attempt, or investigate what happened to the submitted task. The practical outcome is a short retry policy. It specifies the reason for retrying, the delay, the waiting limit, and the action for an unknown outcome.
Before sending, assign an internal task number and preserve the input version. Record every actual send separately: its time, returned status, error reason, and response identifier, if available. One user task may involve several attempts.
For this method, use the states “waiting,” “in progress,” “complete,” “correction required,” and “outcome unknown.” Keep the last state separate: a missing response does not establish failure. This lets an operator see which work can continue without restarting the entire batch.
Choose an action based on the cause
The Claude API documentation associates codes 400, 401, and 403 with request or access problems, while 529 indicates temporary overload. For 429, examine the details: the cause may be a spending cap rather than request frequency alone.
Create a decision record for your API with three actions: correct, retry later, or investigate the outcome. Send invalid parameters for correction. Allow a confirmed temporary failure to receive a limited retry when doing so is safe. Check the particular intermediary’s or provider’s rules separately.
Treat successfully received but unsuitable text as an editorial revision. Otherwise, fresh generation becomes mixed with recovery from technical failures. Do not switch models within such a retry without a separate decision: that changes the conditions for producing the result and makes investigation harder.
Set a delay and an overall deadline
Google Cloud recommends increasing delays between attempts and adding random variation during temporary overload. For your policy, define a maximum delay and an overall task deadline. Measure elapsed time from the first send, including request execution and waiting between attempts.
According to MDN, the Retry-After header specifies a delay in seconds or a time after which another request may be made. Under the proposed policy, wait at least that long. If the delay exceeds the overall task deadline, stop automatic attempts and report the delay.
Check retry behavior in the application’s client library. For example, the official Claude SDK automatically retries transient failures twice by default. Put one layer in charge of sending and count every actual call. Otherwise, the library may additionally retry each application attempt.
Distinguish an unknown outcome from failure
Google Cloud recommends considering both the error and the operation’s idempotency: whether repeating it preserves the final state. The practical inference for this method is that losing the connection before receiving a response leaves the outcome unknown. Automatically starting that task again requires a separate justification.
If the particular API supports checking a task through its saved identifier, check its state first. If that option is unavailable, leave the task for manual investigation. An internal number links records but does not itself prevent another generation at the provider. Decide beforehand whether duplicates are acceptable.
Separate obtaining a draft from publishing it. Even when repeating text generation is acceptable, publishing again requires its own protection against duplicates. A saved draft and a publication record help you check these steps independently.
Example: eight product descriptions
Illustrative example: an editor needs eight short descriptions. For each, they choose a maximum of three actual sends, including the first, and 60 seconds of total elapsed time from the first send. These are hypothetical example settings, not service limits. Library retries are disabled; stopping the wait does not confirm server-side cancellation.
For a temporary failure without Retry-After, this example selects a random delay of one to two seconds, then two to four seconds. Before retrying, check the remaining overall time and use it to limit response waiting. If Retry-After specifies ten seconds, wait at least ten seconds, provided the deadline allows it.
Six descriptions are received and saved. The seventh receives a retry under this policy after an explicit temporary failure, only if retrying is acceptable for the chosen operation. The eighth loses its connection: mark its outcome unknown and investigate separately. Do not restart the whole batch. These numbers and events are invented for explanation; no tests were performed.
Verify stopping behavior and result preservation
Before enabling automatic retries, walk through hypothetical response scenarios on paper, without paid generations. A parameter error should stop processing and request correction. A temporary failure should permit a limited number of sends. Retry-After values expressed as seconds and as dates should produce the correct wait.
Separately check deadline exhaustion, restarting the batch, and a connection loss after sending. Completed results should remain saved, unknown outcomes should remain visible, and no further attempt should begin after the overall deadline. Count actual calls in the log, including library retries, and compare them with the chosen limit.
This exercise verifies your scheme’s behavior in the specified scenarios. It does not guarantee API availability, freedom from duplicate charges, or identical model responses. For operational use, add checks of the saved result: the intended product, language, and completeness. Assess technical success and suitability for publication separately.
