Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🔧 fix: Add missing `finish_reason` to stream chunks (#5563)

James Lamine1226f56d0c55
diff --git a/api/app/clients/OpenAIClient.js b/api/app/clients/OpenAIClient.js
index 8329a8b148..4ea4bc8d35 100644
--- a/api/app/clients/OpenAIClient.js
+++ b/api/app/clients/OpenAIClient.js
@@ -1364,6 +1364,14 @@ ${convo}
}
for await (const chunk of stream) {
+ // Add finish_reason: null if missing in any choice
+ if (chunk.choices) {
+ chunk.choices.forEach(choice => {
+ if (!('finish_reason' in choice)) {
+ choice.finish_reason = null;
+ }
+ });
+ }
this.streamHandler.handle(chunk);
if (abortController.signal.aborted) {
stream.controller.abort();