OpenAi Api Assistant Answers with the Question value

Description: Ive encountered an issue when i send a message to the assistant it returns me the same value as a answer. but its not consistent issue, i can ask the same question a moment after and it will result with a actual answer.
this error usually characterized by long time of waiting for thread run to finish


client.beta.threads.messages.create(, role=“user”, content=user_message
return thread,client.beta.threads.runs.create(,

while run.status == “queued” or run.status == “in_progress”:
run = client.beta.threads.runs.retrieve(,,
return run

return client.beta.threads.messages.list(, order=“asc”).data[-1].content[0].text.value

thanks for eveyone who encountered this issue and found any solution

It can take a while before the Assistant writes a response to the thread of messages, so you need to keep polling the run status until one of the final statuses is set. e.g. [expired, completed, failed, cancelled].

Depending on which one of these final statuses your run ends up, you can then decide the appropriate action for your code to take. Ideally, look for the completed status as an indication of success and treat the other three final statuses as an error of some sort. Your code snippet seems to be only checking the queued and in_progress statuses, which might not be ideal if the run ends up in an error status as you are not handling the errors.

Also be careful of the requires_action status which results when there is a Function call that is required, as the Assistant will wait for up to 10min for your code to send the outputs of the call before expiring the run.

It takes a fair amount of code to properly handles all the possible states in a robust way.More information can be found on the Run lifecycle in the OpenAI docs.

1 Like