Added the exact token count where the provider reports it

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
j-erlerandClaude Opus 5 committed 2026-09-20 17:42:29 +02:00
1 parent c95cc5bacc
commit 0aa3b23b81
21 files changed
+598 -7

No files matched your search

@@ -456,6 +456,18 @@ public sealed class AIJobService(SettingsManager settingsManager, MessageBus mes
aiText.Text += contentStreamChunk;
aiText.Sources.MergeSources(contentStreamChunk.Sources);
//
// Keep what the provider says the request cost. It arrives on one line of the stream,
// usually the last one, and only where a provider reports it at all -- so a chunk
// without it leaves what was reported before alone.
//
if (contentStreamChunk.Usage.IsKnown)
{
aiText.ReportedPromptTokens = contentStreamChunk.Usage.PromptTokens;
aiText.ReportedCompletionTokens = contentStreamChunk.Usage.CompletionTokens;
aiText.ReportedForModel = state.ChatGenerationRequest.ProviderSettings.Model.Id;
}
if (state.Snapshot.Status is not AIJobStatus.RUNNING)
{
state.Snapshot = state.Snapshot with