Invalid_image error with base64

I am using gpt-4o + gpt-4o-mini, with the nodejs openai package, and getting this error…

{
  error: {
    message: 'Invalid image.',
    type: 'invalid_request_error',
    param: null,
    code: 'invalid_image'
  },
  code: 'invalid_image',
  param: null,
  type: 'invalid_request_error'
}

…using this implementation.

      await openai.chat.completions.create({
        model,
        messages: [
          { role: "system", content: systemContent },
          {
            role: "user",
            content: [
              { type: "text", text: prompt },
              { type: "image_url", image_url: { url: base64ImageString } },
            ],
          },
        ],
      });

i know that i am sending a base64 string because I’ve viewed it in the console, and I’m using the same string with Claude and there’s no problems. I have successfully sent a base64 image string to gpt-4o with the same implementation above but using a different method to make the base64 image string.

the error message looks like it’s not getting the base64 string; param: null

What am I doing wrong?
Please help.
Thank you.

my current base64 creation solution is stripping data:image/png;base64, off the front of the string. after manually adding it, all is good for both models…

and now i feel like an idiot but maybe someone else will find this to be helpful…

also, the error message could be a little more clear or something in the docs about requiring data:image/png;base64, at the front of the string cuz some base64 solutions don’t have that. i appreciate all the work on this stuff, just a suggestion.

1 Like