Image encoded in a chat using the OpenAI API

Hi, I’m trying to use the curl api to ask a question about an image. I encoded the image in Base64 and passed the result to the function’s cotent variable. But it doesn’t work and I get the error :

Bad Request
{
    "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
    }
}

Here’s my curl code:

curl https://api.openai.com/v1/chat/completions \N -H « Content-Type : application/json » \N
  -H « Content-Type : application/json » \N- -H « Authorization : a
  -H « Authorization : Bearer YOUR_API_KEY » \N- H
  -d '{
    « model » : « gpt-4o-mini »,
    « messages » : [
      {
        « role » : « utilisateur »,
        « contenu » : [
          {
            « type » : « texte »,
            « text » : « Qu'y a-t-il dans cette image ? »
          },
          {
            « type » : « image_url »,
            « image_url » : {
              « url » : « data:image/jpeg;base64,BASE64_ENCODED_IMAGE »
            }
          }
        ]
      }
    ]
  }'

What’s the problem?

1 Like

actually the issue is the format you have to make an json then you can pass to payload as open ai accepts json object