Application Process
To use the OpenAI Images Generations API, you can first visit the OpenAI Images Generations API page and click the “Acquire” button to obtain the credentials needed for the request:
If you are not logged in or registered, you will be automatically redirected to the login page inviting you to register and log in. After logging in or registering, you will be automatically returned to the current page.
Upon your first application, there will be a free quota provided, allowing you to use the API for free.
Basic Usage
Next, you can fill in the corresponding content on the interface, as shown in the figure:
authorization, which can be selected directly from the dropdown list. The other parameter is model, which is the category of the OpenAI DALL-E model we choose to use; here we mainly have one model, and details can be found in the models we provide. The last parameter is prompt, which is the input for the image generation prompt.
You can also notice that there is corresponding code generation on the right side; you can copy the code to run directly or click the “Try” button for testing.

created, the ID generated for this image generation, used to uniquely identify this task.data, which contains the result information of the image generation.
data includes the specific information of the model-generated image, and the url inside it is the detailed link to the generated image, as shown in the figure.

Image Quality Parameter quality
Next, we will introduce how to set some detailed parameters for the image generation results, among which the image quality parameter quality includes two types: the first standard indicates generating standard images, and the other hd indicates that the created image has finer details and greater consistency.
Below, we set the image quality parameter to standard, with specific settings as shown in the figure:


standard as shown in the figure:

hd can yield the image shown in the figure below:

hd have finer details and greater consistency compared to those generated with standard.
Image Size Parameter size
We can also set the size of the generated images, and we can make the following settings.
The size of the image is set to 1024 * 1024, and the specific settings are shown in the figure below:


1024 * 1024, as shown in the figure below:

1792 * 1024, we can obtain the image shown below:
It can be seen that the image sizes are obviously different. Additionally, more sizes can be set; for detailed information, please refer to our official documentation.
Image Style Parameter style
The image style parameter style includes two parameters. The first one, vivid, indicates that the generated image is more vivid, while the second one, natural, indicates that the generated image is more natural.
The image style parameter is set to vivid, and the specific settings are shown in the figure below:


vivid is shown in the figure below:

natural, we can obtain the image shown below:

vivid is more vivid and realistic than that with natural.
Image Link Format Parameter response_format
The last image link format parameter response_format also has two types. The first type, b64_json, encodes the image link in Base64, while the second type, url, is a regular image link that can be viewed directly.
The image link format parameter is set to url, and the specific settings are shown in the figure below:


url of the generated image is Image URL which can be accessed directly, and the image content is shown below:

b64_json, you can obtain the Base64 encoded image link, with the specific result shown below:
Asynchronous Callback
Due to the potentially long time taken by the OpenAI Images Generations API to generate images, if the API does not respond for a long time, the HTTP request will keep the connection open, leading to additional system resource consumption. Therefore, this API also provides support for asynchronous callbacks. The overall process is: when the client initiates a request, an additionalcallback_url field is specified. After the client initiates the API request, the API will immediately return a result containing a task_id field, representing the current task ID. When the task is completed, the generated image result will be sent to the client-specified callback_url in POST JSON format, which also includes the task_id field, allowing the task result to be associated by ID.
Let’s understand how to operate specifically through an example.
First, the Webhook callback is a service that can receive HTTP requests, and developers should replace it with the URL of their own HTTP server. For demonstration purposes, a public Webhook sample site https://webhook.site/ is used, and opening this site will provide a Webhook URL, as shown in the image:
Copy this URL, and it can be used as a Webhook. The sample here is https://webhook.site/3d32690d-6780-4187-a65c-870061e8c8ab.
Next, we can set the callback_url field to the above Webhook URL, while filling in the corresponding parameters, as shown in the following code:
task_id field, and the data field includes the same image generation result as the synchronous call, allowing the task to be associated through the task_id field.
Error Handling
When calling the API, if an error occurs, the API will return the corresponding error code and message. For example:400 token_mismatched: Bad request, possibly due to missing or invalid parameters.400 api_not_implemented: Bad request, possibly due to missing or invalid parameters.401 invalid_token: Unauthorized, invalid or missing authorization token.429 too_many_requests: Too many requests, you have exceeded the rate limit.500 api_error: Internal server error, something went wrong on the server.

