OpenAI Http 500 parsing error JSON

I’m experiencing the attached http 400 JSON parsing error when trying to send data to OpenAI. In my workflow I’m extracting data from a PDF which is happening successfully, but then I receive the attached error messages for certain PDFs, but not other PDFs. However, when I use this feature (chat with PDF) from my mobile device, I receive the error every time (with all PDFs).

I’m now using model gpt-4o, but this also happened with gpt-3.5-turbo.

Any help would be much appreciated!!

Here is how my API is setup for Chat Completions:

{
“model”: “”,
“messages”: [
{
“role”: “system”,
“content”: “You are a helpful assistant. You can understand and respond based on the content provided from a document.”
},
{
“role”: “system”,
“content”: “Document Content: <extracted_text_from_pdf>”
},
{
“role”: “user”,
“content”: “”
}
]
}

There seems to be an error in the quotes. " This is how they should look.

" :white_check_mark:

:x:

Can you provide the exact error?

Apologies - The error isn’t in the quotes. “” is between the quotes. Not sure why it didn’t past correctly. So this isn’t the issue. Thank you though.

My dynamic value for is between the last set of quotes, but it isn’t showing up in my post here. I tried editing and it still showing empty quotes. Hmmm

Do you see my attached error?
Screenshot 2024-05-14 at 2.22.56 PM

This can be an outdated library. The error message is not complete to confirm that.

As you said you receive the error message for certain PDFs and not others, it’s possible that you are not escaping the input.

{
“model”: “”,
“messages”: [
{
“role”: “system”,
“content”: “You are a helpful assistant. You can understand and respond based on the content provided from a document.”
},
{
“role”: “system”,
“content”: “Document Content: <extracted_text_from_pdf which might contain " >”
},
{
“role”: “user”,
“content”: “”
}
]
}

Or you can try structuring it like this:

curl https://api.openai.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
  "model": "gpt-4o",
  "messages": [
    {
      "role": "system",
      "content": [
        {
          "type": "text",
          "text": "You are a helpful assistant. You can understand and respond based on the content provided from a document."
        }
      ]
    },
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "Hi"
        }
      ]
    }
  ],
  "temperature": 1,
  "max_tokens": 256,
  "top_p": 1,
  "frequency_penalty": 0,
  "presence_penalty": 0

}'