#API ignoring 'image_url' and asks for base64 if timeout is specified

1 messages · Page 1 of 1 (latest)

outer ember
#

Hello,
I realized that for some reason, I'm getting 400 errors because API expected a base64-encoded data URL with image, even tho it is clearly a image_url.

Error code: 400 - {'error': {'message': "Invalid image URL: 'messages[1].content[1].image_url.url'. Expected a base64-encoded data URL with an image MIME type (e.g. 'data:image/png;base64,aW1nIGJ5dGVzIGhlcmU='), but got a value without the 'data:' prefix.", 'type': 'invalid_request_error', 'param': 'messages[1].content[1].image_url.url', 'code': 'invalid_value'}}```

```py
new_message = [
            {
                "type": "text",
                "text": new_message
            },
            *[{
                "type": "image_url",
                "image_url": {"url": img.link}
            } for img in additional_args['images_link']]
        ]```

I stream my response and it seems like sometimes it works, but then randomly it would stop and return a 400 error.
outer ember
#

I found the problem - and it is an issue from OpenAI's end.

this was how I was doing my requests:

response = await oclient.chat.completions.with_raw_response.create(
    model="gpt-4o",
    messages=messages,
    max_tokens=600,
    tools=tools,
    tool_choice="auto",
    timeout=openai.Timeout(60.0),
    stream=True
)```
Here, I added a timeout parameter, that exists in the OpenAI documentation, but messes with the images. timeout accepts either float or openai.Timeout, but both of them won't fix the issue, and cause issues with image_url. 
If this also happens to people, check that your max_tokens is an integer and not a string - because it apparently messes it up too.
So, this is a bug. Removing the timeout made it work correctly.