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

---

# WP_AI_Client_HTTP_Client::create_psr_response( $wp_response ): WordPressAiClientDependenciesPsrHttpMessageResponseInterface

## In this article

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

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

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

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

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

mixed> $wp_response WordPress HTTP API response array.

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

 WordPressAiClientDependenciesPsrHttpMessageResponseInterface PSR-7 response.

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

    ```php
    private function create_psr_response( array $wp_response ): ResponseInterface {
    	$status_code   = wp_remote_retrieve_response_code( $wp_response );
    	$reason_phrase = wp_remote_retrieve_response_message( $wp_response );
    	$headers       = wp_remote_retrieve_headers( $wp_response );
    	$body          = wp_remote_retrieve_body( $wp_response );

    	$response = $this->response_factory->createResponse( (int) $status_code, $reason_phrase );

    	if ( $headers instanceof WP_HTTP_Requests_Response ) {
    		$headers = $headers->get_headers();
    	}

    	if ( is_array( $headers ) || $headers instanceof Traversable ) {
    		foreach ( $headers as $name => $value ) {
    			$response = $response->withHeader( $name, $value );
    		}
    	}

    	if ( ! empty( $body ) ) {
    		$stream   = $this->stream_factory->createStream( $body );
    		$response = $response->withBody( $stream );
    	}

    	return $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#L201)
[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#L201-L225)

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

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

Retrieves only the response code from the raw response.

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

Retrieves only the response message from the raw response.

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

Retrieves only the headers from the raw response.

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

Retrieves only the body from the raw response.

  |

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

Sends a PSR-7 request and returns a PSR-7 response.

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

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

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_ai_client_http_client/create_psr_response/?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%2Fcreate_psr_response%2F)
before being able to contribute a note or feedback.