Skip to content

[BUG] StreamingChatCompletionUpdate.FinishReason always returns null #706

@BazInTheAZ

Description

@BazInTheAZ

Describe the bug

When streaming a chat completion through CompleteChatStreamingAsync, the FinishReason on the StreamingChatCompletionUpdate always returns null.

Monitoring the traffic to the API, I can see the finish reason in the returned data:

data: {"id":"2f5de4d2-34b4-4c79-a7e3-554c0cd0423e","model":"gpt-4.1-mini","created":1758571978,"object":"extensions.chat.completion.chunk","choices":[{"index":0,"delta":{"content":"!"},"end_turn":false,"finish_reason":null}],"system_fingerprint":"fp_4f3d32ad4e"}

data: {"id":"2f5de4d2-34b4-4c79-a7e3-554c0cd0423e","model":"gpt-4.1-mini","created":1758571978,"object":"extensions.chat.completion.chunk","choices":[{"index":0,"delta":{},"end_turn":true,"finish_reason":"stop"}],"system_fingerprint":"fp_4f3d32ad4e"}

data: [DONE]

Here is the relevant bit for looping through the updates:

var updates = chatClient.CompleteChatStreamingAsync(messages, options, CancellationToken.None);

await foreach (var update in updates)
{
    var token = string.Empty;
    if (update.FinishReason != null)
    {
        if (debug == "1")
        {
            token += $"\n\n----\n[DEBUG] Finish Reason: {update.FinishReason}\n----\n\n";

        }
    }
    if (update.ContentUpdate.Count == 0) continue;
    token += update.ContentUpdate[0].Text;
    if (string.IsNullOrEmpty(token)) continue;
    
    
    var bytes = Encoding.UTF8.GetBytes(token);
    await context.Response.OutputStream.WriteAsync(bytes, 0, bytes.Length);
    await context.Response.FlushAsync();
}

The finish reason is never added to the output. Furthermore, stepping through debugging, the FinishReason is always null.

Steps to reproduce

See code in problem description.

Code snippets

OS

Windows 11

.NET version

.NET Framework 4.8

Library version

2.4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageWorkflow: This is a new issue that needs to be triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions