This document details the parameters for the image erase completion model. This model removes one or more elements from an image, such as people, pets, objects, text, or watermarks, while preserving the background. You can specify the areas to remove using a mask image.
Prerequisites
Obtain an API key and export the API key as an environment variable.
HTTP call
To reduce wait times and prevent request timeouts, the service processes requests asynchronously. You need to make two requests:
- Create a task: Send a request to create an image generation task. This request returns a task ID.
- Query the result by task ID: Use the returned task ID to query the result.
Step 1: Create a task
POST https://dashscope.aliyuncs.com/api/v1/services/aigc/image2image/image-synthesis
Request headersContent-TypestringRequiredThe content type of the request. The value must beapplication/json.AuthorizationstringRequiredWe recommend using your Model Studio API key. You can also use your DashScope API key. Example: Bearer d1xxx2a.X-DashScope-AsyncstringRequiredSpecifies whether to enable asynchronous processing. You must set this parameter to enable.Request bodymodelstringRequiredThe model to call.inputobjectRequiredInput image details, such as the image URL.
Properties image_urlstringRequiredThe URL or Base64-encoded data of the input image.The URL must be publicly accessible and use HTTP or HTTPS.Image requirements:
Properties fast_modeboolOptionalSpecifies whether to enable fast mode. The default value is false. In fast mode, inference takes about one-fourth the time of standard mode. This mode is suitable for scenarios that do not require high detail.dilate_flagboolOptionalThe default value is true. We recommend setting this to true if an algorithm generates the erase mask, and to false if you manually paint the erase mask.add_watermark booleanOptionalAdds a Generated by AI watermark. The default value is true, which adds the watermark to the bottom-left corner of the output image. |
|
ResponseoutputobjectTask output details.
Properties task_idstringThe unique task identifier.task_statusstringThe task status.
|
Step 2: Query the result
GET https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}
Request headersAuthorizationstringRequiredYour API key. Example: Bearer d1**2a.Path parameterstask_idstringRequiredThe task ID. |
|
ResponseoutputobjectTask output details.
Properties task_id stringThe task ID.task_status stringThe task status.
Properties TOTAL integerThe total number of tasks.SUCCEEDED integerThe number of successful tasks.FAILED integerThe number of failed tasks.
Properties image_countintegerThe number of generated images. |
Completed task results are available for 24 hours. After this period, the system deletes the task and its results. The generated image URL also expires after 24 hours, so you must save the image after retrieving the task result. |
Status codes
For common status codes for Model Studio services, see Error messages.
This API also returns the following specific status codes:
HTTP status code | Error code | Error message | Description |
|---|---|---|---|
400 | InvalidParameter.JsonPhrase | input json error | Invalid JSON in the request. |
400 | InvalidParameter.FileDownload | oss download error | Failed to download the input image. |
400 | InvalidParameter.ImageFormat | read image error | Failed to read the image. |
400 | InvalidParameter.ImageContent | The image content is not compliant. | The image content is not compliant. |
400 | InvalidParameter | An input parameter value is out of range: xxx | An input parameter value is out of range. |
400 | InvalidParameter.ImageResolution | The input image size is too small or too large. | The input image size is too small or too large. |
500 | InternalError.Algo | algorithm process error | Algorithm error. |
500 | InternalError.FileUpload | oss upload error | Failed to upload the file. |