How to delete expired runs and add new messages in a thread to continue the conversation

I am using the assistants api. When a run in the thread expires, I cannot continue to add messages to the thread. An error like this occurs:

openai.BadRequestError: Error code: 400 - {‘error’: {‘message’: “Can’t add messages to thread_xxxxxxxxxxxx while a run run_xxxxxxxxxxxis active.”, ‘type’: ‘invalid_request_error’, ‘param’: None, ‘code’: None}}

I understand that I can solve this problem by deleting the current thread and creating a new one, but this would result in the loss of the conversation history with the user. I would like to only delete the expired run, or change its status to ‘cancelled’, so that I can continue the conversation with the user in the original thread without losing the conversation history.

However, I haven’t found an API to delete a run.

I tried using the ‘Cancel a run’ interface to change the status to ‘cancelled’, but ‘expired’ cannot be changed to ‘cancelled’, as shown by this error:

openai.BadRequestError: Error code: 400 - {‘error’: {‘message’: “Cannot cancel run with status ‘expired’.”, ‘type’: ‘invalid_request_error’, ‘param’: None, ‘code’: None}}.

How should I solve this problem?



Were you able to find a solution to this? Currently struggling with this.

1 Like

It is very usefull (to delete pending run in a thread) expecially when debugging threads with assistants using functions tool.

EDIT: have a look to this thread also: How to delete a pending run in Assistants? - #4 by roberto_brunialti

1 Like