Gpt-4-vision-preview not working - provided examples failing

The provided examples for gpt-4-vision-preview are failing. It’s acting like there are no images attached at all(even saying there are no images to look at).

Directly from the openai docs:

from openai import OpenAI

client = OpenAI()

response = client.chat.completions.create(
  model="gpt-4-vision-preview",
  messages=[
    {
      "role": "user",
      "content": [
        {"type": "text", "text": "What’s in this image?"},
        {
          "type": "image_url",
          "image_url": {
            "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
            "detail": "high"
          },
        },
      ],
    }
  ],
  max_tokens=300,
)

print(response.choices[0].message.content)

Anyone else seeing this?

Works fine at low or high. That URL, or another.

from openai import OpenAI
client = OpenAI()

response = client.chat.completions.with_raw_response.create(
  model="gpt-4-vision-preview",
  messages=[
    {
      "role": "user",
      "content": [
        {"type": "text", "text": "What’s in this image?"},
        {
          "type": "image_url",
          "image_url": {
            "url": "https://i.imgur.com/oeYzasc.jpeg",
            "detail": "high"
          },
        },
      ],
    }
  ],
  max_tokens=300,
)

print(response.http_response.text)
print(f"time: {response.elapsed.total_seconds():.2f}s")

You can look at the prompt_tokens count of the failed call to see if an image was included.

Having OpenAI retrieve the images can be less reliable than your own image retrieval. Providers may block known OpenAI IP addresses, or OpenAI may respect a robots.txt file. You can download yourself and then call, resized to control costs, by the base64 format, and then see any URL errors before calling the API instead of merely having a confused AI.

Also check Python is 3.8-3.11, and OpenAI library is recent (1.12+).

I’m getting the “server_error” message when using the same example as OP. “detail” does not work for me either.

I am using the official example, using get-4-vision to process an image, also has a error ‘openai.NotFoundError: Error code: 404 - {‘error’: {‘code’: ‘404’, ‘message’: ‘Resource not found’}}’
even if it works for text input.
Any insights?

Looks like you might be using the wrong model.

You can either use gpt-4-vision-preview or gpt-4-turbo - the latter now also has vision capabilities.

See also here and here for reference.

thanks for fast reply, i am using get-4-vision-preview in Azure OpenAI service. it should be the right model.

with "
client = AzureOpenAI(
api_key = api_key,
api_version = api_version,
azure_endpoint = api_base
)

response = client.chat.completions.create(
model=deployment_name, # model = “deployment_name”.
messages=[
{“role”: “system”, “content”: “Assistant is a large language model trained by OpenAI.”},
{“role”: “user”, “content”: “Who were the founders of Microsoft?”}
]
)

print(response)
print(response.model_dump_json(indent=2))
print(response.choices[0].message.content)
"
works well;

but with "
client = AzureOpenAI(
api_key=api_key,
api_version=api_version,
base_url=f"{api_base}openai/deployments/{deployment_name}/extensions",
)

response = client.chat.completions.create(
model=deployment_name,
messages=[
{ “role”: “system”, “content”: “You are a helpful assistant.” },
{ “role”: “user”, “content”: [
{
“type”: “text”,
“text”: “Describe this picture:”
},
{
“type”: “image_url”,
“image_url”: {
“url”: data_url
}
}
] }
],
max_tokens=2000
)
print(response.choices[0])
print(response.choices[0].message.content)
"
has the error 404.

The reason why I mentioned “wrong model” is that you refer to “get” vs “gpt”.
This points towards a possible spelling error.

i see, thanks for the reminding. hahah
now it works, i changed the api-version, the it worked. thanks a lot!

1 Like