Feature

AI Image Generator/Editor Service

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.

Usage Examples and Use-Cases

  • Personalized User Avatars:
    When a user signs up or joins a platform, the API can instantly generate a unique and customizable avatar based on the user’s profile information or preferences. This eliminates the need for default or generic profile pictures.
    Benefit: Enhances user experience by offering a personalized touch from the get-go.
  • Dynamic Ad Content Creation:
    As users browse a platform or app, the API generates tailored visual advertisements in real-time based on the user’s behavior, preferences, or browsing history.
    Benefit: Provides more relevant ad content, increasing the likelihood of user engagement and conversions.
  • Real-time Product Customization:
    In e-commerce or design apps, as users customize product features (like color, shape, or design elements), the API instantly generates a visual representation of the customized product.
    Benefit: Enables users to visualize their customizations instantly, leading to informed decisions and better user satisfaction.
  • Thematic Content for Events or Seasons:
    Depending on current events, holidays, or seasons, apps can use the API to generate thematic visuals or layouts dynamically, enhancing the relevancy of the content.
    Benefit: Keeps apps fresh and contextually relevant, ensuring consistent user engagement throughout the year.
  • Interactive Learning and Education:
    Educational apps can leverage the API to create dynamic visual content based on the subject matter. For instance, generating images of historical figures, events, or scientific concepts as students progress through lessons.
    Benefit: Makes learning more engaging and adaptable to individual learners’ pacing and preferences.
  • Interactive Storytelling:
    In storytelling or news apps, the API creates relevant and dynamic visual content aligned with the narrative. For instance, as a user selects different paths in a story, new scenes are generated in real time.
    Benefit: Makes storytelling more immersive and adaptable to user choices, ensuring higher engagement.

Installation Instructions

  1. Login to Backendless Console and select your app. Open the Marketplace screen, select the API Services section, and install the OpenAI Image Plugin.
  2. During the installation, you are prompted to enter your 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:
  3. To verify the installation, click the Cloud Code icon in the Backendless Console and confirm that the OpenAIImageService API service appears in the list of services:

  4. If you need to change any of the configuration settings (API key, or the default folder for the image files), click the gear icon to access the Service Configuration popup:

Service Methods

The Images API provides three methods for interacting with images:

  1. createImage – creates images from scratch based on a text prompt
  2. createImageEdit – creates edits of an existing image based on a new text prompt.
  3. createImageVariation – creates variations of an existing image.

createImage

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/…"
]

Codeless Reference


createImageEdit

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"
]

Codeless Reference


createImageVariation

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"
]

Codeless Reference