ChatGPT API give me an error when using "" in my prompt

When I send a prompt that has “quote” like that I keep getting an error that says the Json format is wrong.
I tried the Jason safe method, but that didn’t help either. What am I missing?

So here is how my setup looks


1 Like

Remove the double quotes from you setup and try to avoid spaces too. So it should look like this message_content

In bubble when using dynamic data format it as JSON-Safe

That should fix it

1 Like

For any API connector inputs that the user can specify (as opposed to dynamic data that is specified from an option set for example) should always be formatted as JSON-safe and not have quotes in the API Connector body. That makes it impossible for the user to input something that breaks the call.

Like this?


I’m still getting the same error, the moment I remove the quotes around “<message_content>” then it doesn’t even matter what else I do, I still get the same error, event if my prompt is a simple text prompt

Copy your JSON body into JSON Formatter & Validator and add " " around your variable then run the validator. If that’s valid, ensure you have Content-Type as application/json in the request header.

I found a fix

If that worked and :formatted as JSON-safe didn’t, then something else is wrong with your config (most likely the Content-Type header I showed you).

Your current method will break when the user uses line breaks/multiple paragraphs.

Does this look right?

No, because you’re missing a closing } at the end. You need to use formatted as JSON-safe to build a stable API call in this use case.

This will identify any issues with your JSON body. Just make sure you put " " around dynamic parameters just for this validation test (because Bubble will add these when you format your parameter as JSON safe.

Airdev has good guides for OpenAI: OpenAI - Functionality Reference

it’s weird that the closing bracket doesn’t show on that screenshot because it is in there.
I just used the JSON Formatter, here is what it gave back to me when I remove the " " around the variable.

Okay good. Now, remove the quotes around in Bubble (because Bubble will add these for us when we :format as JSON-safe). Take your multiline input, use that value:formatted as JSON-safe in the API call and you’re good to go. If it doesn’t work, the issue is that you don’t have the Content-Type header set to application/json.

ill test that, but I did set the header as you mentioned

Content-type shouldn’t be case sensitive (HTTP/1.1 specification) but maybe OpenAI API is weird → change to Content-Type if it doesn’t work. As far as I can tell, everything else about your call is fine.

Okay so I removed the " " around the variable.




Well that’s peculiar. Can you create a new workflow and action that’s run on a button press - all it should do is make the API call using the static text: “Say a test message” (including the quotes). Let me know if that returns an error.

I added a button
and it gave no errors

Now add a new input, replace “hi” with Input’s value formatted as JSON-safe. I think something in your old workflow is conflicting (do you have an earlier OpenAI action in that old workflow that’s running and isn’t formatted as JSON safe for example?). That’s why I’m suggesting to create a new workflow for debugging.

It worked
No errors