Title: ResponseException
Published: May 20, 2026

---

# class ResponseException {}

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-exception-responseexception/?output_format=md#description)
 * [Methods](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-exception-responseexception/?output_format=md#methods)
 * [Source](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-exception-responseexception/?output_format=md#source)
 * [Changelog](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-exception-responseexception/?output_format=md#changelog)

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

Exception class for HTTP response errors.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-exception-responseexception/?output_format=md#description)󠁿

This is used when response data is unexpected or malformed, typically indicating
that a provider changed in ways our code is not aware of or when parsing response
data fails.

## 󠀁[Methods](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-exception-responseexception/?output_format=md#methods)󠁿

| Name | Description | 
| [ResponseException::fromInvalidData](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-exception-responseexception/frominvaliddata/) | Creates a ResponseException from invalid data in an API response. | 
| [ResponseException::fromMissingData](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-exception-responseexception/frommissingdata/) | Creates a ResponseException for missing expected data. |

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

    ```php
    class ResponseException extends RuntimeException
    {
        /**
         * Creates a ResponseException for missing expected data.
         *
         * @since 0.2.0
         *
         * @param string $apiName The name of the API/provider.
         * @param string $fieldName The field that was expected but missing.
         * @return self
         */
        public static function fromMissingData(string $apiName, string $fieldName): self
        {
            $message = sprintf('Unexpected %s API response: Missing the "%s" key.', $apiName, $fieldName);
            return new self($message);
        }
        /**
         * Creates a ResponseException from invalid data in an API response.
         *
         * @since 0.2.0
         *
         * @param string $apiName The name of the API service (e.g., 'OpenAI', 'Anthropic').
         * @param string $fieldName The field that was invalid.
         * @param string $message The specific error message describing the invalid data.
         * @return self
         */
        public static function fromInvalidData(string $apiName, string $fieldName, string $message): self
        {
            return new self(sprintf('Unexpected %s API response: Invalid "%s" key: %s', $apiName, $fieldName, $message));
        }
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/php-ai-client/src/providers/http/exception/responseexception.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/php-ai-client/src/Providers/Http/Exception/ResponseException.php#L16)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/php-ai-client/src/Providers/Http/Exception/ResponseException.php#L16-L46)

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