SetChatTokeUsage should only run when then response is not streamed in OpenAiBasedProviderClientBase
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3545602. -->
Reported by: [marcus_johansson](https://www.drupal.org/user/385947)
Related to !866
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>Currently the SetChatTokeUsage is run, even when the response is of streamed type. Since the stream will not give back token usage, until the last chunk, this will:</p>
<p>a. fail, currently, because missing array structure<br>
b. not set any tokens, since this is set after the stream is consumed</p>
<h4 id="summary-steps-reproduce">Steps to reproduce (required for bugs, but not feature requests)</h4>
<p>Try to stream any provider that is based on it.</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>Fix so that SetChatTokenUsage only runs on none-streamed responses.</p>
issue