Title: Response::__construct
Published: May 20, 2026

---

# Response::__construct( int $statusCode,  $headers, string|null $body = null )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-response/__construct/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-response/__construct/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-response/__construct/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-response/__construct/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-response/__construct/?output_format=md#wp--skip-link--target)

Constructor.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-response/__construct/?output_format=md#parameters)󠁿

 `$statusCode`intrequired

The HTTP status code.

`string|list`<string>> $headers The response headers.

`$body`string|nulloptional

The response body.

Default:`null`

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-response/__construct/?output_format=md#source)󠁿

    ```php
    public function __construct(int $statusCode, array $headers, ?string $body = null)
    {
        if ($statusCode < 100 || $statusCode >= 600) {
            throw new InvalidArgumentException('Invalid HTTP status code: ' . $statusCode);
        }
        $this->statusCode = $statusCode;
        $this->headers = new HeadersCollection($headers);
        $this->body = $body;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/php-ai-client/src/providers/http/dto/response.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/php-ai-client/src/Providers/Http/DTO/Response.php#L53)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/php-ai-client/src/Providers/Http/DTO/Response.php#L53-L61)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-response/__construct/?output_format=md#related)󠁿

| Uses | Description | 
| [HeadersCollection::__construct()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-collections-headerscollection/__construct/)`wp-includes/php-ai-client/src/Providers/Http/Collections/HeadersCollection.php` |

Constructor.

  |

| Used by | Description | 
| [HttpTransporter::convertFromPsr7Response()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-httptransporter/convertfrompsr7response/)`wp-includes/php-ai-client/src/Providers/Http/HttpTransporter.php` |

Converts a PSR-7 response to a custom Response.

  | 
| [Response::fromArray()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-response/fromarray/)`wp-includes/php-ai-client/src/Providers/Http/DTO/Response.php` |

{@inheritDoc}

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-response/__construct/?output_format=md#changelog)󠁿

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

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwordpress-aiclient-providers-http-dto-response%2F__construct%2F)
before being able to contribute a note or feedback.