Media Grouping
Description
Analyze a batch of images or videos and group similar assets. Results include asset URLs and group assignments in submission order.
Version
0.0.2
Media Requirements
Submit images or videos using URLs that the service can download.
Request URL
Production environment: https://openapi.meitu.com
Task submission endpoint: https://openapi.meitu.com/api/v1/sdk/sync/pushHTTP Method
POST
Content-Type: application/json
Authentication
Use AK/SK signing.
Request Parameters
| Required | Parameter | Type | Description |
|---|---|---|---|
| Yes | task | string | /v1/Cluster_Salon/497372 |
| Yes | task_type | string | Fixed value: formula. |
| Yes | init_images | object[] | Assets to group. |
| Yes | params | string | Algorithm parameters encoded as a JSON string. |
| No | sync_timeout | integer | The example uses -1 to submit without waiting for results. |
init_images
| Required | Parameter | Type | Description |
|---|---|---|---|
| Yes | url | string | Image or video URL. |
| — | profile | object | Asset properties. |
profile
| Required | Parameter | Type | Description |
|---|---|---|---|
| — | media_profiles | object | The example sets media_data_type to url. |
| No | media_extra | object | Additional asset information. The asset ID is taken from asset_id, then name, then the filename in the URL. |
params
In the example, the decoded params JSON contains the parameter object.
parameter
| Required | Parameter | Type | Default | Description |
|---|---|---|---|---|
| No | service_type | string | hair | Service type. Use hair for hair salon media. |
| No | pipeline | string | v6_production | Grouping mode. Supported values: v6_production and v5_final. |
| No | limit | integer | 0 | Maximum number of assets to process. Must be non-negative. 0 means no limit. |
| No | frames | — | — | Shared frame sample count for v6_production. Omit to use the service default. |
| No | dry_run | boolean | false | Set to true to plan the run without extracting features or assigning groups. |
| No | rsp_media_type | string | url | Response media type. Use url. |
Request Example
Submit two videos for grouping. Replace the asset URLs before calling the API.
{
"task": "/v1/Cluster_Salon/497372",
"task_type": "formula",
"init_images": [
{
"url": "https://example.com/input/clip-01.mp4",
"profile": {
"media_profiles": {
"media_data_type": "url"
}
}
},
{
"url": "https://example.com/input/clip-02.mp4",
"profile": {
"media_profiles": {
"media_data_type": "url"
}
}
}
],
"params": "{\"parameter\":{\"service_type\":\"hair\",\"pipeline\":\"v6_production\",\"dry_run\":false}}",
"sync_timeout": -1
}Response Fields
| Field | Type | Description |
|---|---|---|
| --- | --- | --- |
error_code | integer | Gateway error code. |
message | string | Processing message. |
data.status | integer | Task status. Read the grouping results after the task succeeds. |
data.task_id | string | Gateway task ID used to query the task. |
data.result | object | Task result. |
data.progress | number | Task progress. 1 indicates completion. |
Grouping Result Fields
| Field | Type | Description |
|---|---|---|
parameter | object | Always an empty object ({}). |
media_info_list | object[] | Result assets, in submission order. |
media_info_list | object[] | Result assets in submission order. |
media_info_list[].media_data | string | Result asset URL. |
media_info_list[].media_profiles.media_data_type | string | Always url, indicating media_data is a URL. |
media_info_list[].media_profiles.media_data_type | string | url indicates that media_data is a URL. |
media_info_list[].media_extra.media_profiles.media_data_type | string | Asset format, such as MP4 or JPG. |
media_info_list[].media_extra.media_profiles.media_data_group_id | — | Asset group ID, starting at 1. Omitted when dry_run=true. |
media_info_list[].media_extra.media_profiles.media_data_group_id | — | Group ID, starting at 1. Omitted when dry_run=true. |
Response Example
Response Examples
Algorithm Result Example
Successful Response
Both assets have group ID 1, so they belong to the same group.
Response Status: 200
Content-Type: application/json; charset=utf-8
This example shows grouping results in data.result.data. Both assets have group ID 1, so they belong to the same group. Read group IDs from the individual media items, not the URL list.
{
"error_code": 0,
"message": "success",
"data": {
"status": 10,
"task_id": "example-task-id",
"result": {
"id": "example-task-id",
"urls": [
"https://example.com/result/clip-01.mp4",
"https://example.com/result/clip-02.mp4"
],
"data": {
"parameter": {},
"media_info_list": [
{
"media_data": "https://example.com/result/clip-01.mp4",
"media_extra": {
"media_profiles": {
"media_data_type": "MP4",
"media_data_group_id": 1
}
},
"media_profiles": {
"media_data_type": "url"
"parameter": {},
"media_info_list": [
{
"media_data": "https://example.com/result/clip-01.mp4",
"media_extra": {
"media_profiles": {
"media_data_type": "MP4",
"media_data_group_id": 1
}
},
"media_profiles": {
"media_data_type": "url"
}
},
{
"media_data": "https://example.com/result/clip-02.mp4",
"media_extra": {
"media_profiles": {
"media_data_type": "MP4",
"media_data_group_id": 1
}
},
"media_profiles": {
"media_data_type": "url"
}
}
]
}
},
{
"media_data": "https://example.com/result/clip-02.mp4",
"media_extra": {
"media_profiles": {
"media_data_type": "MP4",
"media_data_group_id": 1
}
"progress": 1
}
},
"media_profiles": {
"media_data_type": "url"
}
}
]
}Task Query
When to Query the Task
If the result is not ready after submission, use the gateway's data.task_id with the Task Query API.
If the task is still pending after submission, pass the gateway's data.task_id to the Task Query API. A synchronous response with data.status = 9 means the wait timed out; it does not mean the task failed.
In the query response, data.status = 0 or 1 means the task is not complete, 10 means it succeeded, and 2 means it failed.
Common Error Codes
See API Error Codes.
SDK Examples
Before making a request, fill in your access and secret keys and replace the asset URLs.
Python
import requests
from sign_sdk import sign
url = "https://openapi.meitu.com/api/v1/sdk/sync/push"
body = r'''{
"task": "/v1/Cluster_Salon/497372",
"task_type": "formula",
"init_images": [
{
"url": "https://example.com/input/clip-01.mp4",
"profile": {
"media_profiles": {
"media_data_type": "url"
}
}
},
{
"url": "https://example.com/input/clip-02.mp4",
"profile": {
"media_profiles": {
"media_data_type": "url"
}
}
}
],
"params": "{\"parameter\":{\"service_type\":\"hair\",\"pipeline\":\"v6_production\",\"dry_run\":false}}",
"sync_timeout": -1
}'''
headers = {sign.HeaderHost: "openapi.meitu.com", "Content-Type": "application/json"}
signer = sign.Signer("YOUR_ACCESS_KEY", "YOUR_SECRET_KEY")
request = signer.sign(url, "POST", headers, body)
with requests.Session() as session:
response = session.send(request, timeout=(10, 60), allow_redirects=False)
print(response.status_code, response.text)Go
package main
import (
"fmt"
"io"
"log"
"net/http"
"time"
"github.com/mtlab/api/signer"
)
func main() {
url := "https://openapi.meitu.com/api/v1/sdk/sync/push"
body := `{
"task": "/v1/Cluster_Salon/497372",
"task_type": "formula",
"init_images": [
{
"url": "https://example.com/input/clip-01.mp4",
"profile": {
"media_profiles": {
"media_data_type": "url"
}
}
},
{
"url": "https://example.com/input/clip-02.mp4",
"profile": {
"media_profiles": {
"media_data_type": "url"
}
}
}
],
"params": "{\"parameter\":{\"service_type\":\"hair\",\"pipeline\":\"v6_production\",\"dry_run\":false}}",
"sync_timeout": -1
}`
headers := make(http.Header)
headers.Set(signer.HeaderHost, "openapi.meitu.com")
headers.Set("Content-Type", "application/json")
s := signer.NewSigner("YOUR_ACCESS_KEY", "YOUR_SECRET_KEY")
req, err := s.Sign(url, http.MethodPost, headers, body)
if err != nil {
log.Fatal(err)
}
client := &http.Client{
Timeout: 60 * time.Second,
CheckRedirect: func(*http.Request, []*http.Request) error {
return http.ErrUseLastResponse
},
}
res, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
defer res.Body.Close()
result, err := io.ReadAll(res.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println(res.StatusCode, string(result))
}PHP
<?php
require_once __DIR__ . '/signer.php';
$url = 'https://openapi.meitu.com/api/v1/sdk/sync/push';
$body = <<<'JSON'
{
"task": "/v1/Cluster_Salon/497372",
"task_type": "formula",
"init_images": [
{
"url": "https://example.com/input/clip-01.mp4",
"profile": {
"media_profiles": {
"media_data_type": "url"
}
}
},
{
"url": "https://example.com/input/clip-02.mp4",
"profile": {
"media_profiles": {
"media_data_type": "url"
}
}
}
],
"params": "{\"parameter\":{\"service_type\":\"hair\",\"pipeline\":\"v6_production\",\"dry_run\":false}}",
"sync_timeout": -1
}
JSON;
$headers = ['Host' => 'openapi.meitu.com', 'Content-Type' => 'application/json'];
$signer = new Signer('YOUR_ACCESS_KEY', 'YOUR_SECRET_KEY');
$curl = $signer->sign($url, 'POST', $headers, $body);
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 60,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
]);
$result = curl_exec($curl);
if ($result === false) {
$error = curl_error($curl);
curl_close($curl);
throw new RuntimeException($error);
}
echo curl_getinfo($curl, CURLINFO_HTTP_CODE), PHP_EOL, $result, PHP_EOL;
curl_close($curl);Java
package com.meitu.openai.common;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
public class Main {
public static void main(String[] args) throws Exception {
String url = "https://openapi.meitu.com/api/v1/sdk/sync/push";
String body = "{\n" +
" \"task\": \"/v1/Cluster_Salon/497372\",\n" +
" \"task_type\": \"formula\",\n" +
" \"init_images\": [\n" +
" {\n" +
" \"url\": \"https://example.com/input/clip-01.mp4\",\n" +
" \"profile\": {\n" +
" \"media_profiles\": {\n" +
" \"media_data_type\": \"url\"\n" +
" }\n" +
" }\n" +
" },\n" +
" {\n" +
" \"url\": \"https://example.com/input/clip-02.mp4\",\n" +
" \"profile\": {\n" +
" \"media_profiles\": {\n" +
" \"media_data_type\": \"url\"\n" +
" }\n" +
" }\n" +
" }\n" +
" ],\n" +
" \"params\": \"{\\\"parameter\\\":{\\\"service_type\\\":\\\"hair\\\",\\\"pipeline\\\":\\\"v6_production\\\",\\\"dry_run\\\":false}}\",\n" +
" \"sync_timeout\": -1\n" +
"}";
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
headers.put(Signer.HeaderHost, "openapi.meitu.com");
Signer signer = new Signer("YOUR_ACCESS_KEY", "YOUR_SECRET_KEY");
Map<String, String> signed = signer.sign(url, "POST", headers, body);
HttpURLConnection connection = (HttpURLConnection) URI.create(url).toURL().openConnection();
try {
connection.setRequestMethod("POST");
connection.setConnectTimeout(10000);
connection.setReadTimeout(60000);
connection.setInstanceFollowRedirects(false);
signed.forEach(connection::setRequestProperty);
connection.setDoOutput(true);
try (OutputStream out = connection.getOutputStream()) {
out.write(body.getBytes(StandardCharsets.UTF_8));
}
int status = connection.getResponseCode();
try (InputStream in = status >= 400 ? connection.getErrorStream() : connection.getInputStream()) {
String result = in == null ? "" : new String(in.readAllBytes(), StandardCharsets.UTF_8);
System.out.println(status + " " + result);
}
} finally {
connection.disconnect();
}
}
}