Retry policy

Provider error classes and the retry policy built on them.

One classifier is shared by the gateway (GatewayConfig.retry_policy) and by the launchers’ direct-mode relay, so both decide the same way. Classification uses the HTTP status, the structured error.type/error.code fields and a small set of message patterns seen from real providers. It never changes what the client receives; it only decides whether the same request is sent again.

protoverta.error_classes.error_detail(body)[source]

Return (type_or_code, message) from any common provider error shape.

Parameters:

body (object)

Return type:

tuple[str, str]

protoverta.error_classes.classify(status, body=None, *, transport=False, stream_before_output=False)[source]

Classify one failed attempt.

transport marks a connection failure (no HTTP answer); stream_before_output marks a stream that failed or ended before producing any output.

Parameters:
Return type:

Literal[‘rate_limit’, ‘overloaded’, ‘server’, ‘network’, ‘stream_interrupted’, ‘backend_mismatch’, ‘auth’, ‘billing’, ‘model_not_found’, ‘context_length’, ‘content_policy’, ‘invalid_request’, ‘unknown’]

class protoverta.error_classes.RetryPolicy(enabled=True, max_retries=10, delay_seconds=60.0, jitter=0.2, max_total_seconds=1800.0, retry_classes=frozenset({'backend_mismatch', 'network', 'overloaded', 'rate_limit', 'server', 'stream_interrupted', 'unknown'}), skip_status=frozenset({}), give_up_window_seconds=30.0, random=<built-in method random of Random object>)[source]

Bases: object

How long to keep resending one request whose provider attempt failed.

Attempts wait delay_seconds (± jitter as a fraction, at least the provider’s Retry-After) and stop after max_retries retries or max_total_seconds of waiting. skip_status keeps older configs working: those statuses are never retried whatever their class.

Parameters:
  • enabled (bool)

  • max_retries (int)

  • delay_seconds (float)

  • jitter (float)

  • max_total_seconds (float)

  • retry_classes (frozenset[Literal['rate_limit', 'overloaded', 'server', 'network', 'stream_interrupted', 'backend_mismatch', 'auth', 'billing', 'model_not_found', 'context_length', 'content_policy', 'invalid_request', 'unknown']])

  • skip_status (frozenset[int])

  • give_up_window_seconds (float)

  • random (Callable[[], float])

classmethod from_mapping(raw)[source]

Build from a [retry] config table; unknown keys are rejected.

Parameters:

raw (Mapping[str, object])

Return type:

RetryPolicy

protoverta.error_classes.describe(error_class, status, body)[source]

One bounded log line: class, status and the provider’s message.

Parameters:
  • error_class (Literal['rate_limit', 'overloaded', 'server', 'network', 'stream_interrupted', 'backend_mismatch', 'auth', 'billing', 'model_not_found', 'context_length', 'content_policy', 'invalid_request', 'unknown'])

  • status (int | None)

  • body (object)

Return type:

str

protoverta.retry.retry_after(headers, *, now=None)[source]

Seconds to wait from a Retry-After header (delta seconds or an HTTP date), or None.

Parameters:
  • headers (RetryHeaders | None)

  • now (float | None)

Return type:

float | None