> 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.request

Managed request lifecycle helpers for outbound HTTP calls.

## Module Contents

### Functions

| Name                                                                        | Description                                                            |
| --------------------------------------------------------------------------- | ---------------------------------------------------------------------- |
| [`_resolve_http_client`](#nemoguardrails-http-request-_resolve_http_client) | Yield an injected client or create and close an owned client.          |
| [`http_call`](#nemoguardrails-http-request-http_call)                       | Execute one outbound HTTP request with deterministic client ownership. |

### API

```python
nemoguardrails.http.request._resolve_http_client(
    client: nemoguardrails.http.client.HTTPClient | None,
    factory: collections.abc.Callable[[], nemoguardrails.http.client.ClosableHTTPClient]
) -> collections.abc.AsyncIterator[nemoguardrails.http.client.HTTPClient]
```

async

Yield an injected client or create and close an owned client.

```python
nemoguardrails.http.request.http_call(
    client: nemoguardrails.http.client.HTTPClient | None,
    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,
    raise_for_status: bool = True,
    factory: collections.abc.Callable[[], nemoguardrails.http.client.ClosableHTTPClient] = create_http_client
) -> nemoguardrails.http.types.HTTPResponse
```

async

Execute one outbound HTTP request with deterministic client ownership.

**Parameters:**

**`client`** `HTTPClient | None`

Optional caller-owned client. When omitted, `factory` creates
a client that is closed after the request.

---

**`method`** `str`

HTTP method.

---

**`url`** `str`

Absolute request URL.

---

**`headers`** `Mapping[str, str] | None` — default: None

Optional request headers.

---

**`params`** `Mapping[str, Any] | None` — default: None

Optional query parameters.

---

**`json`** `Any` — default: None

Optional JSON-serializable request body.

---

**`content`** `bytes | str | None` — default: None

Optional raw request body.

---

**`timeout`** `float | None` — default: None

Optional total request timeout in seconds.

---

**`raise_for_status`** `bool` — default: True

Whether responses with status 400 or greater raise.

---

**`factory`** `Callable[[], ClosableHTTPClient]` — default: create\_http\_client

Factory for an owned client when `client` is omitted.

---

**Returns:** `HTTPResponse`

The materialized transport-neutral response.

**Raises:**

* `HTTPStatusError`: If `raise_for_status` is enabled and the response
  status is 400 or greater.
* `TypeError`: If `factory` returns a client that cannot be closed.