Assistant max_completion_tokens not returning status incomplete

According to openai documentation here:
https://platform.openai.com/docs/assistants/deep-dive/managing-threads-and-messages
When we use max_completion_tokens to limit maximum number of tokens used by openai response it should return status as “incomplete” and details will be provided in the incomplete_details.
But when I set max_completion_tokens what happens is that inside runStepDone callback I get status = “completed”.
Here is code snippet with console output that I am receiving:

    openai.beta.threads.runs.stream(thread.id, {
      assistant_id: assistantSettings.apiAssistantId,
      max_completion_tokens: 16,
    })
      .on('textDelta', (textDelta) => {
        res.write(`data: {"message": {"content": "${textDelta.value}"}, "threadId": "${thread.id}"}\n\n`);
      })
      .on('textDone', (content) => {
        res.write(`data: {"message": {"content": "[DONE!]"}, "threadId": "${thread.id}"}\n\n`);
        res.end();
      })
      .on('runStepDone', (runStep: RunStep) => {
        console.log(runStep.status);
        console.log(runStep.usage);
      });

This outputs following in console:

completed
{ prompt_tokens: 109, completion_tokens: 16, total_tokens: 125 }
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
Error: Final run has not been received

My question is that, did I not understand document correctly or am I doing something with with my code?
I think this is a bug with openai assistant probably

1 Like