AI超清V1
描述
本接口用于在云端处理图片超清请求。
图片要求
支持 JPG、JPEG、BMP 格式。
调用 URL
正式环境:https://openapi.meitu.com
任务提交接口:https://openapi.meitu.com/api/v1/sdk/sync/push
任务名称(task):/v1/Ultra_High_Definition/466657
任务类型(task_type):formula调用方法
POST
Content-Type: application/json
权限
请求参数
请求体恰好包含以下五个顶层字段:
| 是否必选 | 参数名 | 类型 | 参数说明 |
|---|---|---|---|
| 必选 | params | string | 推理参数(JSON 字符串) |
| 必选 | init_images | object[] | 图片文件列表 |
| 必选 | task | string | 固定 /v1/Ultra_High_Definition/466657 |
| 必选 | task_type | string | 固定 formula |
| 可选 | sync_timeout | int | 默认 30;-1 表示不等待。同步等待超时后返回状态 9,需使用查询接口获取结果 |
init_images 图片参数,结构说明如下
| 是否必选 | 参数名 | 类型 | 参数说明 |
|---|---|---|---|
| 必选 | url | string | 图片 URL 或 base64 |
| 可选 | profile | object | 多媒体参数 |
profile 多媒体参数,结构说明如下
| 是否必选 | 参数名 | 类型 | 参数说明 |
|---|---|---|---|
| 可选 | media_extra | object | 多媒体附加参数;源文未进一步定义其内部字段 |
| 可选 | media_profiles | object | 多媒体描述 |
| 可选 | version | string | 源文请求示例中传 v1 |
media_profiles 多媒体描述,结构说明如下
| 是否必选 | 参数名 | 类型 | 参数说明 |
|---|---|---|---|
| 可选 | media_data_type | string | 默认 url;url 表示通过 URL 传入图片,jpg 表示传入 JPG 图片的 base64 |
params 推理参数是 JSON 字符串,其反序列化后的结构说明如下
| 是否必选 | 字段 | 类型 | 说明 |
|---|---|---|---|
| 可选 | rsp_media_type | string | 默认 url;url 表示结果图片以 URL 返回,jpg 表示结果图片以 JPG base64 返回 |
| 必选 | parameter | object | 超清算法参数对象 |
parameter 算法参数详情
| 是否必选 | 参数名 | 类型 | 参数说明 |
|---|---|---|---|
| 必选 | style_id | int | 适配风格 ID;从适配风格枚举接口获取 |
| 可选 | sr_num | int | 图片放大倍数,仅支持 2 或 4,默认 2。2 倍最大支持原图 2560 × 2560,4 倍最大支持原图 1280 × 1280 |
| 可选 | create_value | int | 创造力参数,取值范围 0~100;不传时使用适配风格配置的默认值 |
| 可选 | hdr_value | int | HDR 增强数值,取值范围 0~100;不传时使用适配风格配置的默认值 |
| 可选 | resemblance_value | int | 相似度数值,取值范围 0~100;不传时使用适配风格配置的默认值 |
| 可选 | save_photo_format | int | 默认 1,表示 JPG 编码;2 表示 PNG 编码 |
输入值示例
以下示例保留源文中的算法参数值;其中 create_value、hdr_value、resemblance_value 的源文示例传 -1,而参数表声明的取值范围为 0~100。接入时应以当前适配风格配置和服务端校验规则为准;如需使用默认配置,也可不传这三个可选字段。
{
"task": "/v1/Ultra_High_Definition/466657",
"task_type": "formula",
"init_images": [
{
"url": "https://example.com/input.jpg",
"profile": {
"media_profiles": {
"media_data_type": "url"
},
"version": "v1"
}
}
],
"params": "{\"rsp_media_type\":\"url\",\"parameter\":{\"sr_num\":2,\"style_id\":26,\"create_value\":-1,\"hdr_value\":-1,\"resemblance_value\":-1}}",
"sync_timeout": 30
}返回值说明
| 字段 | 类型 | 说明 |
|---|---|---|
| request_id | string | 请求标识 |
| trace_id | string | 链路追踪标识 |
| code | int | 业务状态码,0 表示请求受理成功 |
| error_code | int | 错误码,成功时为 0 |
| message | string | 业务信息或错误信息 |
| tips | any | 补充提示,可为 null |
| data | object | 任务状态和算法结果 |
data 字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| status | int | 状态码:-1 未找到任务;0 创建成功;1 执行中;2 失败;9 需要使用查询接口查询;10 成功 |
| msg | string | 任务状态说明 |
| result | object | 算法结果 |
| progress | number | 任务进度,例如 0.1、0.85、1 |
| predict_elapsed | int | 预计耗时,毫秒 |
| create_time | int64 | 创建时间戳,毫秒 |
| task_id | string | 任务 ID |
| custom_task_id | string | 客户自定义任务 ID |
| trace_id | string | 链路追踪标识 |
| client_info | string | 客户端信息 |
| init_images | object[]/null | 输入媒体回显 |
result 字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| id | string | 任务 ID |
| urls | string[] | 结果图片列表;rsp_media_type=url 时为图片 URL,rsp_media_type=jpg 时为 JPG base64 |
| parameter | object | 算法返回信息类型标识;源文定义其 rsp_media_type 字段 |
| media_info_list | object[] | 算法多媒体结果列表;每项包含图片数据及对应信息 |
parameter 返回字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| rsp_media_type | string | 结果媒体类型;url 表示 media_data 为图片 URL,jpg 表示 media_data 为 JPG base64 |
media_info_list 单个元素的字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| media_data | string | 结果图片 URL 或经过 base64 编码的多媒体文件数据,取决于 rsp_media_type |
| media_profiles | object | 多媒体文件属性信息 |
media_profiles 返回字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| media_data_type | string | 结果媒体数据类型;url 表示 URL,jpg 表示 JPG base64 |
任务失败时,result 还可能包含源文定义的以下字段:
| 字段 | 类型 | 说明 |
|---|---|---|
| ErrorCode | int | 错误代码 |
| ErrorMsg | string | 错误信息 |
| Data | string/null | 具体信息 |
返回值示例
请求成功返回示例(status=10)
Response Status:200
content-type 为 application/json; charset=utf-8
{
"request_id": "req_1234567890",
"trace_id": "trace_1234567890",
"code": 0,
"error_code": 0,
"message": "success",
"tips": null,
"data": {
"status": 10,
"msg": "success",
"result": {
"id": "task_1234567890",
"urls": [
"https://example.com/result.jpg"
],
"parameter": {
"rsp_media_type": "url"
},
"media_info_list": [
{
"media_data": "https://example.com/result.jpg",
"media_profiles": {
"media_data_type": "url"
}
}
]
},
"progress": 1,
"predict_elapsed": 0,
"create_time": 1718172000000,
"task_id": "task_1234567890",
"custom_task_id": "",
"trace_id": "trace_1234567890",
"client_info": "",
"init_images": null
}
}需要查询返回示例(status=9)
当 data.status 为 9 时,使用查询接口和返回的任务 ID 查询结果。
Response Status:200
content-type 为 application/json; charset=utf-8
{
"request_id": "req_1234567890",
"trace_id": "trace_1234567890",
"code": 0,
"error_code": 0,
"message": "success",
"tips": null,
"data": {
"status": 9,
"msg": "processing",
"result": {
"id": "task_1234567890"
},
"progress": 0,
"predict_elapsed": 10000,
"create_time": 1718172000000,
"task_id": "task_1234567890",
"custom_task_id": "",
"trace_id": "trace_1234567890",
"client_info": "",
"init_images": null
}
}请求失败返回示例(status=2)
Response Status:400
content-type 为 application/json; charset=utf-8
{
"request_id": "req_1234567890",
"trace_id": "trace_1234567890",
"code": 20001,
"error_code": 20001,
"message": "PROCESS_ERROR",
"tips": null,
"data": {
"status": 2,
"msg": "PROCESS_ERROR",
"result": {
"id": "task_1234567890",
"ErrorCode": 20001,
"ErrorMsg": "PROCESS_ERROR",
"Data": null
},
"progress": 1,
"predict_elapsed": 0,
"create_time": 1718172000000,
"task_id": "task_1234567890",
"custom_task_id": "",
"trace_id": "trace_1234567890",
"client_info": "",
"init_images": null
}
}当前 API 特有的错误代码与信息
| ErrorCode 状态代码 | 错误信息 | 说明 |
|---|---|---|
| 20001 | PROCESS_ERROR | 处理错误 |
| 20003 | DETECT_NOT_FACE | 人脸缺失 |
| 20004 | MORE_THAN_ONE_FACE | 人脸数大于 1 |
| 20007 | MISSING_LANDMARK_ARGUMENTS | 未传入人脸点 |
| 20008 | UNSUITABLE_IMAGE | 照片不符合规范 |
| 20009 | UNSUPPORT_TYPE | 不支持的 type |
| 20010 | DETECT_NOT_FACE | 检测不到第二张图片的人脸 |
| 20011 | UNSUITABLE_VERTICAL_IMAGE | 垂直高度不满足 |
| 20012 | UNSUITABLE_HORIZONTAL_IMAGE | 水平宽度不满足 |
| 20013 | RESOLUTION_TOO_LARGE_ERROR | 分辨率过大 |
| 20014 | NOT_FOUND | 查找不到图片 |
| 20015 | PICTURE_OVERRUN_ERROR | 图片超限 |
| 20020 | DETECT_FACE_OUTOFIMAGE | 五官缺失 |
| 20021 | DETECT_FACE_PITCHANGLE_BIG | 非正脸,点头或俯仰角过大 |
| 20022 | DETECT_FACE_YAWANGLE_BIG | 非正脸,摇头或旋转角过大 |
| 20023 | DETECT_FACE_LOWAREA | 脸部占比小、像素低 |
| 21001 | LOAD_MODEL_ERROR | 加载模型失败 |
| 21002 | HAIR_MASK_LOSS | 头发 mask 缺失 |
| 21003 | FACE_NUM_ERROR | 人脸个数错误 |
| 21004 | AR_PARSE_FAULT | AR 中 plist 解析错误 |
| 21005 | AR_EEEOR_COUNT | AR 人脸错误 |
| 21006 | AR_FACE_OUT | AR 超过人脸范围 |
| 21007 | JSON_ERROR | JSON 内容错误 |
| 21008 | BACKGROUND_IMAGE_LOSS | 背景图片缺失 |
| 21009 | BODY_MASK_LOSS | body mask 缺失 |
| 21010 | FACE_ANGLE_ERROR | 人脸角度错误 |
| 21011 | SKIN_MASK_LOSS | skin mask 缺失 |
| 21012 | BODY_INFO_LOSS | 骨骼点或者外轮廓点缺失 |
| 21013 | RECT_OUT_IMAGE | 超过图片范围 |
| 30001 | GEN_ERROR | 生成错误 |
通用的错误代码与信息
详见 API 错误码
SDK 调用示例
以下示例均对最终发送的完整 JSON body 进行签名;body 只有 task、task_type、init_images、params、sync_timeout 五个顶层字段。
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": {
"style_id": 26,
"sr_num": 2,
},
}
payload = {
"task": "/v1/Ultra_High_Definition/466657",
"task_type": "formula",
"init_images": [
{
"url": "https://example.com/input.jpg",
"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/Ultra_High_Definition/466657",
"task_type": "formula",
"init_images": [{
"url": "https://example.com/input.jpg",
"profile": {
"media_profiles": {"media_data_type": "url"},
"version": "v1"
}
}],
"params": "{\"rsp_media_type\":\"url\",\"parameter\":{\"style_id\":26,\"sr_num\":2}}",
"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' => [
'style_id' => 26,
'sr_num' => 2,
],
]);
$body = json_encode([
'task' => '/v1/Ultra_High_Definition/466657',
'task_type' => 'formula',
'init_images' => [
[
'url' => 'https://example.com/input.jpg',
'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/Ultra_High_Definition/466657\",\n" +
" \"task_type\": \"formula\",\n" +
" \"init_images\": [{\n" +
" \"url\": \"https://example.com/input.jpg\",\n" +
" \"profile\": {\n" +
" \"media_profiles\": {\"media_data_type\": \"url\"},\n" +
" \"version\": \"v1\"\n" +
" }\n" +
" }],\n" +
" \"params\": \"{\\\"rsp_media_type\\\":\\\"url\\\",\\\"parameter\\\":{\\\"style_id\\\":26,\\\"sr_num\\\":2}}\",\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);
}
}
}