Only initiate API clients once in a page request
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3561497. -->
Reported by: [mxr576](https://www.drupal.org/user/315522)
Related to !28
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>The implementation rebuilds both the generic AI client and the Amazee-specific AI client every time an AI interaction is triggered within a single page request, instead of reusing a single instance per request as intended by the base AI provider APIs.
</p>
<p>
This behavior stems from the implementation of <code>\Drupal\ai_provider_amazeeio\Plugin\AiProvider\AmazeeioAiProvider::loadClient()</code>, which overrides and bypasses the instantiation protection and reuse pattern provided by <code>\Drupal\ai\Base\OpenAiBasedProviderClientBase::loadClient()</code>, and applies a similar per-call construction pattern for the Amazee AI client it manages.</p>
<h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<ul>
<li>Refactor <code>AmazeeioAiProvider::loadClient()</code> so that it delegates client lifecycle and reuse to <code>OpenAiBasedProviderClientBase::loadClient()</code> instead of duplicating or circumventing that logic.</li>
<li>Introduce or align with an internal caching pattern for the Amazee AI client so that it is constructed at most once per page request and then reused for subsequent AI operations initiated through this provider.</li>
</ul>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<h3 id="summary-ui-changes">User interface changes</h3>
<h3 id="summary-api-changes">API changes</h3>
<h3 id="summary-data-model-changes">Data model changes</h3>
issue