Local Inpainting
Description
This API is used to process requests for AI local content generation in the cloud. Please refer to the following documentation for details of the specific effects.
Image Examples
| Input Image | Output Image |
|---|---|
![]() | ![]() |
Image Requirements
Image formats: JPG, PNG
Invocation Information
Task submission endpoint: https://openapi.meitu.com/api/v1/sdk/sync/push
Task name (task): /v1/InPainting/468520
Task type (task_type): formulaPermissions
Request Parameters
| Required | Parameter Name | Type | Parameter Description |
|---|---|---|---|
| Yes | params | string | Inference parameters |
| Yes | init_images | object[] | Image parameters. Two images must be provided: the first is the original image, and the second is the mask image (selecting the area to be painted) |
| Yes | task | string | Fixed: /v1/InPainting/468520 |
| Yes | task_type | string | Fixed: formula |
| No | sync_timeout | int | Default is 30. -1 means no waiting. This is the synchronous timeout. When the API times out, status returns 9. Use the (https://meituhub.cn/docs?id=179&f_id=11) API to query |
| No | rsp_media_type | string | “jpg”: the fused result image is returned directly as base64-encoded data “url”: the fused result image is returned directly as a URL; URL is returned by default |
init_images image parameters are structured as follows
| Required | Parameter Name | Type | Parameter Description |
|---|---|---|---|
| Yes | url | string | Image URL |
| No | profile | object | Multimedia parameters |
profile parameters are structured as follows
| Required | Parameter Name | Type | Parameter Description |
|---|---|---|---|
| No | media_extra | object | Additional multimedia parameters |
| No | media_profiles | object | Multimedia description |
media_profiles parameters are structured as follows
| Required | Parameter Name | Type | Parameter Description |
|---|---|---|---|
| No | media_data_type | string | "url": the multimedia file is transmitted as a URL, "jpg": the multimedia file is transmitted as base64-encoded data |
Parameter description in params (must be escaped as a string)
| Required | Parameter Name | Type | Parameter Description |
|---|---|---|---|
| Yes | parameter | String | Inpainting parameters |
Parameter description in parameter
| Required | Parameter Name | Type | Parameter Description |
|---|---|---|---|
| No | rsp_media_type | String | “jpg”: the fused result image is returned directly as base64-encoded data; “url”: the fused result image is returned directly as a URL |
| No | prompt_pos | String | Positive prompt |
| No | seed | int | Random seed [-1,2147483647]. If not provided, the seed value is generated randomly |
| No | return_format_type | String | Returned image format. Default is ‘png’. Options: [‘jpeg’, ‘jpg’, ‘png’, ‘webp’]. Any other input returns ‘png’ format. |
Input Example
{
"params": "{\"parameter\":{\"rsp_media_type\":\"url\",\"prompt_pos\":\"lipstick lying on satin fabric\"}}",
"init_images": [
{
"profile": {
"media_profiles": {
"media_data_type": "url"
},
"version": "v1"
},
"url": "Original Image URL or Base64"
},
{
"profile": {
"media_profiles": {
"media_data_type": "url"
},
"version": "v1"
},
"url": "Mask URL or Base64"
}
],
"task": "/v1/InPainting/468520",
"task_type": "formula"
}Response Description
Successful Response Description
| Field | Type | Parameter Description |
|---|---|---|
| media_info_list | List | Each item contains multimedia information (for example, image data and corresponding information), same as above |
| parameter | Object | Returned information type identifier |
Field description for a single element in media_info_list
| Field | Type | Parameter Description |
|---|---|---|
| media_data | String | Base64-encoded multimedia file data |
| media_profiles | Object | Description of multimedia file-related attribute information |
Field description in parameter
| Field | Type | Parameter Description |
|---|---|---|
| rsp_media_type | String | 'jpg' indicates that media_data is an image compressed and encoded with base64 |
Field description in media_profiles
| Field | Type | Parameter Description |
|---|---|---|
| media_data_type | String | 'jpg' indicates that media_data is an image compressed and encoded with base64 |
Failed Response Description
| Field | Type | Description |
|---|---|---|
| ErrorCode | Int | Error code |
| ErrorMsg | String | Error message |
| Data | String | Example of the returned detailed information value |
Response Examples
Successful Response Example
Response Status: 200
content-type is application/json; charset=utf-8
{
"parameter": {
"rsp_media_type": "jpg",
}
"media_info_list": [{
"media_data": "...",
"media_profiles": {
"media_data_type": "jpg"
}
}]
}Failed Response Example
Response Status: 400
content-type is application/json; charset=utf-8
{
"ErrorCode": 20003,
"ErrorMsg": "detect no face",
"Data": null
}Error Codes and Messages Specific to the Current API
| ErrorCode Status Code | Error Message | Description |
|---|---|---|
| 20001 | PROCESS_ERROR | Processing error |
| 20003 | DETECT_NOT_FACE | Face missing |
| 20004 | MORE_THAN_ONE_FACE | More than one face |
| 20007 | MISSING_LANDMARK_ARGUMENTS | Face landmarks were not provided |
| 20008 | UNSUITABLE_IMAGE | Image does not meet the requirements |
| 20009 | UNSUPPORT_TYPE | Unsupported type |
| 20010 | DETECT_NOT_FACE | No face detected in the second image |
| 20011 | UNSUITABLE_VERTICAL_IMAGE | Vertical height requirement not met |
| 20012 | UNSUITABLE_HORIZONTAL_IMAGE | Horizontal width requirement not met |
| 20013 | RESOLUTION_TOO_LARGE_ERROR | Resolution is too large |
| 20014 | NOT_FOUND | Image not found |
| 20015 | PICTURE_OVERRUN_ERROR | Image exceeds the limit |
| 20020 | DETECT_FACE_OUTOFIMAGE | Facial features missing |
| 20021 | DETECT_FACE_PITCHANGLE_BIG | Not a frontal face; head nodding/pitch angle is too large |
| 20022 | DETECT_FACE_YAWANGLE_BIG | Not a frontal face; head shaking/rotation angle is too large |
| 20023 | DETECT_FACE_LOWAREA | Face occupies too small an area / pixel count is too low |
| 21001 | LOAD_MODEL_ERROR | Failed to load model |
| 21002 | HAIR_MASK_LOSS | Hair mask missing |
| 21003 | FACE_NUM_ERROR | Incorrect number of faces |
| 21004 | AR_PARSE_FAULT | plist parsing error in AR |
| 21005 | AR_EEEOR_COUNT | AR face error |
| 21006 | AR_FACE_OUT | AR exceeds face range |
| 21007 | JSON_ERROR | JSON content error |
| 21008 | BACKGROUND_IMAGE_LOSS | Background image missing |
| 21009 | BODY_MASK_LOSS | Body mask missing |
| 21010 | FACE_ANGLE_ERROR | Face angle error |
| 21011 | SKIN_MASK_LOSS | Skin mask missing |
| 21012 | BODY_INFO_LOSS | Skeleton points or outer contour points missing |
| 21013 | RECT_OUT_IMAGE | Exceeds image range |
| 30001 | GEN_ERROR | Generation error |
General Error Codes and Messages
See API Error Codes for details.
Invocation Method
import requests
import json
import requests
from sign_sdk import sign
key = ""
secret = ""
def fetchResult(taskId):
url = "https://openapi.meitu.com/api/v1/sdk/status?task_id="+taskId
#key = "your api key"
#secret = "your api secret"
method = "GET"
headers = {
"Content-Type": "application/json",
sign.HeaderHost: "openapi.meitu.com"
}
body = ""
try:
signer = sign.Signer(key, secret)
signed_request = signer.sign(url,method,headers,body)
session = requests.Session()
response = session.send(signed_request,verify=False)
if response.status_code==200:
r=json.loads(response.content)
if r["data"]["result"]["status"]=="10":
# Task succeeded
print(r["data"]["result"]["url"])
elif r["data"]["result"]["status"]=="2" or r["data"]["result"]["status"]=="20":
# Task failed
print(r["data"]["result"])
else:
# Task in progress
fetchResult(taskId)
else:
print(response.text)
except Exception as ex:
print(ex)
url = "http://openapi.meitu.com/api/v1/sdk/sync/push"
method = "POST"
headers = {
"Content-Type": "application/json",
sign.HeaderHost: "openapi.meitu.com",
}
param = {
"parameter": {
"rsp_media_type": "url",
"prompt_pos": "lipstick lying on satin fabric"
}
}
imageUrl="https://obs-open-platform.obs.cn-north-4.myhuaweicloud.com/public/resources/img"
imagePositionMask="https://obs-open-platform.obs.cn-north-4.myhuaweicloud.com/public/resources/pos"
#
body = json.dumps({
# Note: params is of string type and requires json.dumps to convert the data structure once
"params": json.dumps(param),
"init_images": [
# Input original image
{
"url": imageUrl,
"profiles": {
"version": "v1"
}
},
# Input Mask image
{
"url": imagePositionMask,
"profiles": {
"version": "v1"
}
}],
"task": "/v1/InPainting/468520", # task in the invocation information
"task_type": "formula" # task type in the invocation information
})
signer = sign.Signer(key, secret)
print(body)
signed_request = signer.sign(url, method, headers, body)
session = requests.Session()
response = session.send(signed_request,verify=False)
print(response.status_code)
print(response.text)
taskResult= json.loads(response.content)
taskId=taskResult["data"]["result"]["id"]
fetchResult(taskId,None)

