How to generate multiple images at once using Azure OpenAI's DALLE

Seah Bryan 40 Reputation points
2024-11-21T04:50:36.1166667+00:00

Hi everyone, I am currently have a DALL-E 3 model deployed in Azure OpenAI, and I am using Python to access the model. However, when I try to increase the number of generations per call, using the 'n' parameter, it returns the following error:

Failed with Exception: Error code: 400 - {'error': {'code': 'invalidPayload', 'message': 'You must provide n=1 for this model.', 'type': 'invalid_request_error'}}

This is my code:

from openai import AzureOpenAI

client = AzureOpenAI(
           api_version="2024-05-01-preview",
           azure_endpoint="*****",
           api_key="**********"
         )

result = client.images.generate(
           model="dall-e-3",
           prompt="Create an image of a sunset",
           size='1024x1792',
           response_format="url",
           n=2
         )

I'd greatly appreciate any insight into why this occurs. Thanks!

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
3,404 questions
{count} votes

Accepted answer
  1. santoshkc 10,870 Reputation points Microsoft Vendor
    2024-11-21T10:28:41.3333333+00:00

    Hi @Seah Bryan,

    Thank you for reaching out to Microsoft Q&A forum!

    With DALL-E 3, you can't generate more than one image in a single API call: the n parameter must be set to 1. If you need to generate multiple images at once, make parallel requests. While this is the current limitation, Microsoft might improve this in the future to allow generating multiple images in a single request, enhancing efficiency and user experience.

    For more info: Dalle3_parameters.

    I hope you understand! Thank you.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.