Forum Academy Marketplace Showcase Pricing Features

OpenAI - We could not phase the JSON body of your request

Hi i’m trying to build a API call from openAI to sometime i get an error this error

There was an issue setting up your call.
Raw response for the API
Status code 400
{
“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 OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please send an email to [email protected] and include any relevant code you’d like help with.)”,
“type”: “invalid_request_error”,
“param”: null,
“code”: null
}
}

my API call is the following

{
“model”: “text-davinci-003”,
“prompt”: “Q: can you explain to me this excel \n =INDEX(A1:D10, MATCH(“maximum”, A1:D10, 0), MATCH(“January”, A1:D1, 0)) \n”,
“temperature”: 0.22,
“max_tokens”: 500,
“top_p”: 1,
“frequency_penalty”: 0,
“presence_penalty”: 0
}

where is bold is the dynamic value, to be notice is that if run the call with an other dynamic value

{
“model”: “text-davinci-003”,
“prompt”: “Q: can you explain to me this excel \n =SUM(A1:A2) \n”,
“temperature”: 0.22,
“max_tokens”: 500,
“top_p”: 1,
“frequency_penalty”: 0,
“presence_penalty”: 0
}

the call works.

any tip?

i suspect that the quote like “maximum” is acausing the problem however, i should like to not get read of it. is there any way i can set the dynamic value as text so it does not get mess up witht the JSON?

When you’re doing the API call action and filling in the parameter values, add :formatted as JSON safe after your input’s value

+1 to this.

I’ve noticed it only happens when I submit a dynamic value, I tried the ‘:formatted as JSON safe’, no joy :no_mouth:

Also, it all worked perfectly fine yesterday, only an issue today :man_shrugging:

The way i solved it was to change automatically the input from “maximium” to /“maximium/”

Nice, for whoever it might help, my issue was slightly different; I was parsing user generated text and sometimes that text would contain special characters, prompting the error. I’ve simply added a ‘find & replace’ function to remove those when they appear & now it’s working

The issue here could be a character that was not escaped. I have noticed that format as JSON safe only works if the request field is actual non formatted

Plugin builder often pre-define the double quote to make is easier for the user to send text, this not requiring then to properly format the data as a string

Try searching for and escaping all non JSON chars, or create your own API call that does not assume the data is text