I have managed to connect successfully with OpenAI API and managed to post a prompt. However, starting with today, without me making any changes, I am getting this error which I have no idea how to fix. I’ve tried rewriting the API call, validated the JSON script, tested each dynamic variable of the script, change6my secret key, etc… nothing worked,
Is there any change in the API connector or on OpenAI side?
***.bubbleapps.io says
The service OpenAl - OpenAl Gift Idea just
returned an error (HTTP 400). Please consult
their documentation to ensure your call is setup
properly. Raw error:
f
"error":
"message" "We could not
parse the JSON body of your request. (HINT:
This likely means you aren't using your
HTTP library correctly. The OpenAl API expects a
JSON payload, but what was sent was not valid
JSON. If you have trouble figuring out how to fix
this, please contact us through our help center at help.openai.com.)"
"type"
"invalid_request_error"
"param": null,
OK
Your messages parameter should look like {“role”: “user”, “content”: }
Where prompt is Arbitrary text:formatted as JSON-safe. That guarantees the formatting is safe every time. If you’re using :find and replace to ensure JSON safety in API calls, you’re doing it wrong and making life harder for yourself than it needs to be!
Unfortunately the issue still persists even when using :formatted as JSON-safe, which is why I tried getting a bit more granular by going through multiple find and replace modifiers.
Okay slight update - I’ve now added the dynamic data to the Workflow, rather than relying on dynamic data insertion in the API call itself.
I’m still getting the issue because it looks like when the dynamic text is inserted, it’s wrapping the text in “”, even when selecting :formatted as JSON-safe.
Formatted as JSON safe, this will return “Tell me a joke”.
That will work in our API call.
Now suppose we submit an empty prompt. Formatted as JSON-safe will return “”. That means that no matter what our prompt is, it is always, without fail, absolutely JSON-safe. Any API call that uses a user input should be formatted as JSON safe.
In the API connector, it looks like “content”: - as opposed to “content”: “”.
Ah sorry I should have explained - the dynamic text is within static text.
Specifically, the body of the prompt looks like this right now:
“content”: “Produce a brief. The user has selected the copywriting style as {Selected Copy Style:formatted as JSON-safe}. Ensure your response is provided in Mark Down.”
The curly braces aren’t present in the actual workflow, I’ve just used them here to demonstrate where the dynamic data is being inserted
So for example, the prompt being sent is:
“content”: “Produce a brief. The user has selected the copywriting style as “Marketing Email”. Ensure your response is provided in Mark Down.”
Your entire prompt should be in the API connector.
Then, in the API call action, Arbitrary text:formatted as JSON safe.
Then, inside Arbitrary text:
Produce a brief. The user has selected the copywriting style as {Selected Copy Style}. Ensure your response is provided in Mark Down.
:formatted as JSON safe should be applied last, not in the middle of the API call. This will format the entire prompt as JSON safe.
Using Arbitrary text:formatted as JSON-safe essentially gives you a text input where you can put anything without needing any other format as JSON safe / find and replace.
Right, my apologies I think I’m with you now, but I’d just like to clarify a few points:
Is Arbitrary Text:formatted as JSON-safe the entire content for the API call action - then within Arbitrary text I just insert the static and dynamic text for my prompt?
Do I need to include a key-value pair in the API connector for the Arbitrary text?
So sorry for all the questions, your help is so appreciated!
Depends if you’re sending conversation history or not. If it’s just a single turn API call with a system prompt and user message, then preformat it like that in the API Connector with system prompt / user prompt messages in the messages array. Else, have a <messages> parameter and you can add the relevant messages.
Also I realise some of my <prompt> have been hidden by the forum (probably thinks it’s formatting) which might make some of my replies read confusingly.
Okay thank you so much. Yeah this is just a single API call.
I just used Arbitrary text:formatted as JSON-safe for the “content” part in the API action (Workflows page).
This is what was sent to the API:
{
“model”: “gpt-4o-2024-08-06”,
“max_tokens”: 400,
“messages”: [
{
“role”: “system”,
“content”: “You are Pen Affleck, a marketing coordinator. Your task is to create a copywriting brief based on one of eight styles: Social Media Caption, Social Media Post, Blog, Marketing Email, YouTube Script, Product Description, Sales Ad, or Random. Tailor the brief to the selected style and ensure the tone of voice matches the style and context. Example: For a trendy company launching new sneakers, a marketing email might be light-hearted and fun, like: ‘Hey! We need an email for our new running sneakers! They’re breathable, lightweight, and available in five colours. Launch price: $39.99 with 20% off!’”
},
{
“role”: “user”,
“content”: “Produce a brief. Your response should be as if it were the message from you (the marketing coordinator) to the copywriter, do not address the request for the brief. The user has selected the copywriting style as Marketing Email. Ensure your response is provided in Mark Down and keep it fairly short.”
}
]
}
Unfortunately I’m still getting the same error, but as far as I can see, this should be JSON safe?
I’ve attached the body shown in the API connector and the Action on the workflows page. Am I doing something really dumb here? haha