
openai
#10068
thread_operation_error
Cannot add messages to a thread while an active run is in progress.
This error has been identified and solved.
Reason
The error "Can't add messages to thread_JS11XQsRG0YCGFpW7ylpG2yM while a run run_yQrPxI86HgmUs0Q9b1XFx23L is active" with a 400 status code in the OpenAI API typically indicates that you are attempting to add messages to a conversation thread while an existing API request (or "run") is still active and has not yet completed.
This error occurs because the OpenAI API does not allow you to add new messages to a thread until the current run associated with that thread has finished. This is a restriction to maintain the integrity and sequence of the conversation flow.
Solution
To fix the error "Can't add messages to thread_JS11XQsRG0YCGFpW7ylpG2yM while a run run_yQrPxI86HgmUs0Q9b1XFx23L is active," you need to ensure that you are not attempting to add new messages to the thread until the current run has completed.
Wait for the current run to complete before adding new messages.
Check the status of the run periodically and only proceed with adding messages once the status is "completed".
Consider implementing a queue to handle messages that need to be added while a run is active, and process them once the run is completed.
Ensure your loop or asynchronous function correctly handles the waiting period for the run to finish before attempting to add new messages.
Suggested Links
https://cheatsheet.md/chatgpt-cheatsheet/openai-api-error-axioserror-request-failed-status-code-400
https://community.openai.com/t/cant-add-messages-to-thread-while-a-run-is-active/491669
https://community.openai.com/t/getting-400-response-with-already-working-code/509212
https://community.openai.com/t/is-api-not-working-i-get-the-error-run-is-active-right-from-the-second-request-to-the-specified-thread-id/508821
https://forum.bubble.io/t/open-ai-api-http-400-error-payload/268017
https://community.openai.com/t/i-am-receiving-an-error-status-code-400/351121
https://community.openai.com/t/error-400-can-t-add-messages-to-thread-while-a-run-is-active/1048887