API does not support .webp URL

When I try to pass a .webp URL as an image input to the API, I get this error:

openai.BadRequestError: Error code: 400 - {'error': {'message': "You uploaded an unsupported image. Please make sure your image has of one the following formats: ['png', 'jpeg', 'gif', 'webp'].", 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_image_format'}}

The error message clearly says that webp is supported, but apparently it is not.

Here is the relevant part of the python code I’m using:

prompt = f"""
    Your task is to extract information related to vehicles and their prices, given an image representing a vehicle promotion.
    """
    request_content = [{"type": "text", "text": prompt}]
    request_content.extend([{
        "type": "image_url",
        "image_url": {
            "url": "<LINK THAT ENDS WITH .webp>"
        }
    }])
    
    completion = client.beta.chat.completions.parse(
        model="gpt-4o",
        messages=[
           {
               "role": "user",
               "content": request_content
           }
        ],
        response_format=CarList
    )

Note that the forum doesn’t let me paste the actual link I’m using, but I can assure you it’s a valid .webp image URL that is available for public access.

There’s many sites that will serve a web page for an image without a referrer.

Others that will block without a click-thru referrer from the site.

Others that will block the OpenAI retriever, by robots.txt or by their own rules.

A working webp:

    prompt = f"""
    Describe images with your built-in computer vision.
    """
    request_content = [{"type": "text", "text": prompt}]
    request_content.extend([{
        "type": "image_url",
        "image_url": {
            "url": "https://www.gstatic.com/webp/gallery/2.webp"
        }
    }])

A more entertaining way of making the API request:

with client.beta.chat.completions.stream(
    model="gpt-4o",
    messages=[{"role": "user", "content": request_content}],
    stream_options={"include_usage": True},
    max_completion_tokens=2000,  # openai.LengthFinishReasonError if JSON unparsable
    response_format=SimpleResponse,
) as stream:
    for event in stream:
        process_event(event)

It can see:

Content Delta Event:
{
  "type": "content.delta",
  "delta": "}",
  "snapshot": "{\"response\":\"The image depicts a person engaged in a water sport, possibly kayaking or rafting, as they navigate through turbulent water. The individual is wearing a helmet and a red life jacket, signifying safety precautions. Water splashes dramatically around them, creating a dynamic and exciting scene. The background suggests a natural setting, likely a river or a rapid, emphasizing the thrill of the activity.\"}",
  "parsed": {
    "response": "The image depicts a person engaged in a water sport, possibly kayaking or rafting, as they navigate through turbulent water. The individual is wearing a helmet and a red life jacket, signifying safety precautions. Water splashes dramatically around them, creating a dynamic and exciting scene. The background suggests a natural setting, likely a river or a rapid, emphasizing the thrill of the activity."
  }
}

If you are having remote image issues, I would download them yourself while collecting the user input, resize to your budget, send as base64 file.

1 Like

Thank you for your reply! I am writing a script that scrapes a dealership website’s images (which may or may not contain promotional details), and passes them to the API to retrieve the promotional details. This is where I am encountering the URL blocking issue.

Is there any way to circumvent that problem, or is the only option to programmatically download the images and send them to OpenAI as base64 files?

The OpenAI retriever is out of your control. There’s no retry except to make another API request and get another AI response, and sometimes it just doesn’t work.

A persistent downloader of your own can report problems to a user earlier, and you can use your own user-agent and referrer and the fact that you aren’t OpenAI on the cloud to get image resources more reliably.