Assistant example stuck on "queued" status

I am testing the example math tutor code from the docs but the run status is stuck on either queue or in_progress. The same assistant is working in the playground.

from openai import OpenAI
import os
import dotenv
import docx
from time import sleep, ctime

dotenv.load_dotenv()
openai_api_key = os.getenv("OPEN_KEY")



client = OpenAI(api_key=openai_api_key)

assistant = client.beta.assistants.retrieve(assistant_id="MY_ASSISSTANT_ID")
thread = client.beta.threads.create()
message = client.beta.threads.messages.create(
    thread_id=thread.id,
    role="user",
    content="I need to solve the equation `3x + 11 = 14`. Can you help me?"
)
run = client.beta.threads.runs.create(
  thread_id=thread.id,
  assistant_id=assistant.id,
  instructions="Please address the user as Jane Doe. The user has a premium account."
)
run = client.beta.threads.runs.retrieve(
  thread_id=thread.id,
  run_id=run.id
)

print(client.beta.threads.messages.list(thread_id=thread.id))


print(run)
counter = 0
while run.status != "completed":
    print(f"[{ctime()}]: Working... {run.status}")
    if counter % 10 == 0:
        print(f"\t\t{run}")
    counter += 1
    sleep(5)

print(client.beta.threads.messages.list(thread_id=thread.id))

The API Reference says the run should almost instantly be moved to in_progress. If this is due to a lot of requests going in shouldn’t it fail?

2 Likes

I fixed it by updating fetching run status just after while:

while run.status != “completed”:
run = client.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id)
if counter % 10 == 0:
print(f"\t\t{run}")
counter += 1
time.sleep(5)

5 Likes

Thank you for your help! How did you come up with that?

2 Likes

Via the API github doc at openai-python/blob/main/api.md

1 Like

By reading the API documentation on github.

I am seeing long queue times in the order of minutes on runs. I don’t see any other requests happening at the same time.

Can you tell me how did you fixed it? I am also facing the same!!!

Facing the same issue here. My run is stuck in queued. The assistants API is also very slow

Hey folks! This should now be resolved. Please let me know if you continue to see this issue.

4 Likes

What happened today to the Assistant API, Custom GPTs and OpenAI systems in general? They were very degraded but the report was “all systems operational”… Do you have a report or something? Would be great.

1 Like

Hey Logan,

I’m still seeing the error, it seems to only happen when I create runs in a Flask app instead of a Jupyter notebook. Here’s the commands:

message = message_manager.create_message(thread_id=thread['id'], role="user", content=content)#message object is created
        run = run_manager.create_run(thread_id=thread['id'], assistant_id='fake_id')#assistant is run on message from user

I run this same code in my Flask app and the status gets stuck in ‘queued’ but running in notebook it completes automatically. I’m using the same string for the content variable. Thanks in advance for your help:)

I’m using it with curl in php and have the same problem (I think, not really a coder). But according to my log the last entry is always in_progress.
“status”:“queued”, …
and a second later “status”:“in_progress”, … nothing after that.

I am experiencing this issue as well, started this morning

I am also experiencing this issue calling via python. As others have said the playground still works fine. This began for me as I was integrating Functions calls. It looks like all of my previous runs have the “expired” status.

The topic has been pinned globally to enhance its visibility and encourage users to provide specific details when encountering the issue. Rather than ‘me too’ responses lacking specifics, the focus is on gathering valuable information. Although the problem has been addressed, there seem to be lingering corner cases.

The pinned status will expire on Thursday. However, if the community can contribute enough specific information, there is hope that the root cause(s) can be identified and resolved. It’s essential to remember that many employees will be intermittently unavailable over the next few weeks for holidays and vacation time.

Note: I am not an OpenAI employee but a user with the privilege to pin topics.

Seeing the same issue today, Dec 19 at around 12:00 pm EST. Assistant API is very slow - it’s between 1-2 minutes to return a response.

Thanks.

You noted slow but the topic is about being stuck.

For others who posted, can you clarify that stuck means it never gets out of the queue and slow should not be considered for this problem.

Am also facing the issue, unable to get out of the queue. code snippet below:

run = client.beta.threads.runs.create(
        thread_id=thread.id,
        assistant_id=assistant.id
    )
    while run.status != "completed":
        print(f'run status: {run}')
        
        if run.status == "completed":
            print("\n")
            break

similar issue - for some reason I cannot fathom, the first run to the thread completes almost instantaneously but a second remains queued forever with no status or usage update, even though the thread shows that an answer was returned.

This is my code snippet—

while run.status == "queued" or run.status == "in_progress":
        print(run.status)
        run = client.beta.threads.runs.retrieve(
            thread_id=thread.id,
            run_id=run.id,
        )
        time.sleep(5)

Here after printing 5/6 times “in_progress” it is getting stuck there only without returning any error or any movement of the code.
But in the GUI of thread, it can be seen that the correct response is being generated.

1 Like