“Retry three times” sounds like a small allowance. It can become a large request burst when the same policy exists in a client, an application wrapper, and a job queue.
Consider a deliberately simplified example. A model client permits three attempts per call. A wrapper calls that client up to three times. The queue executes the wrapper up to three times. If every attempt reaches the service and fails, one logical job can produce twenty-seven model requests.
Those numbers are illustrative. They are not Codex defaults, gateway limits, or a measured incident. The point is multiplication: independent layers can each behave as configured while their combined behavior defeats the team's intended limit.
For developers investigating “Codex exceeded retry limit, last status: 429,” the first task is still identifying the service and reason for the response. After that, inspect who is allowed to retry. A repeated request is an operational decision, not a harmless implementation detail.
Draw the attempt boundary around the actual model request
A coding workflow has several identifiers. The user has a task. A queue may have a job. An agent may create several model turns. A client may make multiple HTTP attempts for one turn.
Count these separately. A task with ten valid model turns is different from a single turn resent ten times after an error. If your dashboard contains only task totals, the two behaviors can look identical.
For each attempted model call, record an application-generated logical call ID, an attempt number, the route label, the selected model, the error category, and elapsed time. Preserve provider or gateway request IDs when returned. Do not log authorization headers or the entire prompt by default.
The existing Codex 429 troubleshooting article covers finding the affected account, endpoint, and quota. This article starts once you can distinguish a retryable temporary condition from an error that needs a configuration or account change.
Decide which layer owns recovery
There is no universal rule that the SDK must own every retry. There should be an explicit rule for your application.
A short interactive request might let the HTTP client perform a small retry sequence within the user's deadline. A long background job might disable that sequence and let a durable scheduler decide when to try again. The important requirement is that one layer understands the total budget.
The official OpenAI Python SDK documents automatic retries and a max_retries setting. Those settings belong to that SDK. They are not a claim about the internal retry behavior of Codex, another provider's SDK, or every API gateway.
If your own Python worker wraps the SDK and needs full ownership, configure that worker deliberately:
The base URL must come from the verified documentation for the route you use. Turning off client retries does not turn off retries elsewhere. Inspect the queue, your wrapper, and any service-specific behavior independently.
For a Codex process, use the configuration documented for your installed version. Do not put Python constructor parameters into a TOML provider block. The advanced configuration reference is the appropriate starting point for client-specific settings.
Separate waiting from eligibility
Before calculating a delay, decide whether another request is justified.
An expired key needs credential repair. An unsupported model identifier needs a corrected route or model selection. A malformed tool schema needs a corrected request. Repeating those requests immediately adds noise without changing the condition that caused the failure.
A 429 response also needs interpretation. The response may concern temporary request pressure, token capacity, or an account-level limit. Use the service's documented error details. The OpenAI rate-limit guide describes rate limits and backoff for its API; a gateway's translated response must be interpreted using that gateway's contract.
An explicit Retry-After value describes when to consider a later attempt. It does not compel the application to keep a user waiting beyond its own deadline. The HTTP semantics specification permits both delay seconds and an HTTP date for this field.
Do not shorten a long server-requested delay to fit a small local cap and then retry early. If the delay exceeds the available budget, stop or schedule later. That distinction is easy to miss in a generic exponential-backoff helper.
A policy function that makes no network requests
The following example calculates a decision after a failed attempt. It accepts a supplied clock value, so its behavior can be tested without sleeping. attempts_used includes the attempt that just failed. The deadline and retryable classification belong to the application.
The numbers in this demonstration are application policy examples. They are not recommended limits for every model. A long reasoning request needs a different execution allowance from a short classification request.
In a running worker, calculate the remaining deadline using a monotonic clock. Use wall-clock UTC only to interpret an HTTP-date header. Set the next request's transport timeout so it also fits the remaining budget. Otherwise, a correct delay calculation can still be followed by a request that runs beyond the user's deadline.
Validate policy inputs at your configuration boundary: positive attempt counts, finite nonnegative durations, and an aware UTC time. The function illustrates the decision, not a complete scheduler, cancellation system, or persistent retry store.
A queue redelivery is not a fresh budget
A worker can stop correctly and still create a retry storm if the queue redelivers the job with its attempt counter reset.
Persist the logical call's retry history with the job. A replacement worker should know how many transport attempts have already been made, when another attempt becomes eligible, and whether the job's business deadline has passed.
For a user waiting in a browser, “defer” may mean return a clear pending status. For a batch workflow, it may mean schedule the next attempt. Neither should silently start a brand-new logical job with a fresh allowance.
Also separate model generation from business side effects. If an agent already executed an external action, replaying the entire workflow can repeat that action even when the model request retry itself is correctly bounded. Use operation receipts and reconciliation for those actions. A request budget alone cannot provide exactly-once business execution.
The background response polling guide is useful when your selected protocol supports durable background jobs. Do not replace a timed-out operation with a new generation before checking whether the original job is still running.
Measure useful recovery, not just fewer errors
A retry policy can reduce the number of visible errors by keeping users waiting longer. That is not necessarily an improvement.
Track accepted task completions, end-to-end latency, total transport attempts, and the fraction of jobs deferred or abandoned. Compare those measures on the same workload and model route. Keep interactive work and batch work separate because their deadlines serve different users.
Report the reason for the final outcome. “Attempt budget reached” and “account quota requires action” should not become the same generic failure message. The former suggests an operational decision; the latter requires a different response.
Test with synthetic failures before using paid traffic. Feed the policy a temporary error, an invalid key classification, a long Retry-After value, a malformed header, and an exhausted attempt count. Verify that it stops when expected. This catches logic errors without repeatedly sending real requests into an already constrained service.
Check cancellation and reconnects explicitly
A user can cancel while a worker is waiting for the next eligible attempt. The worker should check cancellation before sleeping, after waking, and before sending another request. Otherwise, the interface may show a cancelled task while the application continues creating model traffic.
Cancellation of a local wait does not necessarily cancel an upstream generation already accepted by the service. Record that distinction. Where the protocol offers a cancellation operation, use its documented semantics and retain the original operation identifier. Where it does not, explain that the local workflow has stopped while the remote outcome may still need reconciliation.
A streaming reconnect also deserves its own policy. Receiving a few output events and then losing the connection is different from failing before a request was accepted. Repeating the entire generation can produce a second answer and additional usage. If the protocol supports retrieving the original response, investigate that path before creating another operation.
Do not make a transport retry counter double as the agent's reasoning-step limit. A healthy agent may legitimately need several model turns, while one unhealthy turn may consume all of its retry allowance. Record both counters so a product owner can distinguish a complicated task from repeated transport failure.
Finally, test a worker restart during the waiting interval. The replacement worker should recover the persisted eligibility time and remaining allowance. If it starts at attempt one simply because it is a new process, your global budget exists only on paper. This is one of the most useful failure-injection tests for a queue-backed model integration because it exercises recovery without requiring a real provider outage.
Connect the policy to the model route
When evaluating a gateway, ask what error details and request identifiers the route returns. Determine whether retry-related headers survive the path. Record unknown behavior as unknown rather than assuming that an OpenAI-compatible body implies identical rate-limit semantics.
The gateway architecture guide provides the wider integration context. If the failure instead involves unsupported tool requests, use the Responses compatibility article or the forced tool-choice investigation. Authentication failures belong with the expired-key guide, not in a larger retry allowance.
To evaluate a route with this policy, create a 4SAPI account, confirm the required model and protocol are available, and run a small controlled workload using a separate test key. Set an application-side request budget before expanding traffic. The useful result is a traceable recovery policy whose total attempts you can explain.




