GPT4 Vision error when passing GCP Storage Bucket URL

Hi,

I am getting a not-so-verbose error saying my image is invalid. My workflow includes uploading images to the GCP storage bucket and using those URLs in the prompt. The png images are public but I’m not sure why OpenAI is not taking them in.

Error: BadRequestError: Error code: 400 - {'error': {'message': 'Invalid image.', 'type': 'invalid_request_error', 'param': None, 'code': None}}

Here is a sample URL that is not working.

client = OpenAI()

response = client.chat.completions.create(
    model="gpt-4-vision-preview",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "Describe the image."},
                {
            "type": "image_url",
            "image_url": {
              "url": "https://storage.googleapis.com/image-save-bucket/a9f3706e66452b08f9f6ae93a6d1a6b2cdnbubbleiof1704802072614x356122042160301950take_0.png"
            }
          }
            ],
        }
    ],
    max_tokens=1500,
)

Hi and welcome to the Developer Forum!

Best way to avoid this kind of issue is to download the image locally and then send it to the API in base64 encoded format. That way you have control over checking the image for validity within your own code and you will be assured of a valid image being sent to the model.

Unfortunately, we’re using Bubble io no/low code tool for the UI with limited code functionality. Are there any permissions that I’m missing for the image? The image URL is public and I couldn’t find anything about why this is failing.

No, it’s just that internet hosting images services can restrict access whenever they wish, I’ve seen more than a few people mention that pointing the bot at remote sites has been problematic. The solution is to host locally and upload in base64. I think that bubble does allow javascript functions to run by making use of the toolbox plugin, perhaps that is an avenue for you to investigate.

Unfortunately, no-code system are often more work than actually coding in python or java.

Agreed that no-code will increase the overall work. The toolbox plugin doesn’t seem to support the libraries (or any libraries for that matter) that will be needed.

PNG was a hit or miss on GCP Cloud storage. Using JPEG solved it. Sample URL with JPEG: https://storage.googleapis.com/image-save-bucket/a9f3706e66452b08f9f6ae93a6d1a6b2cdnbubbleiof1704802072614x356122042160301950take_1_temp.jpg