-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Chat completions stream cut off without finich_reason (regression after update) #1738
Copy link
Copy link
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Confirm this is a Node library issue and not an underlying OpenAI API issue
- This is an issue with the Node library
Describe the bug
Its a bit hard to exactly pinpoint whats going on but we have an application running for some time now on version 6.9.1 of the sdk where every thing works as expected.
When we upgraded to version 6.16.0 the stream response was cut of mid generation...
To Reproduce
The following code works with SDK version 6.9.1 and cuts off half way in version 6.16.0 without finich reason.
Keep in mind that the input tokens are in total over 50k and we expect over 40K output tokens. (it takes some time to complete..)
// Setup of client
const client = new OpenAI({
apiKey: key,
})
// Start completion
const response = client.chat.completions.create({
messages: [
{ role: 'system' as const, content: systemPrompt || 'You are a helpful assistant.' }, // dynamic system prompt
{ role: 'user' as const, content: input }, // dynamic input
],
model: 'gpt-5.1-2025-11-13',
stream: true,
stream_options: {
include_usage: true,
},
user: '123', // dynamic user id
store: false,
reasoning_effort: 'none',
response_format: {
type: 'json_schema',
json_schema: {
name: 'schema_name', // dynamic name
strict: true,
schema: z.toJSONSchema(zodSchema), // dynamic zod schema here
},
},
})
// Handeling incomming data
let fullResponse = ''
let finishReason: ChatCompletionChunk.Choice['finish_reason'] | null = null
let usage: OpenAI.Completions.CompletionUsage | null = null
for await (const chunk of response) {
const choice = chunk.choices[0]
if (!choice) continue
if (choice.delta.content) {
const newGeneratedToken = choice.delta.content
fullResponse += newGeneratedToken
}
if (choice.finish_reason) {
finishReason = choice.finish_reason
}
if (chunk.usage) {
usage = chunk.usage
}
}
// Handeling errors etc..
if (!finishReason) {
throw new Error('OpenAI response has no finish reason')
}
// Do some more workCode snippets
OS
macOS - 26.2
Node version
node v22.20.0
Library version
openai 6.16.0
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working