Trying to pass a base64 encoded image with node

I’m trying to pass a base64 encoded image to gpt-4o, but gets an 400 Invalid base64 image_url.

I use the following code:

    const openairesponse = await openai.chat.completions.create({
    model: "gpt-4o",
    messages: [
      { role: 'system', content: "Convert the image to text" },
      {
      "role": "user",
      "content": [
        {
        "type": "image_url",
        "image_url": {
          //The base64 encoded image
          "url": "data:image/jpeg;base64,"+base64Image
        }
        }
      ]
      }
    ],
    });

The base64Image is s string starting with ‘/9j/’ and should be valid.

Any idea what I’m doing wrong?

/Mathias

Facing the same error, let me know if you have found a workaround or solution

Unfortunately haven’t found a solution yet.