Skip to content

Retries

Configure retries with RetryPolicy — attempt count, retryable statuses, backoff, and retry headers handling.

export function SdkSignature({children}) { async function copy(event) { const button = event.currentTarget; const code = button.parentElement.querySelector("pre code"); try { await navigator.clipboard.writeText(code.textContent); button.setAttribute("aria-label", "Signature copied"); button.dataset.copied = "true"; } catch { button.setAttribute("aria-label", "Copy failed; select the signature to copy"); } setTimeout(() => { button.setAttribute("aria-label", "Copy signature"); delete button.dataset.copied; }, 2000); } return

{children}
; }

typesafe\_sdk.RetryPolicy

dataclass

RetryPolicy(\n max_retries: [int](https://docs.python.org/3/builtins/functions.html#int) = 2,\n backoff_initial: [float](https://docs.python.org/3/builtins/functions.html#float) = 0.5,\n backoff_max: [float](https://docs.python.org/3/builtins/functions.html#float) = 5.0,\n backoff_jitter: [float](https://docs.python.org/3/builtins/functions.html#float) = 0.25,\n http_statuses: [set](https://docs.python.org/3/builtins/stdtypes.html#set)[[int](https://docs.python.org/3/builtins/functions.html#int)] = (\n lambda: {408, 429, *[range](https://docs.python.org/3/builtins/stdtypes.html#range)(500, 600)}\n )(),\n respect_retry_after: [bool](https://docs.python.org/3/builtins/functions.html#bool) = True,\n api_connection_error: [bool](https://docs.python.org/3/builtins/functions.html#bool) = True,\n api_timeout_error: [bool](https://docs.python.org/3/builtins/functions.html#bool) = True,\n exceptions: [set](https://docs.python.org/3/builtins/stdtypes.html#set)[\n [type](https://docs.python.org/3/builtins/functions.html#type)[[BaseException](https://docs.python.org/3/builtins/exceptions.html#BaseException)]\n ] = [set](https://docs.python.org/3/builtins/stdtypes.html#set)(),\n predicate: [Callable](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable)[[[BaseException](https://docs.python.org/3/builtins/exceptions.html#BaseException)], [bool](https://docs.python.org/3/builtins/functions.html#bool)]\n | None = None,\n timeout: [float](https://docs.python.org/3/builtins/functions.html#float) | None = 30.0,\n)\n

Configuration for SDK retry behavior.

Examples:

from typesafe_sdk import RetryPolicy, TypeSafeClient

client = TypeSafeClient(
    retry=RetryPolicy(
        max_retries=3, timeout=10.0, http_statuses={429, 500, 502, 503, 504}
    )
)

max\_retries

class-attribute instance-attribute

max_retries : [int](https://docs.python.org/3/builtins/functions.html#int) = 2 \n

Maximum retries after the initial attempt; 0 disables retries.

backoff\_initial

class-attribute instance-attribute

backoff_initial : [float](https://docs.python.org/3/builtins/functions.html#float) = 0.5 \n

First backoff delay in seconds, doubled each attempt up to backoff_max; zero disables backoff.

backoff\_max

class-attribute instance-attribute

backoff_max : [float](https://docs.python.org/3/builtins/functions.html#float) = 5.0 \n

Maximum backoff delay in seconds; zero disables backoff.

backoff\_jitter

class-attribute instance-attribute

backoff_jitter : [float](https://docs.python.org/3/builtins/functions.html#float) = 0.25 \n

Fraction of each backoff delay randomly subtracted, between 0 and 1.

http\_statuses

class-attribute instance-attribute

http_statuses: [set](https://docs.python.org/3/builtins/stdtypes.html#set)[[int](https://docs.python.org/3/builtins/functions.html#int)] = [field](https://docs.python.org/3/library/dataclasses.html#dataclasses.field)(\n default_factory=lambda: {\n 408,\n 429,\n *[range](https://docs.python.org/3/builtins/stdtypes.html#range)(500, 600),\n }\n)\n

HTTP status codes that are retried.

respect\_retry\_after

class-attribute instance-attribute

respect_retry_after : [bool](https://docs.python.org/3/builtins/functions.html#bool) = True \n

Whether to honor Retry-After and retry-after-ms response headers.

api\_connection\_error

class-attribute instance-attribute

api_connection_error : [bool](https://docs.python.org/3/builtins/functions.html#bool) = True \n

Whether to retry TypeSafeAPIConnectionError, raised when the request cannot reach or read from the server.

api\_timeout\_error

class-attribute instance-attribute

api_timeout_error : [bool](https://docs.python.org/3/builtins/functions.html#bool) = True \n

Whether to retry TypeSafeAPITimeoutError, raised when the request exceeds its timeout.

exceptions

class-attribute instance-attribute

exceptions: [set](https://docs.python.org/3/builtins/stdtypes.html#set)[[type](https://docs.python.org/3/builtins/functions.html#type)[[BaseException](https://docs.python.org/3/builtins/exceptions.html#BaseException)]] = [field](https://docs.python.org/3/library/dataclasses.html#dataclasses.field)(\n default_factory=[set](https://docs.python.org/3/builtins/stdtypes.html#set)\n)\n

Additional exception types that trigger a retry, on top of the built-in rules.

predicate

class-attribute instance-attribute

predicate: (\n [Callable](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable)[[[BaseException](https://docs.python.org/3/builtins/exceptions.html#BaseException)], [bool](https://docs.python.org/3/builtins/functions.html#bool)] | None\n) = None\n

An optional predicate called with the raised exception; returning True triggers a retry in addition to the other rules.

timeout

class-attribute instance-attribute

timeout : [float](https://docs.python.org/3/builtins/functions.html#float) | None = 30.0 \n

Total retry budget in seconds per SDK call, including the initial attempt and delays; None disables the limit.

Stops before a retry whose delay would reach or exceed the budget, re-raising the last error.