400 Client Error - Running Threads

So I’ve been going back and forth through the forums for the past 2 weeks and still haven’t been able to solve my issue.

I’m trying to create an assistant using “Assistants API”, the message part works fine, but running a thread is a pain and always responds with “Error running the assistant: 400 Client Error: Bad Request for url:”

Here’s my code, after of course creating the assistant, the thread and the message:

Headers = {
    'Authorization': 'Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    'Content-Type': 'application/json',
    'OpenAI-Beta': 'assistants=v2'

Thread_Id = "thread_7hJY7anghFlp0qECNbpkaxWd"

#== Running The Assistant ==
Instructions = "Please address the user as James Bond"

Run_Url = f"v1/threads/{Thread_Id}/runs"

    Run_Response = Req.post(
        headers = Headers,
            "instructions": Instructions,
    Run = Run_Response.json()
except Req.exceptions.RequestException as e:
    Log.error(f"Error running the assistant: {e}")

I still get the same response if I use something like this:

    Run = Client.beta.threads.runs.create(
        thread_id = Thread_Id,
        assistant_id = Assistant_Id,
        instructions = Instructions,
except Exception as e:
    Log.error(f"Error Running The Assistant: {e}")

Hope this helps, and thanks in advance!

  1. If you are using the requests or httpx library, the content type does not need to be specified in the header. It will adapt to you using “json” or “files” in the POST.

  2. Secondly, instructions added to a run replaces existing instructions of an assistant, making what you programmed it with essentially useless.

  3. The URL doesn’t have the fully-qualified https:// and domain name.

The capitalization instead of snake_case is a headache.

I appreciate your response. I incorporated the aforementioned three points you pointed out, however the error still persists.

I’m getting the following response:

httpx:HTTP Request: GET
v1/threads/thread_14RSN1un4DtRd5Tm7CgB3E7a/messages “HTTP/1.1 200 OK”
ERROR:root:An Error Occurred While Retrieving The Run: ‘SyncCursorPage[Message]’

Which shows: {“error”:{“message”:“Missing bearer or basic authentication in header”,“type”:“invalid_request_error”,“param”:null,“code”:null}}

“missing authentication” - are you still using the header with your API key in every API call?

Are you polling, checking the status of the run, and then watching to see if the AI invoked one of you assistants’ tools. A “requires action” status for needing a tool return would be present, with the tool call, instead of a “download your response message” status.