POST
/v1/images/generationsGenerate images from text prompts
Creates a high-quality image from a text prompt using GPT-IMAGE-1, the latest image generation model with automatic prompt optimization and enhanced visual capabilities.
- IdempotentThe SDK sends
Idempotency-Key, so a retried request is only applied once.
promptstringrequired
A text description of the desired image(s). Supports up to 32,000 characters and provides automatic prompt optimization for best results.
modelstringrequired
The model to use for image generation.
moderationstringoptional
The moderation setting for the image generation. Supported values: low, auto.
backgroundstringoptional
The background setting for the image generation. Supported values: transparent, opaque, auto.
output_formatstringoptional
The output format for the image generation. Supported values: png, webp, jpeg.
output_compressionintegeroptional
The output compression level for the image generation (0-100).
nintegerrequired
The number of images to generate. Must be between 1 and 10.
qualitystringoptional
The quality of the image that will be generated. Supported values: auto, high, medium, low.
sizestringoptional
The size of the generated images. GPT-IMAGE-1 supports: auto (automatically select best size), 1536x1024 (landscape), 1024x1536 (portrait).
streambooleanoptional
If set to true, partial image data will be streamed as the image is being generated. The response will be sent as server-sent events with partial image chunks. When stream is true, partial_images must be greater than 0.
partial_imagesintegeroptional
The number of partial image chunks to return during streaming generation. Defaults to 0. When stream=true, this must be greater than 0 to receive progressive updates of the image as it is being generated.
userstringoptional
A unique identifier representing your end-user, which can help DigitalOcean to monitor and detect abuse.
200Successful image generation. When stream is true, response is sent as Server-Sent Events (text/event-stream); otherwise a single JSON object (application/json) is returned.
createdintegerrequired
The Unix timestamp (in seconds) of when the images were created.
dataarray<object>required
The list of generated images.
backgroundstringoptional
The background setting used for the image generation.
output_formatstringoptional
The output format of the generated image.
qualitystringoptional
The quality setting used for the image generation.
sizestringoptional
The size of the generated image.
usageobjectoptional
Usage statistics for the image generation request.
401Authentication failed due to invalid credentials.
idstringrequired
A short identifier corresponding to the HTTP status code returned. For example, the ID for a response returning a 404 status code would be "not_found."
messagestringrequired
A message providing additional information about the error, including details to help resolve it when possible.
request_idstringoptional
Optionally, some endpoints may include a request ID that should be provided when reporting bugs or opening support tickets to help identify the issue.
429The API rate limit has been exceeded.
idstringrequired
A short identifier corresponding to the HTTP status code returned. For example, the ID for a response returning a 404 status code would be "not_found."
messagestringrequired
A message providing additional information about the error, including details to help resolve it when possible.
request_idstringoptional
Optionally, some endpoints may include a request ID that should be provided when reporting bugs or opening support tickets to help identify the issue.
500There was a server error.
idstringrequired
A short identifier corresponding to the HTTP status code returned. For example, the ID for a response returning a 404 status code would be "not_found."
messagestringrequired
A message providing additional information about the error, including details to help resolve it when possible.
request_idstringoptional
Optionally, some endpoints may include a request ID that should be provided when reporting bugs or opening support tickets to help identify the issue.
defaultThere was an unexpected error.
idstringrequired
A short identifier corresponding to the HTTP status code returned. For example, the ID for a response returning a 404 status code would be "not_found."
messagestringrequired
A message providing additional information about the error, including details to help resolve it when possible.
request_idstringoptional
Optionally, some endpoints may include a request ID that should be provided when reporting bugs or opening support tickets to help identify the issue.
Error handling
A 401 is returned: Authentication failed due to invalid credentials. A 429 is returned: The API rate limit has been exceeded. A 500 is returned: There was a server error. Any other status is an error: There was an unexpected error.