400 invalid image Bad Request Error in create completion

I am making a chatbot. On receiving image inputs from the user, the image is uploaded to a public supabase storage bucket ( there are no restrictions on image access), then the image URL is retrieved and the url is used as a parameter send to the chat completion endpoint. I am using the gpt-4o-turbo model. When I send a dynamically generated URL like this I get an error: Error in createCompletion: BadRequestError: 400 Invalid image.

However if I take this exact same URL that caused the bad request and hardcode it as a parameter, I get a valid response.

Why is this happening? The URL strings are the exact same. I even added a long delay between the URL creation and the calling of the API, so that is not the issue. I have also checked that the dynamically generated URL is a string as well.
The types of the URL are the same.
The image size is very small so token size is not an issue either.
It is also a JPG image so image type should not be an issue too.
The bucket is public so access to the image should not be an issue either, if access permissions was the problem then I would get invalid responses when I hardcoded the URL too.

These are the request parameters with the dynamically generated URL that gave an invalid response:

Prepared userMessage: {
  "role": "user",
  "content": [
    {
      "type": "text",
      "text": "what is this"
    },
    {
      "type": "image_url",
      "image_url": {
        "url": "https://bucketId.supabase.co/storage/v1/object/public/chat-images/imageId.jpg"
      }
    }
  ]
}

And this is the request parameters with the hardcoded URL that gave a valid response:

Prepared userMessage: {
  "role": "user",
  "content": [
    {
      "type": "text",
      "text": "what is this"
    },
    {
      "type": "image_url",
      "image_url": {
        "url": "https://bucketId.supabase.co/storage/v1/object/public/chat-images/imageId.jpg"
      }
    }
  ]
}

Would appreciate any help :slight_smile: Can dm the image URL as well

1 Like

Up!
Got the same exact problem. But with the gpt-o model.
Also uploading to supabase in an open Bucket.

Does it work sometimes or does it not work at all?

I got the invalid image Message only occasionaly (with the same uploaded images).

@carnilogic It does not work at all. Was there anything in common in the images that it worked with?

when putting your code in https://jsonformatter.curiousconcept.com/# it gives an error.

After some diggin it could also be because of formatting in this forum.

@carnilogic I’ve removed the actual ids from this url and just kept placeholders like imageUrl