GPT-4-Vision Preview is not working

I use gpt-4-vision and i get error 400:

My code:

response = client.chat.completions.create(
    model="gpt-4-vision-preview",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "Hello! What do you see?"},
                {"type": "image_url", "image_url": "url..."},
            ],
        }
    ],
    stream=False,
)

Error:
openai.BadRequestError: Error code: 400 - {‘error’: {‘message’: ‘[\n {\n “code”: “invalid_type”,\n “expected”: “string”,\n “received”: “array”,\n “path”: [\n “messages”,\n 1,\n “content”\n ],\n “message”: “Expected string, received array”\n }\n]’, ‘type’: ‘error’, ‘param’: None, ‘code’: None}}

You need to edit your code a bit in the image url part:

{
            "role": "user",
            "content": [
                {"type": "text", "text": "Hello! What do you see?"},
                {"type": "image_url", "image_url": { "url": "url..."}},
            ],
        }

See docs for reference

1 Like

Thanks! Your answer helped me