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

@@ -15,12 +15,30 @@ public record ChatCompletionDeltaStreamLine(string Id, string Object, uint Creat
{
}
/// <summary>
/// What the provider says the request cost, on the one line which carries it.
/// </summary>
/// <remarks>
/// Not a positional parameter: every provider builds an empty line through the constructor
/// above, and a further parameter would change all of those call sites for a value none of
/// them has. Providers send this block only when the request asked for it, and then on a final
/// line of its own which carries no choices -- which is why the usage is read apart from the
/// content rather than next to it.
/// </remarks>
public ChatCompletionUsage? Usage { get; init; }
/// <inheritdoc />
public bool ContainsContent() => this.Choices.Count > 0;
/// <inheritdoc />
public ContentStreamChunk GetContent() => new(this.Choices[0].Delta.Content, []);
/// <inheritdoc />
public bool ContainsUsage() => this.GetUsage().IsKnown;
/// <inheritdoc />
public TokenUsage GetUsage() => this.Usage is null ? TokenUsage.UNKNOWN : TokenUsage.OfReported(this.Usage.PromptTokens, this.Usage.CompletionTokens);
#region Implementation of IAnnotationStreamLine
//