Title: WP_AI_Client_HTTP_Client::sendRequestWithOptions
Published: May 20, 2026

---

# WP_AI_Client_HTTP_Client::sendRequestWithOptions( WordPressAiClientDependenciesPsrHttpMessageRequestInterface $request, WordPressAiClientProvidersHttpDTORequestOptions $options ): WordPressAiClientDependenciesPsrHttpMessageResponseInterface

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_ai_client_http_client/sendrequestwithoptions/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_ai_client_http_client/sendrequestwithoptions/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_ai_client_http_client/sendrequestwithoptions/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_ai_client_http_client/sendrequestwithoptions/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_ai_client_http_client/sendrequestwithoptions/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_ai_client_http_client/sendrequestwithoptions/?output_format=md#wp--skip-link--target)

Sends a PSR-7 request with transport options and returns a PSR-7 response.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_ai_client_http_client/sendrequestwithoptions/?output_format=md#parameters)󠁿

 `$request`WordPressAiClientDependenciesPsrHttpMessageRequestInterfacerequired

The PSR-7 request.

`$options`WordPressAiClientProvidersHttpDTORequestOptionsrequired

Transport options for the request.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_ai_client_http_client/sendrequestwithoptions/?output_format=md#return)󠁿

 WordPressAiClientDependenciesPsrHttpMessageResponseInterface The PSR-7 response.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_ai_client_http_client/sendrequestwithoptions/?output_format=md#source)󠁿

    ```php
    public function sendRequestWithOptions( RequestInterface $request, RequestOptions $options ): ResponseInterface {
    	$args = $this->prepare_wp_args( $request, $options );
    	$url  = (string) $request->getUri();

    	$response = wp_safe_remote_request( $url, $args );

    	if ( is_wp_error( $response ) ) {
    		$message = sprintf(
    			/* translators: 1: Request URL. 2: Error message. */
    			__( 'Network error occurred while sending request to %1$s: %2$s' ),
    			$url,
    			$response->get_error_message()
    		);

    		throw new NetworkException(
    			$message, // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
    			$response->get_error_code() ? (int) $response->get_error_code() : 0
    		);
    	}

    	return $this->create_psr_response( $response );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/ai-client/adapters/class-wp-ai-client-http-client.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/ai-client/adapters/class-wp-ai-client-http-client.php#L99)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/ai-client/adapters/class-wp-ai-client-http-client.php#L99-L120)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_ai_client_http_client/sendrequestwithoptions/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_AI_Client_HTTP_Client::prepare_wp_args()](https://developer.wordpress.org/reference/classes/wp_ai_client_http_client/prepare_wp_args/)`wp-includes/ai-client/adapters/class-wp-ai-client-http-client.php` |

Prepares WordPress HTTP API arguments from a PSR-7 request.

  | 
| [WP_AI_Client_HTTP_Client::create_psr_response()](https://developer.wordpress.org/reference/classes/wp_ai_client_http_client/create_psr_response/)`wp-includes/ai-client/adapters/class-wp-ai-client-http-client.php` |

Creates a PSR-7 response from a WordPress HTTP response.

  | 
| [wp_safe_remote_request()](https://developer.wordpress.org/reference/functions/wp_safe_remote_request/)`wp-includes/http.php` |

Retrieves the raw response from a safe HTTP request.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [is_wp_error()](https://developer.wordpress.org/reference/functions/is_wp_error/)`wp-includes/load.php` |

Checks whether the given variable is a WordPress Error.

  |

[Show 2 more](https://developer.wordpress.org/reference/classes/wp_ai_client_http_client/sendrequestwithoptions/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_ai_client_http_client/sendrequestwithoptions/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_ai_client_http_client/sendrequestwithoptions/?output_format=md#changelog)󠁿

| Version | Description | 
| [7.0.0](https://developer.wordpress.org/reference/since/7.0.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_ai_client_http_client%2Fsendrequestwithoptions%2F)
before being able to contribute a note or feedback.