Product Image Restoration

Description

Restores product images.

Version

1.0

Image Requirements

  • Supported image formats: PNG and JPEG.
  • Supported image size: no larger than 20 MB.

API URL

    Production environment: https://openapi.meitu.com
    Task submission endpoint: https://openapi.meitu.com/api/v1/sdk/sync/push
    Task name (task): /v1/goods_image_repair/493222
    Task type (task_type): formula

Method

POST

Content-Type: application/json

Authentication

Open Platform API Signing

Request Parameters

RequiredParameterTypeDescription
YesparamsstringAlgorithm parameters (JSON string)
Yesinit_imagesobject[]Media file list
YestaskstringFixed value: /v1/goods_image_repair/493222
Yestask_typestringFixed value: formula
Nosync_timeoutintSynchronous timeout; defaults to 30

The init_images media file parameters have the following structure:

RequiredParameterTypeDescription
YesurlstringImage URL or Base64-encoded data
YesprofileobjectAttribute information

The profile object has the following structure:

RequiredParameterTypeDescription
Yesmedia_profilesobjectMedia attributes
YesversionstringFixed value: v1

The media_profiles object has the following structure:

RequiredParameterTypeDescription
Yesmedia_data_typestringurl indicates a URL; types such as jpg indicate Base64-encoded data

The params inference parameter is a JSON string with the following structure:

RequiredFieldTypeDescription
Norsp_media_typestringDefaults to url; jpg returns Base64-encoded data, while url returns a URL
YesparameterobjectCore algorithm parameter object

Algorithm parameters in parameter:

RequiredParameterTypeDescription
NoversionstringAlgorithm version, such as 1.0.0 or 2.0.0; defaults to 1.0.0
Nocreate_valueintCreativity value in the range -100 to 100; defaults to 0
Nohdr_valueintHDR enhancement value in the range 0 to 100; defaults to 30
Noresemblance_valueintResemblance value in the range 0 to 100; defaults to 100
NopromptstringPrompt; defaults to an empty string
Nosr_numintUpscaling factor; allowed values are 2 and 4, and the default is 2. For 2× upscaling, the source image can be up to 2560×2560; for 4× upscaling, it can be up to 1280×1280
Noportraits_xzintWhether to enable portrait-scene processing; defaults to 0. 0: disabled; 1: enabled
Nocustom_size_flagintWhether to enable adaptive sizing; defaults to 0. 0: disabled; 1: enabled
Not specified in sourceguidance_valueintThe source JSON example establishes only that the type is int and the example value is 120; the source does not specify its meaning, whether it is required, its valid range, or its default value
Not specified in sourcemodeintThe source JSON example establishes only that the type is int and the example value is 2; the source does not specify its meaning, whether it is required, its valid range, or its default value
Not specified in sourcealgorithm_versionstringThe source JSON example establishes only that the type is string and the example value is v3; the source does not specify its meaning, whether it is required, its valid range, or its default value

Request Example

{
  "task": "/v1/goods_image_repair/493222",
  "task_type": "formula",
  "init_images": [
    {
      "url": "https://file.style3d.com/app/intellistyle/company/ai/1784340525931/CAL020-DDPD.png",
      "profile": {
        "media_profiles": {
          "media_data_type": "url"
        },
        "version": "v1"
      }
    }
  ],
  "params": "{\"rsp_media_type\":\"url\",\"parameter\":{\"version\":\"1.0.0\",\"create_value\":100,\"hdr_value\":30,\"resemblance_value\":100,\"prompt\":\"\",\"sr_num\":2,\"portraits_xz\":0,\"custom_size_flag\":1,\"guidance_value\":120,\"mode\":2,\"algorithm_version\":\"v3\"}}",
  "sync_timeout": 30
}

Response Fields

Note: Generated results are periodically deleted. Download and save them promptly.
FieldTypeDescription
request_idstringRequest identifier
trace_idstringTrace identifier
codeintBusiness status code; 0 indicates that the request was accepted successfully
error_codeintError code; 0 on success
messagestringBusiness message
tipsanyAdditional information; may be null
dataobjectTask status and algorithm result

Fields in data:

FieldTypeDescription
statusintStatus code: -1, task not found; 0, created successfully; 1, processing; 2, failed; 9, timed out—use the query API; 10, succeeded
resultobjectAlgorithm result
progressnumberTask progress
predict_elapsedintEstimated processing time, in milliseconds
create_timeint64Creation timestamp, in milliseconds
task_idstringTask ID
custom_task_idstringClient-defined task ID
trace_idstringTrace identifier
client_infostringClient information
init_imagesobject[]/nullEcho of the input media

Fields in data.result:

FieldTypeDescription
idstringUnique task identifier
urlsarrayList of generated image URLs
parametersobjectAlgorithm parameter information, including the response media type and algorithm version
dataobjectDetailed data returned by the algorithm
msgstringMessage returned by the algorithm
msg_idstringMessage ID
imagesarrayList of generated media URLs
mtlab_resobjectUnderlying algorithm result
media_info_listarrayMedia information list

Fields in data.result.parameters:

FieldTypeDescription
rsp_media_typestringResponse media type
versionstringAlgorithm version

Fields in data.result.data:

FieldTypeDescription
durationobjectProcessing-time statistics for each stage
error_codeintAlgorithm error code; 0 indicates success
error_msgstringAlgorithm error message
extraobjectExtended metadata
media_info_listarrayMedia information list
msg_idstringMessage ID
parameterobjectEcho of the parameters

Fields in data.result.data.duration:

FieldTypeDescription
alg_process_timeintAlgorithm processing time, in milliseconds
created_timestampintTask creation timestamp
pull_timestampintResource retrieval timestamp
repost_timeintReprocessing time, in milliseconds
upload_timeintResource upload time, in milliseconds
waiting_timeintQueue wait time, in milliseconds

Fields in data.result.data.extra.trans_meta:

FieldTypeDescription
req_metaarrayRequest media metadata list; media_type in each item indicates the media type
rsp_metaarrayResponse media metadata list; each item contains height, media_type, size, and width

Fields in each item of data.result.media_info_list and data.result.data.media_info_list:

FieldTypeDescription
media_datastringMedia data URL
media_extraobject/nullAdditional media information
media_profilesobjectMedia profile information

Fields in media_profiles:

FieldTypeDescription
media_data_heightintMedia height, in pixels
media_data_sizeintMedia size, in bytes
media_data_typestringMedia data type, such as url
media_data_widthintMedia width, in pixels

Fields in data.result.mtlab_res:

FieldTypeDescription
ErrorCodeintUnderlying error code
ErrorMsgstringUnderlying error message
error_codeintError code (compatibility field)
error_msgstringError message (compatibility field)
media_info_listarray/nullMedia information list
msg_idstringMessage ID
parameterobject/nullParameter information

Error codes and messages specific to this API:

Error CodeError MessageDescription
20001PROCESS_ERRORProcessing error

Response Examples

Successful Response Example

{
  "request_id": "",
  "trace_id": "",
  "code": 0,
  "error_code": 0,
  "message": "success",
  "tips": null,
  "data": {
    "status": 10,
    "result": {
      "id": "t_mt1a3i5n7b8e22d6dc-44ee-4834-a6a3-e30e2292f5d8",
      "urls": [
        "https://obs-large.mtlab.meitu.com/mtopen/ff56d688358849259556be0f50065a60/d69631a2-d6b3-4bac-6d52-7b4b46fe11a5.jpeg"
      ],
      "parameters": {
        "rsp_media_type": "url",
        "version": "1.0.35"
      },
      "data": {
        "duration": {
          "alg_process_time": 4505,
          "created_timestamp": 1784536063,
          "pull_timestamp": 1784536063,
          "repost_time": 0,
          "upload_time": 211,
          "waiting_time": 135
        },
        "error_code": 0,
        "error_msg": "success",
        "extra": {
          "trans_meta": {
            "req_meta": [
              {
                "media_type": "image"
              }
            ],
            "rsp_meta": [
              {
                "height": 3314,
                "media_type": "image",
                "size": 1726,
                "width": 1977
              }
            ]
          }
        },
        "media_info_list": [
          {
            "media_data": "https://obs-large.mtlab.meitu.com/mtopen/ff56d688358849259556be0f50065a60/d69631a2-d6b3-4bac-6d52-7b4b46fe11a5.jpeg",
            "media_extra": null,
            "media_profiles": {
              "media_data_height": 3314,
              "media_data_size": 1767986,
              "media_data_type": "url",
              "media_data_width": 1977
            }
          }
        ],
        "msg_id": "130a0c98-b631-4ef8-4b1d-r009b6117553",
        "parameter": {
          "rsp_media_type": "url",
          "version": "1.0.35"
        }
      },
      "msg": "success",
      "msg_id": "130a0c98-b631-4ef8-4b1d-r009b6117553",
      "images": [
        "https://obs-large.mtlab.meitu.com/mtopen/ff56d688358849259556be0f50065a60/d69631a2-d6b3-4bac-6d52-7b4b46fe11a5.jpeg"
      ],
      "mtlab_res": {
        "ErrorCode": 0,
        "ErrorMsg": "",
        "error_code": 0,
        "error_msg": "",
        "media_info_list": null,
        "msg_id": "130a0c98-b631-4ef8-4b1d-r009b6117553",
        "parameter": null
      },
      "media_info_list": [
        {
          "media_data": "https://obs-large.mtlab.meitu.com/mtopen/ff56d688358849259556be0f50065a60/d69631a2-d6b3-4bac-6d52-7b4b46fe11a5.jpeg",
          "media_extra": null,
          "media_profiles": {
            "media_data_height": 3314,
            "media_data_size": 1767986,
            "media_data_type": "url",
            "media_data_width": 1977
          }
        }
      ]
    },
    "progress": 1,
    "predict_elapsed": 10000,
    "create_time": 1784536063640,
    "task_id": "t_mt1a3i5n7b8e22d6dc-44ee-4834-a6a3-e30e2292f5d8",
    "custom_task_id": "",
    "trace_id": "",
    "client_info": "",
    "init_images": null
  }
}

Pending Response Example

Use the query API to retrieve the result.

Response Status: 200

Content-Type: application/json; charset=utf-8

{
  "request_id": "",
  "trace_id": "",
  "code": 0,
  "error_code": 0,
  "message": "success",
  "tips": null,
  "data": {
    "status": 9,
    "result": {
      "id": "t_mt1a3i5n7b8e22d6dc-44ee-4834-a6a3-e30e2292f5d8"
    },
    "progress": 0,
    "predict_elapsed": 10000,
    "create_time": 1784536063640,
    "task_id": "t_mt1a3i5n7b8e22d6dc-44ee-4834-a6a3-e30e2292f5d8",
    "custom_task_id": "",
    "trace_id": "70b45244-3360-4859-bc01-9ec4435a81e8",
    "client_info": "",
    "init_images": null
  }
}

Failed Response Example

Response Status: 400

Content-Type: application/json; charset=utf-8

{
  "request_id": "",
  "trace_id": "",
  "code": 20001,
  "error_code": 20001,
  "message": "PROCESS_ERROR",
  "tips": null,
  "data": {
    "status": 2,
    "result": {
      "error_code": 20001,
      "message": "PROCESS_ERROR"
    },
    "progress": 0,
    "predict_elapsed": 0,
    "create_time": 0,
    "task_id": "",
    "custom_task_id": "",
    "trace_id": "",
    "client_info": "",
    "init_images": null
  }
}

General Error Codes

See API Error Codes.

SDK Examples

Python

import json

import requests
from sign_sdk import sign

def api_call_example():
    key = "your_api_key"
    secret = "your_api_secret"
    url = "https://openapi.meitu.com/api/v1/sdk/sync/push"
    method = "POST"

    headers = {
        "Content-Type": "application/json",
        sign.HeaderHost: "openapi.meitu.com",
    }
    inner_params = {
        "rsp_media_type": "url",
        "parameter": {
            "version": "1.0.0",
            "create_value": 100,
            "hdr_value": 30,
            "resemblance_value": 100,
            "prompt": "",
            "sr_num": 2,
            "portraits_xz": 0,
            "custom_size_flag": 1,
            "guidance_value": 120,
            "mode": 2,
            "algorithm_version": "v3",
        },
    }
    payload = {
        "task": "/v1/goods_image_repair/493222",
        "task_type": "formula",
        "init_images": [
            {
                "url": "https://file.style3d.com/app/intellistyle/company/ai/1784340525931/CAL020-DDPD.png",
                "profile": {
                    "media_profiles": {"media_data_type": "url"},
                    "version": "v1",
                },
            }
        ],
        "params": json.dumps(inner_params, ensure_ascii=False),
        "sync_timeout": 30,
    }
    body = json.dumps(payload, ensure_ascii=False)

    signer = sign.Signer(key, secret)
    signed_request = signer.sign(url, method, headers, body)
    response = requests.Session().send(signed_request)
    print(f"Status: {response.status_code}")
    print(f"Response: {response.text}")

if __name__ == "__main__":
    api_call_example()

Go

package main

import (
    "fmt"
    "io"
    "net/http"

    "github.com/mtlab/api/signer"
)

func main() {
    key := "your_api_key"
    secret := "your_api_secret"
    signObj := signer.NewSigner(key, secret)

    url := "https://openapi.meitu.com/api/v1/sdk/sync/push"
    method := http.MethodPost
    headers := make(http.Header)
    headers.Set(signer.HeaderHost, "openapi.meitu.com")
    headers.Set("Content-Type", "application/json")

    body := `{
  "task": "/v1/goods_image_repair/493222",
  "task_type": "formula",
  "init_images": [{
    "url": "https://file.style3d.com/app/intellistyle/company/ai/1784340525931/CAL020-DDPD.png",
    "profile": {
      "media_profiles": {"media_data_type": "url"},
      "version": "v1"
    }
  }],
  "params": "{\"rsp_media_type\":\"url\",\"parameter\":{\"version\":\"1.0.0\",\"create_value\":100,\"hdr_value\":30,\"resemblance_value\":100,\"prompt\":\"\",\"sr_num\":2,\"portraits_xz\":0,\"custom_size_flag\":1,\"guidance_value\":120,\"mode\":2,\"algorithm_version\":\"v3\"}}",
  "sync_timeout": 30
}`

    req, err := signObj.Sign(url, method, headers, body)
    if err != nil {
        fmt.Println("Failed to sign request:", err)
        return
    }

    resp, err := http.DefaultClient.Do(req)
    if err != nil {
        fmt.Println("Failed to send request:", err)
        return
    }
    defer resp.Body.Close()

    responseBody, err := io.ReadAll(resp.Body)
    if err != nil {
        fmt.Println("Read response failed:", err)
        return
    }
    fmt.Println("Response:", resp.StatusCode, string(responseBody))
}

PHP

<?php
require 'signer.php';

$key = 'your_api_key';
$secret = 'your_api_secret';
$signer = new Signer($key, $secret);

$url = 'https://openapi.meitu.com/api/v1/sdk/sync/push';
$method = 'POST';
$headers = ['Content-Type' => 'application/json'];

$innerParams = json_encode([
    'rsp_media_type' => 'url',
    'parameter' => [
        'version' => '1.0.0',
        'create_value' => 100,
        'hdr_value' => 30,
        'resemblance_value' => 100,
        'prompt' => '',
        'sr_num' => 2,
        'portraits_xz' => 0,
        'custom_size_flag' => 1,
        'guidance_value' => 120,
        'mode' => 2,
        'algorithm_version' => 'v3',
    ],
]);

$body = json_encode([
    'task' => '/v1/goods_image_repair/493222',
    'task_type' => 'formula',
    'init_images' => [
        [
            'url' => 'https://file.style3d.com/app/intellistyle/company/ai/1784340525931/CAL020-DDPD.png',
            'profile' => [
                'media_profiles' => ['media_data_type' => 'url'],
                'version' => 'v1',
            ],
        ],
    ],
    'params' => $innerParams,
    'sync_timeout' => 30,
]);

$curl = $signer->sign($url, $method, $headers, $body);
$response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

if ($status === 0) {
    echo 'Error: ' . curl_error($curl);
} else {
    echo 'Status: ' . $status . "\n";
    echo 'Response: ' . $response . "\n";
}
curl_close($curl);
?>

Java

package com.meitu.openai.common;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

public class Main {
    public static void main(String[] args) throws Exception {
        Signer signer = new Signer("your_api_key", "your_api_secret");
        String url = "https://openapi.meitu.com/api/v1/sdk/sync/push";
        String method = "POST";

        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
        headers.put(Signer.HeaderHost, "openapi.meitu.com");

        String body = "{\n" +
                "  \"task\": \"/v1/goods_image_repair/493222\",\n" +
                "  \"task_type\": \"formula\",\n" +
                "  \"init_images\": [{\n" +
                "    \"url\": \"https://file.style3d.com/app/intellistyle/company/ai/1784340525931/CAL020-DDPD.png\",\n" +
                "    \"profile\": {\n" +
                "      \"media_profiles\": {\"media_data_type\": \"url\"},\n" +
                "      \"version\": \"v1\"\n" +
                "    }\n" +
                "  }],\n" +
                "  \"params\": \"{\\\"rsp_media_type\\\":\\\"url\\\",\\\"parameter\\\":{\\\"version\\\":\\\"1.0.0\\\",\\\"create_value\\\":100,\\\"hdr_value\\\":30,\\\"resemblance_value\\\":100,\\\"prompt\\\":\\\"\\\",\\\"sr_num\\\":2,\\\"portraits_xz\\\":0,\\\"custom_size_flag\\\":1,\\\"guidance_value\\\":120,\\\"mode\\\":2,\\\"algorithm_version\\\":\\\"v3\\\"}}\",\n" +
                "  \"sync_timeout\": 30\n" +
                "}";

        Map<String, String> signedHeaders = signer.sign(url, method, headers, body);
        HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
        connection.setRequestMethod(method);
        for (Map.Entry<String, String> entry : signedHeaders.entrySet()) {
            connection.setRequestProperty(entry.getKey(), entry.getValue());
        }
        connection.setDoOutput(true);
        connection.getOutputStream().write(body.getBytes(StandardCharsets.UTF_8));

        int status = connection.getResponseCode();
        InputStream stream = status >= 400
                ? connection.getErrorStream()
                : connection.getInputStream();
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) {
            StringBuilder response = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                response.append(line);
            }
            System.out.println("Response: " + status + " " + response);
        }
    }
}