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

client.images.generate is not generating images

Open NeillGiraldo opened this issue 1 year ago • 4 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

I am not able to generate images via the python library.

I have tried generating text and works perfectly fine. so I assume the problem is with the images module.

You can find the code in the next section.

and this is what I get when I do pip show openai

Name: openai Version: 1.75.0 Summary: The official Python library for the openai API Home-page: None Author: None Author-email: OpenAI [email protected] License: Apache-2.0 Location: {path-to-venv}/.venv/lib/python3.9/site-packages Requires: anyio, typing-extensions, tqdm, pydantic, distro, jiter, sniffio, httpx Required-by:

To Reproduce

  1. When I try to run the following code

from openai import OpenAI
import os

PROMPT = "People sitting outside in a warm european summer"
MODEL = "dall-e-3"  # Or "dall-e-2"

try:
    response = client.images.generate(
        model=MODEL,
        prompt=PROMPT,
        n=1,             # Number of images to generate (default is 1)
        size="1024x1024", # Size of the generated image (options vary by model)
        # quality="standard", # For dall-e-3, can be "standard" or "hd" (default is "standard")
        # style="vivid",     # For dall-e-3, can be "vivid" or "natural" (default is "vivid")
        # user="your-user-id", # Optional: For tracking purposes
    )
    image_url = response.data[0].url
    print(f"Generated image URL: {image_url}")

except Exception as e:
    print(f"An error occurred: {e}")
    if hasattr(e, 'response'):
        print(f"Full error response: {e.response.json()}")

  1. I get the following response

{'error': {'message': 'Error in request. Please check your input.', 'type': 'invalid_request_error', 'param': None, 'code': None}}

Code snippets


OS

macOS

Python version

Python v3.9.0

Library version

openai v1.75.0

NeillGiraldo avatar Apr 19 '25 13:04 NeillGiraldo

Seems to be an issue with the underlying OpenAI API, because I get the same error even with a curl request.

balazspiller avatar Apr 20 '25 20:04 balazspiller

I've experienced the same issue throughout the day as well. I agree with @balazspiller that this appears to be related to the endpoint itself. The prompt content did not always matter either. Following for updates.

zerfl avatar Apr 20 '25 22:04 zerfl

Same problem here. And sometimes, simple re-trying a few moments later works, sometimes not.

kongzii avatar Apr 23 '25 08:04 kongzii

Thanks for reporting!

I believe this should be resolved now but as it is an issue with the underlying OpenAI API and not the SDK, would you mind reposting at community.openai.com if you run into it again?

RobertCraigie avatar May 02 '25 00:05 RobertCraigie