The vast digital landscape is continually shifting towards a more visual-centric approach, where images not only complement content but often drive engagement and understanding. Recognizing the potential of marrying AI with imagery, we present our Image Generator/Editor Service API. This groundbreaking service utilizes the prowess of OpenAI’s models, enabling a myriad of image-related tasks – from generating visuals based on textual descriptions to advanced image manipulation, setting the stage for a revolution in digital visualization.
OpenAI API key
, and Images folder
. The “Images folder” is a directory in the Backendless files storage of your app where the generated images will be stored. Enter the required details and click the Save button:The Images API provides three methods for interacting with images:
Creates new image(s) from a prompt. The more detailed the prompt, the more likely you are to get the result that you or your end user want.
Method:
POST
Endpoint URL:
https://xxxx.backendless.app/api/services/OpenAIImageService/createImage
The xxxx.backendless.app
is a subdomain assigned to your application. For more information, see the Client-side Setup section of the Backendless documentation.
Request Headers:
Content-Type:application/json
Request Body:
The request body must be a JSON object with the structure shown below:
{ "prompt": "string", "numberOfImages": 0, "responseFormat": "string", "size": "string", "user": "string" }
Parameters explanation:
prompt
– Required. A text description of the desired image(s). The more detailed the description, the more likely you are to get the result that you or your end user want. The maximum length is 1000 characters.numberOfImages
– Optional. The number of images to generate. Must be between 1 and 10. Default to 1. responseFormat
– Optional. The format in which the generated images are returned. Must be either url
or b64_json
.size
– Optional. The size of the generated images. Smaller sizes are faster to generate. Must be one of 256x256
, 512x512
, or 1024x1024
.user
– Optional. A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.Response Body:
Returns a list of generated images in the following format:
[ "https://image-url-1", "https://image-url-2", "https://image-url-3", ... ]
Example:
curl -X "POST" "https://xxx.backendless.app/api/services/OpenAIImageService/createImage" \ -H 'Content-Type: application/json' \ -H 'Accept: application/json' \ -d $'{ "prompt": "A cat in a hat", "numberOfImages": 1, "size": "512x512" }'
Response:
[ "https://oaidalleapiprodscus.blob.core.windows.net/private/…" ]
This method allows you to edit and extend an image by uploading a mask. The transparent areas of the mask indicate where the image should be edited, and the prompt should describe the full new image, not just the erased area. The uploaded image and mask must both be square PNG images less than 4MB in size and must have the same dimensions. The non-transparent areas of the mask are not used when generating the output, so they don’t necessarily need to match the original image.
Image: |
Mask: |
Prompt:
A flower field with a dinosaur in it. |
Result: |
Method:
POST
Endpoint URL:
https://xxxx.backendless.app/api/services/OpenAIImageService/createImageEdit
The xxxx.backendless.app
is a subdomain assigned to your application. For more information, see the Client-side Setup section of the Backendless documentation.
Request Headers:
Content-Type:application/json
Request Body:
The request body must be a JSON object with the structure shown below:
{ "imageUrl": "string", "prompt": "string", "maskUrl": "string", "numberOfImages": 1, "responseFormat": "string", "size": "string", "user": "string", "saveSourceImage": false, "saveSourceMask": false }
Parameters explanation:
imageUrl
– Required. Must be a URL for a valid PNG file, less than 4MB, and square. If maskUrl
is not provided, the image referenced by this parameter must have transparency, which will be used as the mask.prompt
– Required. A text description of the desired image(s). The maximum length is 1000 characters.maskUrl
– Optional. An additional image whose fully transparent areas (e.g. where alpha is zero) indicate where the image should be edited. Must be a valid PNG file, less than 4MB, and have the same dimensions as the image referenced in imageUrl
.numberOfImages
– Optional. The number of images to generate. Must be between 1 and 10. Default to 1.responseFormat
– Optional. The format in which the generated images are returned. Must be either url
or b64_json
. Default to url
.size
– Optional. The size of the generated images. Must be one of 256x256
, 512x512
, or 1024x1024
. Defaults to 1024x1024
.user
– Optional. A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.saveSourceImage
– Optional. When set to true
the source image is saved in the folder specified during the service installation. Defaults to false
.saveSourceMask
– Optional. When set to true
the source mask image is saved in the folder specified during the service installation. Defaults to false
.Response Body:
Returns a list of generated images in the following format:
[ "https://image-url-1", "https://image-url-2", "https://image-url-3", ... ]
Example:
curl -X "POST" "https://xxxx.backendless.app/api/services/OpenAIImageService/createImageEdit" \ -H 'Content-Type: application/json' \ -H 'Accept: application/json' \ -d $'{ "imageUrl": "https://www.backendless.us/api/files/images/flower-field-original.png", "maskUrl": "https://www.backendless.us/api/files/images/flower-field-mask.png", "prompt": "A flower field with Spiderman", "numberOfImages": 2 }'
Response:
[ "https://oaidalleapiprodscus.blob.core.windows.net/private/org-z8bpMZcyVDHPjjjJKbP5diyE/user-PsbPicpgJc4uG80brMQAF2uY/img-WYM4XLU002HTsC1Vnw98k3W5.png?st=2023-10-20T18%3A03%3A45Z&se=2023-10-20T20%3A03%3A45Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-10-20T09%3A07%3A40Z&ske=2023-10-21T09%3A07%3A40Z&sks=b&skv=2021-08-06&sig=NSp%2BurHvaGKifLGqw85aEl8diRGJU3RdF/9eDVZg3WU%3D" "https://oaidalleapiprodscus.blob.core.windows.net/private/org-z8bpMZcyVDHPjjjJKbP5diyE/user-PsbPicpgJc4uG80brMQAF2uY/img-E1n3wX87Vrwa4FEKOPxvOMr7.png?st=2023-10-20T18%3A03%3A44Z&se=2023-10-20T20%3A03%3A44Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-10-20T09%3A07%3A40Z&ske=2023-10-21T09%3A07%3A40Z&sks=b&skv=2021-08-06&sig=CtE3N7qim4%2B9cokgFOOf2DLHI50lQrzfoL1rR4NpGbE%3D" ]
Creates a variation of a given image.
Original Image: |
Variation 1: |
Variation 2: |
Method:
POST
Endpoint URL:
https://xxxx.backendless.app/api/services/OpenAIImageService/createImageVariation
The xxxx.backendless.app
is a subdomain assigned to your application. For more information, see the Client-side Setup section of the Backendless documentation.
Request Headers:
Content-Type:application/json
Request Body:
The request body must be a JSON object with the structure shown below:
{ "imageUrl": "string", "numberOfImages": 1, "responseFormat": "string", "size": "string", "user": "string", "saveSourceImage": "string" }
Parameters explanation:
imageUrl
– Required. Must be a link to the image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, and square.numberOfImages
– Optional. The number of images to generate. Must be between 1 and 10. Defaults to 1.responseFormat
– Optional. The format in which the generated images are returned. Must be either url
or b64_json
.size
– Optional. The size of the generated images. Must be one of 256x256
, 512x512
, or 1024x1024
. Defaults to 1024x1024
.user
– Optional. A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.saveSourceImage
– Optional. When set to true
, the image in the imageUrl
parameter will be saved in the folder specified during the service installation.Response Body:
Returns a list of generated images in the following format:
[ "https://image-url-1", "https://image-url-2", "https://image-url-3", ... ]
Example:
curl -X "POST" "https://xxxx.backendless.app/api/services/OpenAIImageService/createImageVariation" \ -H 'Content-Type: application/json' \ -H 'Accept: application/json' \ -d $'{ "imageUrl": "https://www.backendless.us/api/files/images/burger.png", "numberOfImages": 2 }'
Response:
[ "https://oaidalleapiprodscus.blob.core.windows.net/private/org-z8bpMZcyVDHPjjjJKbP5diyE/user-PsbPicpgJc4uG80brMQAF2uY/img-phJcBEzrA816csybvN2uYOhC.png?st=2023-10-20T21%3A51%3A14Z&se=2023-10-20T23%3A51%3A14Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-10-20T18%3A18%3A55Z&ske=2023-10-21T18%3A18%3A55Z&sks=b&skv=2021-08-06&sig=ikmYpwMgXqeR7j9KroFxFHdZ2zWxvI91ZLQhnbUYh1g%3D" "https://oaidalleapiprodscus.blob.core.windows.net/private/org-z8bpMZcyVDHPjjjJKbP5diyE/user-PsbPicpgJc4uG80brMQAF2uY/img-k6fVTAbAknhXJJxabgMUwgc8.png?st=2023-10-20T21%3A51%3A14Z&se=2023-10-20T23%3A51%3A14Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-10-20T18%3A18%3A55Z&ske=2023-10-21T18%3A18%3A55Z&sks=b&skv=2021-08-06&sig=/V%2BdG5XU9MOEoKsykCPQ15PmcXZhydaNlSc18yVwH08%3D" ]