I’m attempting to generate an image using dall-e-2
via the OpenAI Python SDK. My code is as follows:
from openai import OpenAI
client = OpenAI(api_key=“sk-…”)
result = client.images.generate(
model=“dall-e-2”,
prompt=“generate a white siamese cat”,
size=“1024x1024”,
n=1,
)
print(result.data[0].url)
However, I consistently get this error:
openai.PermissionDeniedError: Error code: 403 - {
'error': {
'message': None,
'type': 'image_generation_user_error',
'param': None,
'code': None
}
}
Is dall-e-2 still supported in the latest OpenAI Python SDK (openai>=1.x)? Or is it restricted to specific users/projects?
Any help or clarification on access limitations would be appreciated.
Hello @Vijaya_Lakshmi,
Welcome to the community! You can try this working code with the latest OpenAI Python SDK:
from openai import OpenAI
client = OpenAI(api_key= "your-key")
result = client.images.generate(
model="dall-e-2",
prompt="generate a white siamese cat",
size="1024x1024",
n=1,
)
print(result.data[0].url)
This works correctly with both openai 1.91.0 & 1.87.0 versions
.
Image Result:
Thank you @Innovatix
But,I have tried using both versions of the OpenAI SDK, but the issue remains unresolved.
As you can see in my settings, I do have access to DALL·E 2:
Here is the code I used to list the available models:
from openai import OpenAI
client = OpenAI(api_key=“”)
models = client.models.list()
print([model.id for model in models.data])
And this is the output I got, which only shows dall-e-3
:
PS D:\projects\vijayalakshmi.y_2308\vijayalakshmi.y_2308\dalle sample> python q.py
[‘dall-e-3’]
PS D:\projects\vijayalakshmi.y_2308\vijayalakshmi.y_2308\dalle sample>
Can you please help me resolve this issue or let me know if there’s any additional setup required to use dall-e-2
?