Keep gettin 400 Bad Request at /threads/runs

While testing API with postman I keep getting “400 Bad Request”, although the same request worked from cURL console… I’m pretty sure it’s something stupid, but already lost 12 hours and cant seem to fix it…

Same request through postman… No deal.

Anyone could help?

A special header in your API call is required to use Assistants.

Then remember that what you show creates a new thread. To continue a conversation:

post https://api.openai.com/v1/threads/{thread_id}/runs

All the prerequisites to this run must exist.

1 Like

First, what are you trying to achieve? Are you Running the thread? Or retrieving the Run? The Endpoint you’re using is not something I’ve seen in documentation. Can you check if you’re using the correct one?

He is attempting the create thread and run method.

1 Like

Ohh, thanks for correcting me. I’ve never used the Thread and Run with single API hit.

Yup, I’m trying the “Create and Run” method. It worked through cURL console, but I can’t seem to find what I’m missing while using Postman.
My final goal is to integrate my agent to Instagram using ManyChat, witch, also, doesn’t work, replying the same 400 Bad Request error, as Postman

Are you passing this in the header?

"OpenAI-Beta: assistants=v2"

The accented character should be escaped UTF-8 bytes. Additionally, you can check for directional quotes, mismatched containers, remove all the white space such as linefeeds and possible tabs, and run the body through a JSON validator.

It seems I was missing the header “Host”, witch is not under the API Reference, although it worked since I’ve added… Could you guys enlighten me on why?

Host is used for virtual hosts. Example:

I may have a server web54.host-you-ai-apps-here.org. It has one external IP address.

My customers set up their own websites on my host, like superduper.ai or ratemygpt.biz.

When a request is sent to my server’s IP address, there’s no clue which virtual host it is meant for. I’ll just send back an error for api.superduper.ai.

The Host header is required.

Most libraries handle this header for you because it is almost mandatory on the modern web.

===

What the playground sends for headers to the API for chat completions:

Host: api.openai.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:125.0) Gecko/20100101 Firefox/125.0
Accept: text/event-stream
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: https://platform.openai.com/
Content-Type: application/json
Authorization: Bearer sess-0BH10qGiVu3ZlXGCA5iO1hEmxG9UhLOTEhD
OpenAI-Organization: org-iUA5iO18m7EzoS9eUrGCAxG9UhLOT
Content-Length: 275
Origin: https://platform.openai.com
Connection: keep-alive
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-site
Pragma: no-cache
Cache-Control: no-cache
TE: trailers
1 Like

Only using “v1” was the problem. After updating to v2 its started working.
“OpenAI-Beta: assistants=v2”

1 Like