GPT-4 Vision API Node.js Error

Hi @Nikoldigital ,
the error message alludes to an error in the composition of the payload, in particular the ‘content’ keys.
‘content’ keys are objects, not strings. In your constant ‘payload’, ‘content’ keys are simple strings, such as:

"content": "Analyze the garment sketch and provide a description."

or

"content": "data:${mimeType};base64,${base64Image}"

But they must be something like that:

"content": [
  {              
    "type": "text",                                               
    "text": "Analyze the garment sketch and provide a description."
  }
]

and

"content": [
  {
    "type": "text",
    "text": "{USER_PROMPT_HERE}"
  },
  {
    "image_url": {
      "url": "data:image/jpeg;base64,{BASE64_IMAGE_DATA_HERE}",
      "detail": "high"
    },
    "type": "image_url"
  }
]

My examples are json objects, but you can apply them to javascript objects, as well.

This is a complete structure of a working json payload:

{                     
  "messages": [
    {
      "content": [
        {
          "type": "text",
          "text": "Analyze the garment sketch and provide a description."
        } 
      ], 
      "role": "system"  
    },                                                               
    {                       
      "content": [
        {                    
          "type": "text",
          "text": "{USER_PROMPT_HERE_IF_ANY}"
        },
        {
          "image_url": {
            "url": "data:${mimeType};base64,${base64Image}",
            "detail": "{high/low IS_YOUR_CHOICE_SEE_API_DOCS}"
          },
          "type": "image_url"
        }                                                               
      ],
      "role": "user"
    }
  ],                                                                                                                                                                    
  "model": "gpt-4-vision-preview",
  "max_tokens": 3500
}

Hope it’s help.
Ciao

2 Likes