Select a Model
Prepare an Image Generation Request
Open a general-purpose application in the application list and click the copy button to the right of API KEY. Next, use this key to generate an image. If you use a restricted key, make sure it permits image generation; editing reference images also requires image editing permission.Generate Your First Image
Response JSON
The following excerpt from an existing Images response shows where the task ID, model, and image URL appear. The model you selected and the image address are determined by the values returned by this request.data[].url. To adjust the aspect ratio, quality, or output format, see the image generation guide. If you select the b64_json response format, decode the corresponding result according to the guide.
Edit a Reference Image
ReplaceYOUR_IMAGE_URL with an accessible reference image URL, then describe what you want to change.
Response JSON
The following excerpt from an existing Images response shows where the task ID, model, and image URL appear. The model you selected and the image address are determined by the values returned by this request.data[].url. See the image editing guide for input requirements for multiple images, masks, sizes, and formats.
Long-Running Tasks and Error Recovery
When you need an asynchronous approach, setasync=true according to the image API documentation and save the returned task ID. Use OpenAI task query to obtain the final result of the original task and avoid submitting it again while waiting. Handle authentication, balance, and parameter errors according to the error in the response, and retain the trace_id for troubleshooting.
See OpenAIAPI for complete call examples and access to more capabilities.
