> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/guardrails/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/guardrails/_mcp/server.

# nemoguardrails.http.retry

Bounded retry policies and a transport-neutral retrying HTTP client.

## Module Contents

### Classes

| Name                                                                  | Description                                                        |
| --------------------------------------------------------------------- | ------------------------------------------------------------------ |
| [`RetryPolicy`](#nemoguardrails-http-retry-RetryPolicy)               | Configure bounded retries for an HTTP client.                      |
| [`RetryingHTTPClient`](#nemoguardrails-http-retry-RetryingHTTPClient) | Apply a retry policy around another transport-neutral HTTP client. |

### Functions

| Name                                            | Description |
| ----------------------------------------------- | ----------- |
| [`_header`](#nemoguardrails-http-retry-_header) | -           |

### API

```python
class nemoguardrails.http.retry.RetryPolicy(
    max_attempts: int = 3,
    retryable_methods: frozenset[str] = (lambda: frozenset({'DELETE...,
    retryable_status_codes: frozenset[int] = (lambda: frozenset({408, 40...,
    initial_delay: float = 0.5,
    max_delay: float = 8.0,
    max_retry_after: float = 60.0,
    retry_transport_errors: bool = True,
    honor_retry_override_header: bool = False,
    clamp_retry_after: bool = False
)
```

Dataclass

Configure bounded retries for an HTTP client.

`max_attempts` includes the initial request. Methods are normalized to
uppercase, and POST is intentionally absent from the safe default set.
`Retry-After` values are honored only when they fall within
`max_retry_after` unless clamping is explicitly enabled. Vendor override
headers are ignored unless `honor_retry_override_header` is enabled.

**`clamp_retry_after`** `bool = False`

---

**`honor_retry_override_header`** `bool = False`

---

**`initial_delay`** `float = 0.5`

---

**`max_attempts`** `int = 3`

---

**`max_delay`** `float = 8.0`

---

**`max_retry_after`** `float = 60.0`

---

**`retry_transport_errors`** `bool = True`

---

**`retryable_methods`** `frozenset[str]`

---

**`retryable_status_codes`** `frozenset[int]`

---

```python
nemoguardrails.http.retry.RetryPolicy.__post_init__() -> None
```

```python
nemoguardrails.http.retry.RetryPolicy.can_retry_method(
    method: str
) -> bool
```

Return whether the policy permits retrying the HTTP method.

```python
nemoguardrails.http.retry.RetryPolicy.retry_after(
    response: nemoguardrails.http.types.HTTPResponse,
    now: datetime.datetime
) -> float | None
```

Return a usable `Retry-After` delay in seconds.

Both delta-seconds and HTTP-date values are supported. Invalid or
out-of-policy values return `None` so the client uses exponential
backoff instead.

```python
nemoguardrails.http.retry.RetryPolicy.should_retry(
    response: nemoguardrails.http.types.HTTPResponse
) -> bool
```

Return whether a response status or opted-in override requests a retry.

```python
class nemoguardrails.http.retry.RetryingHTTPClient(
    client: nemoguardrails.http.client.HTTPClient,
    policy: nemoguardrails.http.retry.RetryPolicy | None = None,
    sleep: collections.abc.Callable[[float], collections.abc.Awaitable[None]] = asyncio.sleep,
    random_value: collections.abc.Callable[[], float] = random.random,
    now: collections.abc.Callable[[], datetime.datetime] | None = None
)
```

Apply a retry policy around another transport-neutral HTTP client.

Closing this wrapper closes the wrapped client only when it implements
:class:`ClosableHTTPClient`.

**`_now`** `= now or (lambda: datetime.now(timezone.utc))`

---

**`_policy`** `= policy or RetryPolicy()`

---

**`wrapped_client`** `HTTPClient`

Return the underlying client.

---

```python
nemoguardrails.http.retry.RetryingHTTPClient.__aenter__() -> nemoguardrails.http.retry.RetryingHTTPClient
```

async

Return this client from an asynchronous context manager.

```python
nemoguardrails.http.retry.RetryingHTTPClient.__aexit__(
    exc_type: object,
    exc_value: object,
    traceback: object
) -> None
```

async

Close wrapped resources when leaving an asynchronous context.

```python
nemoguardrails.http.retry.RetryingHTTPClient._backoff(
    retries: int
) -> float
```

```python
nemoguardrails.http.retry.RetryingHTTPClient._with_wrapped_client(
    client: nemoguardrails.http.client.HTTPClient
) -> nemoguardrails.http.retry.RetryingHTTPClient
```

Apply the current retry settings to another client.

```python
nemoguardrails.http.retry.RetryingHTTPClient.close() -> None
```

async

Close the wrapped closable client at most once.

```python
nemoguardrails.http.retry.RetryingHTTPClient.request(
    method: str,
    url: str,
    headers: typing.Mapping[str, str] | None = None,
    params: typing.Mapping[str, typing.Any] | None = None,
    json: typing.Any = None,
    content: bytes | str | None = None,
    timeout: float | None = None
) -> nemoguardrails.http.types.HTTPResponse
```

async

Send a request and retry eligible failures within policy bounds.

The returned response includes `retry_count` in its extensions.
Transport errors also expose their completed retry count before being
re-raised.

```python
nemoguardrails.http.retry._header(
    headers: typing.Mapping[str, str],
    name: str
) -> str | None
```