Sorry if this has been asked somewhere, but I’ve been searching for an answer and haven’t found anything. I’m struggling to send assistant messages via the API. I’m following the documentation (for some reason it won’t let me post a link) but it’s not working. A summary of my problem:
First, I have an assistant id and a thread id – no problems creating those.
I try to create a message like this:
(Note: some values are replaced with [VARIABLE] for security/privacy reasons; spaces in the URL are only there because this site gets mad when I try to post a URL, they are not there in the actual code).
var endpoint = “https:// api.openai. com/v1/threads/[THREAD_ID]/messages/”;
var response = UrlFetchApp.fetch(endpoint, options);
Instead of creating and returning the new message, it gives me back an empty list of messages (this is the exact same response I receive when using “get” instead of “post”). As far as I can tell, no message is added to the thread.
I would first check the request using CURL and see that the output is correct with POST, use -v to get verbose output. Feed it the same HEADERS. API_KEY, thread_id etc…
Have you logged the HEADERS and USER_PROMPT and options to inspect what it is sending?
Okay, I figured it out! UrlFetchApp normally selects the “Content-Type” automatically; I’ve been letting it do that for most calls because specifying it explicitly was often breaking things. But it seems that in this case, not specifying was breaking it!
I simply added “Content-Type”:“application/json” to the headers and it seems to be working now. (Not sure what UrlFetchApp was using for the content type but evidently it was the wrong thing).
Thanks guys, your replies got me pointed in the right direction!