Title: ProviderRegistry::createDefaultProviderRequestAuthentication
Published: May 20, 2026

---

# ProviderRegistry::createDefaultProviderRequestAuthentication( WordPressAiClientProvidersclass-string $className ): WordPressAiClientProviders?RequestAuthenticationInterface

## In this article

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

[ Back to top](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-providerregistry/createdefaultproviderrequestauthentication/?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 default request authentication instance for a provider.

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

 `$className`<span class="WordPressAiClientProvidersclass-string”>WordPressAiClientProvidersclass-
stringrequired

The provider class name.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-providerregistry/createdefaultproviderrequestauthentication/?output_format=md#return)󠁿

 WordPressAiClientProviders?RequestAuthenticationInterface The default request authentication
instance, or null if not required or if no credential data can be found.

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

    ```php
    private function createDefaultProviderRequestAuthentication(string $className): ?RequestAuthenticationInterface
    {
        $providerMetadata = $className::metadata();
        $providerId = $providerMetadata->getId();
        $authenticationMethod = $providerMetadata->getAuthenticationMethod();
        if ($authenticationMethod === null) {
            return null;
        }
        $authenticationClass = $authenticationMethod->getImplementationClass();
        if ($authenticationClass === null) {
            return null;
        }
        $authenticationSchema = $authenticationClass::getJsonSchema();
        // Iterate over all JSON schema object properties to try to determine the necessary authentication data.
        $authenticationData = [];
        if (isset($authenticationSchema['properties']) && is_array($authenticationSchema['properties'])) {
            /** @var array<string, mixed> $details */
            foreach ($authenticationSchema['properties'] as $property => $details) {
                $envVarName = $this->getEnvVarName($providerId, $property);
                // Try to get the value from environment variable or constant.
                $envValue = getenv($envVarName);
                if ($envValue === \false) {
                    if (!defined($envVarName)) {
                        continue;
                        // Skip if neither environment variable nor constant is defined.
                    }
                    $envValue = constant($envVarName);
                    if (!is_scalar($envValue)) {
                        continue;
                    }
                }
                if (isset($details['type'])) {
                    switch ($details['type']) {
                        case 'boolean':
                            $authenticationData[$property] = filter_var($envValue, \FILTER_VALIDATE_BOOLEAN);
                            break;
                        case 'number':
                            $authenticationData[$property] = (int) $envValue;
                            break;
                        case 'string':
                        default:
                            $authenticationData[$property] = (string) $envValue;
                    }
                } else {
                    // Default to string if no type is specified.
                    $authenticationData[$property] = (string) $envValue;
                }
            }
            // If any required fields are missing, return null to avoid immediate errors.
            if (isset($authenticationSchema['required']) && is_array($authenticationSchema['required'])) {
                /** @var list<string> $requiredProperties */
                $requiredProperties = $authenticationSchema['required'];
                if (array_diff_key(array_flip($requiredProperties), $authenticationData)) {
                    return null;
                }
            }
        }
        /** @var RequestAuthenticationInterface */
        /** @var array<string, mixed> $authenticationData */
        return $authenticationClass::fromArray($authenticationData);
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/php-ai-client/src/providers/providerregistry.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/php-ai-client/src/Providers/ProviderRegistry.php#L418)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/php-ai-client/src/Providers/ProviderRegistry.php#L418-L478)

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

| Uses | Description | 
| [ProviderRegistry::getEnvVarName()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-providerregistry/getenvvarname/)`wp-includes/php-ai-client/src/Providers/ProviderRegistry.php` |

Converts a provider ID and field name to a constant case environment variable name.

  |

| Used by | Description | 
| [ProviderRegistry::registerProvider()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-providerregistry/registerprovider/)`wp-includes/php-ai-client/src/Providers/ProviderRegistry.php` |

Registers a provider class with the registry.

  |

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