Retries¶
GatewayConfig.retry_policy (CLI: --retry-policy '{"max_retries": 10, "delay_seconds": 60}') makes the gateway resend a request whose provider attempt failed, before the client sees the failure. It supersedes retry_attempts/retry_max_wait.
Each failed attempt is classified by protoverta.error_classes.classify from the HTTP status, the structured error.type/error.code and a small set of message patterns seen from real providers:
Class |
Typical signal |
Retried by default |
|---|---|---|
|
429, |
yes, waiting at least |
|
503, 529, |
yes |
|
500, 502, 504, |
yes |
|
connection refused/reset, DNS failure, socket timeout |
yes |
|
a stream that fails or ends before any output |
yes |
|
“created under a different Azure OpenAI resource” |
yes |
|
anything not recognised below |
yes |
|
401, 403, “invalid api key”, “unauthorized client” |
no |
|
402, “insufficient credits/quota” |
no |
|
404, “not a valid model ID”, “model … not found” |
no |
|
413, “maximum context length” |
no |
|
content filter, “flagged by the safety system” |
no |
|
other 400/422 |
no |
Rules:
A stream is read until it produces output. Output is never resent; a stream that fails after output reaches the client as it is.
An upstream
x-should-retryheader wins over the class:falseis never retried,truealways is.Waits are
delay_seconds±jitter(a fraction), at least the provider’sRetry-After, and stop aftermax_retriesretries,max_total_secondsof waiting or the request’s total deadline. A deliberate wait does not count againstprogress_timeout.Local deadlines and client disconnects are never retried. Cancelling the request in the client stops the wait.
The last failure reaches the client with
x-should-retry: false, so the client does not retry it again on top. Forgive_up_window_seconds(30 s) after giving up, further failures are answered at once: clients that resend immediately (Codex reconnects, Claude Code resending a 400 with fewer features) do not run another full cycle each.retry_classes/no_retry_classesadd or remove classes;skip_statuslists statuses that are never retried.retry_log(a callable) receives one line per decision with the class, status and provider message; no request content is logged.
Network retries resend a request whose generation may already have started upstream; providers can bill such attempts. Remove network from the retried classes where that matters.
Configuration¶
From the command line, pass a JSON object; from Python, a protoverta.error_classes.RetryPolicy:
protoverta ... --retry-policy '{"max_retries": 10, "delay_seconds": 60, "no_retry_classes": ["network"]}'
from protoverta.error_classes import RetryPolicy
from protoverta.server import GatewayConfig
config = GatewayConfig(..., retry_policy=RetryPolicy(max_retries=10, delay_seconds=60), retry_log=print)
The launchers read the same settings from the [retry] table of their configuration file.