Title: _wp_connectors_is_ai_api_key_valid
Published: May 20, 2026

---

# _wp_connectors_is_ai_api_key_valid( string $key, string $provider_id ): bool|null

## In this article

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

[ Back to top](https://developer.wordpress.org/reference/functions/_wp_connectors_is_ai_api_key_valid/?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.

Checks whether an API key is valid for a given provider.

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

 `$key`stringrequired

The API key to check.

`$provider_id`stringrequired

The WP AI client provider ID.

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

 bool|null True if valid, false if invalid, null if unable to determine.

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

    ```php
    function _wp_connectors_is_ai_api_key_valid( string $key, string $provider_id ): ?bool {
    	try {
    		$registry = AiClient::defaultRegistry();

    		if ( ! $registry->hasProvider( $provider_id ) ) {
    			_doing_it_wrong(
    				__FUNCTION__,
    				sprintf(
    					/* translators: %s: AI provider ID. */
    					__( 'The provider "%s" is not registered in the AI client registry.' ),
    					$provider_id
    				),
    				'7.0.0'
    			);
    			return null;
    		}

    		$registry->setProviderRequestAuthentication(
    			$provider_id,
    			new ApiKeyRequestAuthentication( $key )
    		);

    		return $registry->isProviderConfigured( $provider_id );
    	} catch ( Exception $e ) {
    		wp_trigger_error( __FUNCTION__, $e->getMessage() );
    		return null;
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/connectors.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/connectors.php#L476)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/connectors.php#L476-L503)

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

| Uses | Description | 
| [ApiKeyRequestAuthentication::__construct()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-apikeyrequestauthentication/__construct/)`wp-includes/php-ai-client/src/Providers/Http/DTO/ApiKeyRequestAuthentication.php` |

Constructor.

  | 
| [AiClient::defaultRegistry()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-aiclient/defaultregistry/)`wp-includes/php-ai-client/src/AiClient.php` |

Gets the default provider registry instance.

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

Generates a user-level error/warning/notice/deprecation message.

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

Retrieves the translation of $text.

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

Marks something as being incorrectly called.

  |

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

| Used by | Description | 
| [_wp_connectors_rest_settings_dispatch()](https://developer.wordpress.org/reference/functions/_wp_connectors_rest_settings_dispatch/)`wp-includes/connectors.php` |

Masks and validates connector API keys in REST responses.

  |

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