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

---

# ProviderRegistry::setRequestAuthenticationForProvider( WordPressAiClientProvidersclass-string $className, WordPressAiClientProvidersHttpContractsRequestAuthenticationInterface $requestAuthentication )

## In this article

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

[ Back to top](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-providerregistry/setrequestauthenticationforprovider/?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.

Sets the request authentication for a specific provider, hooking up its class instances.

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

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

The provider class name.

`$requestAuthentication`WordPressAiClientProvidersHttpContractsRequestAuthenticationInterfacerequired

The authentication instance.

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

    ```php
    private function setRequestAuthenticationForProvider(string $className, RequestAuthenticationInterface $requestAuthentication): void
    {
        $authenticationMethod = $className::metadata()->getAuthenticationMethod();
        if ($authenticationMethod === null) {
            throw new InvalidArgumentException(sprintf('Provider %s does not expect any authentication, but got %s.', $className, get_class($requestAuthentication)));
        }
        $expectedClass = $authenticationMethod->getImplementationClass();
        if (!$requestAuthentication instanceof $expectedClass) {
            throw new InvalidArgumentException(sprintf('Provider %s expects authentication of type %s, but got %s.', $className, $expectedClass, get_class($requestAuthentication)));
        }
        $availability = $className::availability();
        if ($availability instanceof WithRequestAuthenticationInterface) {
            $availability->setRequestAuthentication($requestAuthentication);
        }
        $modelMetadataDirectory = $className::modelMetadataDirectory();
        if ($modelMetadataDirectory instanceof WithRequestAuthenticationInterface) {
            $modelMetadataDirectory->setRequestAuthentication($requestAuthentication);
        }
        if (is_subclass_of($className, ProviderWithOperationsHandlerInterface::class)) {
            $operationsHandler = $className::operationsHandler();
            if ($operationsHandler instanceof WithRequestAuthenticationInterface) {
                $operationsHandler->setRequestAuthentication($requestAuthentication);
            }
        }
    }
    ```

[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#L384)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/php-ai-client/src/Providers/ProviderRegistry.php#L384-L408)

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

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

Sets the request authentication instance for the given provider.

  | 
| [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/setrequestauthenticationforprovider/?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%2Fsetrequestauthenticationforprovider%2F)
before being able to contribute a note or feedback.