Title: _wp_connectors_pass_default_keys_to_ai_client
Published: May 20, 2026

---

# _wp_connectors_pass_default_keys_to_ai_client()

## In this article

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

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

Passes stored connector API keys to the WP AI client.

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

    ```php
    function _wp_connectors_pass_default_keys_to_ai_client(): void {
    	try {
    		$ai_registry = AiClient::defaultRegistry();
    		foreach ( wp_get_connectors() as $connector_id => $connector_data ) {
    			if ( 'ai_provider' !== $connector_data['type'] ) {
    				continue;
    			}

    			$auth = $connector_data['authentication'];
    			if ( 'api_key' !== $auth['method'] || empty( $auth['setting_name'] ) ) {
    				continue;
    			}

    			if ( ! $ai_registry->hasProvider( $connector_id ) ) {
    				continue;
    			}

    			// Skip if the key is already provided via env var or constant.
    			$key_source = _wp_connectors_get_api_key_source( $auth['setting_name'], $auth['env_var_name'] ?? '', $auth['constant_name'] ?? '' );
    			if ( 'env' === $key_source || 'constant' === $key_source ) {
    				continue;
    			}

    			$api_key = get_option( $auth['setting_name'], '' );
    			if ( ! is_string( $api_key ) || '' === $api_key ) {
    				continue;
    			}

    			$ai_registry->setProviderRequestAuthentication(
    				$connector_id,
    				new ApiKeyRequestAuthentication( $api_key )
    			);
    		}
    	} catch ( Exception $e ) {
    		wp_trigger_error( __FUNCTION__, $e->getMessage() );
    	}
    }
    ```

[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#L626)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/connectors.php#L626-L662)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/_wp_connectors_pass_default_keys_to_ai_client/?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_connectors_get_api_key_source()](https://developer.wordpress.org/reference/functions/_wp_connectors_get_api_key_source/)`wp-includes/connectors.php` |

Determines the source of an API key for a given connector.

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

Retrieves all registered connectors.

  | 
| [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.

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

Retrieves an option value based on an option name.

  |

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

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