Professional Portrait API Integration Guide
Version: V1 | Last updated: October 29, 2026
Professional Portrait (meituhub_workflow_9486_v1) transforms an input photo into a polished professional portrait. Provide one portrait photo and optionally add requirements such as clothing preferences.
This guide describes production API authentication, request parameters, task queries, and integration examples in Python, Go, PHP, and Java. Replace the media URLs, credentials, and task IDs in the examples with your own values.
Contents
- Getting Started
- Submit a Task
- Response Format
- Query a Task
- Language Examples
- Request Examples
- Related Documentation
Getting Started
Get Your AK and SK
-
Sign in to the MeituHub Console and open Account Overview.
-
In the API Keys section, click Copy next to each of the following fields to obtain your AK and SK:
MEITU_OPENAPI_ACCESS_KEY: Access Key (AK).MEITU_OPENAPI_SECRET_KEY: Secret Key (SK).
Use the SK only for server-side request signing. Do not include it in browser code, mobile apps, public repositories, or logs.
Request Signing
Both submission and query requests require AK/SK signing. Use the official signing SDK to sign the full URL, HTTP method, headers, and request body, then send the request generated by the SDK. Do not modify the body after signing.
For signing details, see API Request Signing.
Submit a Task
POST https://openapi.meitu.com/api/v1/sdk/sync/push
Content-Type: application/jsonRequest Parameters
The params.prompt_1 path below refers to a field inside the decoded params string. Place prompt_1 at the top level of a JSON object, then serialize that object into the params string.
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| task | string | Yes | Fixed value | Workflow identifier. Always meituhub_workflow_9486_v1. |
| task_type | string | Yes | Fixed value | Always cozeflow. |
| init_images | object[] | Yes | None | Input image list. Provide one portrait photo at init_images[0]. |
| init_images[0].url | string | Yes | None | Input image URL accessible directly by the server. Replace the sample image from the capability page. |
| params | string | Yes | None | Workflow parameters serialized as a JSON string. Use "{}" when no additional requirements are supplied. |
| params.prompt_1 | string | No | Capability page prefill: 黑色高领短袖 (black high-neck short-sleeved top) | Additional requirements. Free text with no enum restrictions. Send the prefilled value explicitly to use it. |
| sync_timeout | integer | No | 30 in these examples | Synchronous wait time in seconds. Retain the task ID and query the task after a timeout. |
Media Input
Each element in init_images uses the following structure:
{
"url": "https://example.com/input.jpg",
"profile": {
"version": "v1",
"media_profiles": {
"media_data_type": "url"
}
}
}| Field | Type | Required | Description |
|---|---|---|---|
| url | string | Yes | An image URL directly accessible to the server. |
| profile.version | string | Yes | Always v1. |
| profile.media_profiles.media_data_type | string | Yes | Always url. |
This workflow has one image input position: init_images[0] is the input photo. Supply an actual portrait photo and do not add reference image positions.
Business Parameters
Use prompt_1 for additional requirements. Example before serialization:
{
"prompt_1": "黑色高领短袖"
}The value above means a black high-neck short-sleeved top and matches the capability page's prefilled value. The corresponding params field is:
{
"params": "{\"prompt_1\":\"黑色高领短袖\"}"
}The outer type of params must be a string. prompt_1 is optional free text. Use "{}" when no additional requirements are supplied. To use the capability page's prefilled requirements, send that value explicitly.
Response Format
Response Fields
Gateway responses may include an envelope containing code, error_code, message, and data. When the envelope is present, check the outer business codes first, then read the task object from data. If an SDK returns the task object directly, read status, task_id, result, and related fields at the top level.
| Field | Type | Description |
|---|---|---|
| code | integer, optional | Gateway business code. 0 indicates normal request processing. For nonzero values, inspect the error details. |
| error_code | integer, optional | Gateway error code. 0 indicates no corresponding gateway error. |
| message | string, optional | Gateway message or error details. |
| request_id / trace_id | string, optional | Request tracing identifiers. Retain them for troubleshooting. |
| data | object, optional | Task object. Absent when the task object is returned directly. |
The following paths are relative to the task object:
| Field | Type | Description |
|---|---|---|
| status | integer | Task status. See the status table below. |
| task_id | string | Task ID used for subsequent queries. |
| progress | number, optional | Task progress, usually from 0 to 1. |
| result | object / null | Task result. May be empty before completion or on failure. |
| result.id | string, optional | Task ID associated with the result. |
| result.media_info_list | object[], optional | Output image list. The configured output is output_1, corresponding to the first result image. |
| result.media_info_list[].media_data | string | Output image URL. |
| result.media_info_list[].media_profiles | object, optional | Media metadata. For URL results, media_data_type is url. |
| result.media_info_list[].media_extra | object / null, optional | Additional media metadata. |
| result.parameters | JSON value, optional | Additional capability-specific business data. |
| result.code / result.error_code | integer, optional | Business error codes in the result. Inspect the error details for nonzero values. |
| result.msg / result.error_msg | string, optional | Result message or error details. |
Task Status
| status | Meaning | Action |
|---|---|---|
| -1 | Task not found | Check the task ID, calling account, and task retention period. |
| 0 | Created | Save the task ID and continue querying. |
| 1 | Running | Continue querying. |
| 2 | Failed | Handle the gateway and result error details. |
| 9 | Synchronous wait timed out | Save the task ID and continue querying. |
| 10 | Succeeded | Read result.media_info_list. |
HTTP 200 only indicates that the HTTP request completed. Determine task success using the outer business codes, task status, and result errors. Do not treat progress=1 or the presence of a task_id alone as success.
Success Example
This example shows the response structure with a gateway envelope. The task ID and media URL are placeholders:
{
"code": 0,
"error_code": 0,
"message": "success",
"data": {
"progress": 1,
"result": {
"id": "example-task-id",
"media_info_list": [
{
"media_data": "https://example.com/result.png",
"media_extra": {},
"media_profiles": {
"media_data_type": "url"
}
}
],
"parameters": {}
},
"status": 10,
"task_id": "example-task-id"
}
}With a data envelope, the first output image URL is data.result.media_info_list[0].media_data. For a directly returned task object, it is result.media_info_list[0].media_data. Process every item in the returned list and download the result files promptly.
Synchronous Timeout Example
{
"code": 0,
"error_code": 0,
"message": "success",
"data": {
"progress": 0,
"result": {
"id": "example-task-id"
},
"status": 9,
"task_id": "example-task-id"
}
}status=9 does not mean the task failed. Query the result using the returned task_id.
Failure Example
{
"code": 0,
"error_code": 0,
"message": "success",
"data": {
"progress": 0,
"result": null,
"status": 2,
"task_id": "example-task-id"
}
}A task can fail with status=2 even when the outer business codes are 0. Authentication failures, rate limits, and invalid parameters may instead return nonzero business codes or a non-2xx HTTP status without a task ID. Retain the error response and request tracing identifiers. For general error codes, see API Error Codes.
Query a Task
GET https://openapi.meitu.com/api/v1/sdk/status?task_id=example-task-id| Parameter | Location | Type | Required | Description |
|---|---|---|---|---|
| task_id | Query | string | Yes | Task ID returned by submission. |
Use AK/SK credentials from the same account used for submission. Sign the full URL including task_id and the GET method, with an empty request body. The returned fields and status meanings are described in Response Format.
Increase query intervals gradually, for example 2, 5, then 10 seconds, and set an application-level waiting limit. If that limit is reached, retain the task ID and query again later. Task information and media links may expire, so query and save results promptly.
If a submission request times out before you receive a task ID, verify whether the task was created before submitting again.
Language Examples
The four examples use the same request.json file. Copy the complete request body from Request Examples, replace the media URLs and other placeholders, and save it as request.json.
SDK Setup
| Language | Official Documentation | Dependencies |
|---|---|---|
| Python | Python SDK | sign_sdk, requests |
| Go | Go SDK | github.com/mtlab/api/signer |
| PHP | PHP SDK | Official signer.php, cURL extension, PHP 7.3+ |
| Java | Java SDK | Official signing SDK, JDK 11+ |
Download the Python signing package from the SDK download link. Add the extracted sign_sdk package to your import path and install requests:
python -m pip install requestsRun Configuration
To submit a task:
export MEITU_OPENAPI_ACTION='push'
export MEITU_REQUEST_FILE='request.json'To query a task, use this configuration instead:
export MEITU_OPENAPI_ACTION='status'
export MEITU_TASK_ID='example-task-id'Each run performs the selected operation once and prints the full HTTP response. The examples do not automatically poll or retry submissions. After receiving a response, check the business codes and task status as described in Response Format.
Python
Save as client.py and run python client.py:
import json
import os
from pathlib import Path
from urllib.parse import urlencode
import requests
from sign_sdk import sign
HOST = "openapi.meitu.com"
ACTION = os.environ.get("MEITU_OPENAPI_ACTION", "push")
ak = os.environ["MEITU_OPENAPI_ACCESS_KEY"]
sk = os.environ["MEITU_OPENAPI_SECRET_KEY"]
if not ak or not sk:
raise ValueError("Missing AK/SK")
if ACTION == "push":
payload = json.loads(Path(os.environ.get("MEITU_REQUEST_FILE", "request.json")).read_text(encoding="utf-8"))
if not isinstance(payload.get("params"), str):
raise ValueError("params must be a JSON string")
json.loads(payload["params"])
method = "POST"
url = f"https://{HOST}/api/v1/sdk/sync/push"
body = json.dumps(payload, ensure_ascii=False, separators=(",", ":"))
elif ACTION == "status":
task_id = os.environ["MEITU_TASK_ID"]
if not task_id:
raise ValueError("Missing task_id")
method = "GET"
url = f"https://{HOST}/api/v1/sdk/status?" + urlencode({"task_id": task_id})
body = ""
else:
raise ValueError("MEITU_OPENAPI_ACTION must be push or status")
headers = {"Content-Type": "application/json", sign.HeaderHost: HOST}
signed_request = sign.Signer(ak, sk).sign(url, method, headers, body)
with requests.Session() as session:
response = session.send(signed_request, timeout=(10, 100), verify=True, allow_redirects=False)
print("HTTP", response.status_code)
print(response.text)
response.raise_for_status()Go
Save as main.go and run go run main.go in a Go module with the signing SDK dependency configured:
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"os"
"time"
"github.com/mtlab/api/signer"
)
func main() {
if err := run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func run() error {
ak, sk := os.Getenv("MEITU_OPENAPI_ACCESS_KEY"), os.Getenv("MEITU_OPENAPI_SECRET_KEY")
if ak == "" || sk == "" {
return fmt.Errorf("missing AK/SK")
}
method, endpoint, body := http.MethodPost, "https://openapi.meitu.com/api/v1/sdk/sync/push", ""
switch os.Getenv("MEITU_OPENAPI_ACTION") {
case "", "push":
filename := os.Getenv("MEITU_REQUEST_FILE")
if filename == "" {
filename = "request.json"
}
raw, err := os.ReadFile(filename)
if err != nil {
return err
}
var payload map[string]interface{}
if err = json.Unmarshal(raw, &payload); err != nil {
return err
}
params, ok := payload["params"].(string)
if !ok || !json.Valid([]byte(params)) {
return fmt.Errorf("params must be a JSON string")
}
body = string(raw)
case "status":
taskID := os.Getenv("MEITU_TASK_ID")
if taskID == "" {
return fmt.Errorf("missing task_id")
}
method = http.MethodGet
endpoint = "https://openapi.meitu.com/api/v1/sdk/status?" + url.Values{"task_id": {taskID}}.Encode()
default:
return fmt.Errorf("MEITU_OPENAPI_ACTION must be push or status")
}
headers := make(http.Header)
headers.Set("Content-Type", "application/json")
headers.Set(signer.HeaderHost, "openapi.meitu.com")
req, err := signer.NewSigner(ak, sk).Sign(endpoint, method, headers, body)
if err != nil {
return err
}
client := &http.Client{Timeout: 100 * time.Second, CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }}
resp, err := client.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
raw, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
fmt.Println("HTTP", resp.StatusCode)
fmt.Println(string(raw))
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return fmt.Errorf("HTTP request failed")
}
return nil
}PHP
Place the official signer.php in the same directory, save as client.php, and run php client.php:
<?php
require_once __DIR__ . '/signer.php';
$ak = getenv('MEITU_OPENAPI_ACCESS_KEY');
$sk = getenv('MEITU_OPENAPI_SECRET_KEY');
if (!$ak || !$sk) { throw new RuntimeException('Missing AK/SK'); }
$action = getenv('MEITU_OPENAPI_ACTION') ?: 'push';
$body = '';
if ($action === 'push') {
$file = getenv('MEITU_REQUEST_FILE') ?: 'request.json';
$body = file_get_contents($file);
if ($body === false) { throw new RuntimeException('Cannot read request.json'); }
$payload = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
if (!isset($payload['params']) || !is_string($payload['params'])) { throw new RuntimeException('params must be a JSON string'); }
json_decode($payload['params'], true, 512, JSON_THROW_ON_ERROR);
$method = 'POST';
$url = 'https://openapi.meitu.com/api/v1/sdk/sync/push';
} elseif ($action === 'status') {
$taskId = getenv('MEITU_TASK_ID');
if (!$taskId) { throw new RuntimeException('Missing task_id'); }
$method = 'GET';
$url = 'https://openapi.meitu.com/api/v1/sdk/status?' . http_build_query(['task_id' => $taskId], '', '&', PHP_QUERY_RFC3986);
} else {
throw new RuntimeException('MEITU_OPENAPI_ACTION must be push or status');
}
$headers = ['Content-Type' => 'application/json', 'Host' => 'openapi.meitu.com'];
$curl = (new Signer($ak, $sk))->sign($url, $method, $headers, $body);
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 100,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
]);
$response = curl_exec($curl);
if ($response === false) {
$error = curl_error($curl);
curl_close($curl);
throw new RuntimeException($error);
}
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
echo 'HTTP ' . $status . PHP_EOL . $response . PHP_EOL;
if ($status < 200 || $status >= 300) { throw new RuntimeException('HTTP request failed'); }Java
Add the official SDK to the classpath, save as Main.java, and compile and run with JDK 11+. Encode request.json as UTF-8:
import com.meitu.openai.common.Signer;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
public class Main {
private static String requiredEnv(String name) {
String value = System.getenv(name);
if (value == null || value.isBlank()) throw new IllegalArgumentException("Missing " + name);
return value;
}
public static void main(String[] args) throws Exception {
String ak = requiredEnv("MEITU_OPENAPI_ACCESS_KEY");
String sk = requiredEnv("MEITU_OPENAPI_SECRET_KEY");
String action = System.getenv().getOrDefault("MEITU_OPENAPI_ACTION", "push");
String method;
String url;
String body = "";
if ("push".equals(action)) {
String filename = System.getenv().getOrDefault("MEITU_REQUEST_FILE", "request.json");
body = Files.readString(Path.of(filename), StandardCharsets.UTF_8);
method = "POST";
url = "https://openapi.meitu.com/api/v1/sdk/sync/push";
} else if ("status".equals(action)) {
method = "GET";
url = "https://openapi.meitu.com/api/v1/sdk/status?task_id="
+ URLEncoder.encode(requiredEnv("MEITU_TASK_ID"), StandardCharsets.UTF_8);
} else {
throw new IllegalArgumentException("MEITU_OPENAPI_ACTION must be push or status");
}
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
headers.put(Signer.HeaderHost, "openapi.meitu.com");
Map<String, String> signedHeaders = new Signer(ak, sk).sign(url, method, headers, body);
HttpURLConnection connection = (HttpURLConnection) URI.create(url).toURL().openConnection();
try {
connection.setRequestMethod(method);
connection.setConnectTimeout(10000);
connection.setReadTimeout(100000);
connection.setInstanceFollowRedirects(false);
for (Map.Entry<String, String> header : signedHeaders.entrySet()) connection.setRequestProperty(header.getKey(), header.getValue());
if ("POST".equals(method)) {
byte[] bytes = body.getBytes(StandardCharsets.UTF_8);
connection.setDoOutput(true);
connection.setFixedLengthStreamingMode(bytes.length);
try (OutputStream output = connection.getOutputStream()) { output.write(bytes); }
}
int status = connection.getResponseCode();
System.out.println("HTTP " + status);
InputStream stream = status >= 400 ? connection.getErrorStream() : connection.getInputStream();
if (stream != null) {
try (InputStream input = stream) { System.out.println(new String(input.readAllBytes(), StandardCharsets.UTF_8)); }
}
if (status < 200 || status >= 300) throw new IllegalStateException("HTTP request failed");
} finally {
connection.disconnect();
}
}
}Request Examples
See Request Parameters for types, required fields, and prefilled values. Each example supplies one input image and serializes params as a JSON string.
Use the Prefilled Requirements
Send the capability page's prefilled requirement explicitly: a black high-neck short-sleeved top. Save the following complete request as request.json and replace the input image URL before running the language examples:
{
"task": "meituhub_workflow_9486_v1",
"task_type": "cozeflow",
"init_images": [
{
"url": "https://example.com/input.jpg",
"profile": {
"version": "v1",
"media_profiles": {
"media_data_type": "url"
}
}
}
],
"params": "{\"prompt_1\":\"黑色高领短袖\"}",
"sync_timeout": 30
}Customize Additional Requirements
Change prompt_1 as needed, for example to specify a white shirt and a black blazer:
{
"task": "meituhub_workflow_9486_v1",
"task_type": "cozeflow",
"init_images": [
{
"url": "https://example.com/input.jpg",
"profile": {
"version": "v1",
"media_profiles": {
"media_data_type": "url"
}
}
}
],
"params": "{\"prompt_1\":\"White shirt with a black blazer\"}",
"sync_timeout": 30
}Omit Additional Requirements
Omit the optional prompt_1 field while keeping params as a string:
{
"task": "meituhub_workflow_9486_v1",
"task_type": "cozeflow",
"init_images": [
{
"url": "https://example.com/input.jpg",
"profile": {
"version": "v1",
"media_profiles": {
"media_data_type": "url"
}
}
}
],
"params": "{}",
"sync_timeout": 30
}