openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

Vision example throws an error

Open gee-gendo opened this issue 1 month ago • 0 comments

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • [x] This is an issue with the Python library

Describe the bug

The script from the readme throws a 400 error

openai.BadRequestError: Error code: 400 - {'error': {'message': 'Error while downloading https://upload.wikimedia.org/wikipedia/commons/thumb/d/d5/2023_06_08_Raccoon1.jpg/1599px-2023_06_08_Raccoon1.jpg.', 'type': 'invalid_request_error', 'param': 'url', 'code': 'invalid_value'}}

I believe the image might be too big?

Note: This may just be a docs issue

To Reproduce

  1. Run the readme script for vision
  2. See the error

Code snippets

# Running the following script from the readme 

import os
from openai import OpenAI

client = OpenAI(
    # This is the default and can be omitted
    api_key=os.environ.get("OPENAI_API_KEY"),
)

prompt = "What is in this image?"
img_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d5/2023_06_08_Raccoon1.jpg/1599px-2023_06_08_Raccoon1.jpg"

response = client.responses.create(
    model="gpt-4o-mini",
    input=[
        {
            "role": "user",
            "content": [
                {"type": "input_text", "text": prompt},
                {"type": "input_image", "image_url": f"{img_url}"},
            ],
        }
    ],
)


# throws 
openai.BadRequestError: Error code: 400 - {'error': {'message': 'Error while downloading https://upload.wikimedia.org/wikipedia/commons/thumb/d/d5/2023_06_08_Raccoon1.jpg/1599px-2023_06_08_Raccoon1.jpg.', 'type': 'invalid_request_error', 'param': 'url', 'code': 'invalid_value'}}

OS

macOS

Python version

Python v3.12.11

Library version

openai v2.8.1

gee-gendo avatar Dec 11 '25 11:12 gee-gendo