Open AI API http 400 error payload

I have been having this error
… just returned an error (HTTP 400). Please consult their documentation to ensure your call is setup properly. Raw error:

{
"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 contact us through our help center at help.openai.com.)",
"type": "invalid_request_error",
"param": null,
"code": null
}
}

But my json code is formatted as
{
“model”: “gpt-3.5-turbo”,
“messages”: [{“role”: “user”, “content”: “This is my essay, . You are an advanced AI essay grader, grade the essay below.”}]
}

I shortened my prompt here. Please where is the problem from?

Hi Marquis,

Your quotation marks, for some reason, are being considered symbols. So, making the changes (switching to the correct quotation marks), your code would look like this:

{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "This is my essay, . You are an advanced AI essay grader, grade the essay below."}]
}

If you encounter any issues, let me know! :slight_smile:

I tried that, but its still showing the same error

This is strange. Can you send me a full screenshot of your API connection screen?

Can you please take a look at it here?

I have included the screenshot.

Hi Marquis, I apologize for the delay of 6 days, I actually just received the notification of your message now.

Analyzing your screenshot, I can see that there is a JSON error.

it should actually be:

{
  "model": "gpt-3.5-turbo",
  "messages": [
    {
      "role": "user",
      "content": "This is my essay, <Essay>. You are an advanced AI essay grader designed to provide comprehensive feedback on each line of the essay provided below, while adhering to the highest standards of academic writing and critical analysis based on the NSW Year 12 English syllabus. Your task is to provide a thorough and detailed critical analysis of the essay, including specific referenced examples that can be improved to achieve full marks and an A+ grade. You will also be expected to score the whole essay using the NSW Year 12 English Marking rubric and give it a score out of 20, with a clear breakdown of how you arrived at that score. Please provide feedback on each line of the essay, identifying areas of strength and weakness, and providing suggestions on how to improve the essay's grammar themes, context, structure, coherence, and other relevant areas. Your should be extensive, thorough, and straightforward, and should not mention any limitations or apologize for being an AI model. Please respond in British English and refrain from using any colloquial or informal language. It is important that you discuss each line of the essay."
    }
  ]
}

Apparently, the “messages” object was defined as an object with keys, but the correct format should have been an array of objects. By applying the correction I showed, “messages” becomes an array with a single object containing the user’s information.

If you want to make the request more organized, you can follow a better path:

{
  "model": "gpt-3.5-turbo",
  "messages": [
    {
      "role": "user",
      "content": "Hi!"
    }
  ]
}

It is also important to note that you are fetching dynamic data when requesting <Essay>, which means there might be more issues there. Make sure that the dynamic data you are fetching with <Essay> does not contain quotation marks. If quotation marks are necessary, please use a :find & replace and change " to \"

1 Like

Very helpful. Thank you.