GPT-4o Error: Image URLs in System Messages

Hi everyone,

I’m encountering an error when using GPT-4o that I haven’t run into with GPT-4-turbo. When I switched over, I got this error:

Error code: 400 - {‘error’: {‘message’: “Invalid ‘messages[4]’. Image URLs are only allowed for messages with role ‘user’, but this message with role ‘system’ contains an image URL.”, ‘type’: ‘invalid_request_error’, ‘param’: ‘messages[4]’, ‘code’: ‘invalid_value’}}

Seems like GPT-4o doesn’t allow image URLs in system messages, while GPT-4-turbo doesn’t have a problem with it. Are there any workarounds for this, or plans to update GPT-4o to allow images in system messages?

Thanks for any help or info!

2 Likes

In the API reference, you can see what is allowed to be in a system role:

Untitled

This is the endpoint validation - content is a string, not an array of things. Keep on expanding “user” and you see the image format you can send.

https://platform.openai.com/docs/api-reference/chat/create#chat-create-messages

Thanks for pointing that out!

I’ll review the documentation further to ensure I’m following the correct format.

So then assistant / system cannot pass in imageURLs? However according to gpt-4o vision documentation: " Images can be passed in the user , system and assistant messages" https://platform.openai.com/docs/guides/vision

see my question (unsolved) here: GPT-4o API bug: Can't take in image_url from assistant in messages, only user

I have the same problem for my app on anvil.works. I create a url and feed it but gives the same error. It error out every so often and sometimes it works.

Super strange

My solution was to transition from using a SystemMessage to HumanMessage:

Old

        if image:
            url = f"data:image/jpeg;base64,{image}"
            new_msg = SystemMessage(content=[{'type':'image_url', "image_url": {'url': url}}])
            messages.append(new_msg)
            logger.info("Image found in request, adding to messages.")

New

        if image:
            url = f"data:image/jpeg;base64,{image}"
            new_msg = HumanMessage(content=[{'type':'image_url', "image_url": {'url': url}}])
            messages.append(new_msg)
            logger.info("Image found in request, adding to messages.")