ChatGPT Error 400

My chatgpt api call fails when I try and test it. It works fine when initialising but it doesn’t work when I use it in my bubble app. I have attached a screenshot of what I have entered in the bubble api connector and my in app workflows.
![Screenshot 2023-10-01 at 21.36.31|690x431](upload://sd


I forgot to include this image

What is the error message, error code and error body of the failed API call?

In my apps, I create a data type called API-Fail where I save those details to debug issues. Likely in your case, your JSON formatting is wrong.

Hey, thanks for your response, this is the error I am getting

Hey, I used JSON safe in the workflow and it didn’t stop the error unfortunately. A photo of the JSON safe in the workflow is in the images above

This is not formatted as JSON safe:
CleanShot 2023-10-07 at 11.38.33@2x

You’ve got confused where you format as JSON safe. You format the keys (the message content) as JSON-safe. Not the entire JSON body.

{“key1”: “Example”} formatted as JSON-safe returns “{\”key1\”: \”Example\”} which is obviously not what you want.

So is it just the dynamic text I replace with Arbitrary text formatted as JSON safe?

Thanks for all your help so far!

I didn’t look at all the screen shots. I just read the error message which indicates it is not formatted as proper JSON.

I formatted everything as JSON safe and it returned the same error

Formatted everything JSON related as JSON safe - for clarity

The way you are formatting looks like it is incorrect.

You can verify this by taking the values generated through your setup and put them into a tool like JSON formatter (google search test JSON format) and see if there are errors in the formatting.

You have to save the “message content” as a JSON safe, not the complete string.

I guess the structure of the json should look like this:

[{"role": "user", "content": "Text1"},{"role": "assistant", "content": "output1"},{"role": "user", "content": "Text2"},{"role": "assistant", "content": "output2"},....]

But if you now do the json safe after the search the following happens with the sting above.

"[{"role\" \"user\", \"content\": \"Text1\"},{\"role\": \"assistant\", \"content\": \"output1\"},{\"role\": \"user\", \"content\": \"Text2\"},{\"role\": \"assistant\", \"content\": \"output2\"},....]"

The API cannot work with this and gives you the 400 error because of the incorrect structure.

Interesting, I am not a coder but I tried the workflows with no JSON safes before and it didn’t work either

Is this what you are suggesting?

It found no errors when I ran it

Can you save and show the input, which you send as prompt. A small example should be enough. That makes the analysis a bit easier :slight_smile:

1 Like

The text field is where the prompt is saved in the database. I can screen record myself as well if that would be helpful?