Back to Home

Change Clothes AI API 文档

2025-05-28

Posted by

Change Clothes AI API 文档

简介与应用场景

Change Clothes AI API 让开发者可以通过简单的 API 调用,将虚拟服装轻松叠加到模特图片上。非常适用于电商、虚拟试衣、时尚搭配和内容创作等场景。无论是为用户提供在线试衣体验,还是帮助内容创作者批量生成服装搭配图片,该 API 都能极大提升效率和用户体验。

常见应用场景

  • 电商平台提供虚拟试衣,提升转化率
  • 时尚搭配类 App 生成穿搭预览
  • 内容创作者批量生成服装组合图片
  • 时装设计师预览新服装设计效果
  • AI 虚拟形象或虚拟角色换装

API 密钥

使用我们的 API 需要获取 API 凭证。你可以在控制台管理你的 API 密钥。

管理 API 密钥 →

API 1:通过服装图片换装

要使用此接口,你需要提供模特图片和服装图片。如果没有服装图片,或希望通过文本描述服装,请参见下一个接口。

API 地址

POST https://changeclothesai.online/api/openapi/change-clothes-ai

接入指南

请求头

Header 名称必填说明
content-type必须为 multipart/form-data
authorization必须为 Bearer ${SECRET_KEY}
${SECRET_KEY} 为你的 API 密钥。

请求体 FormData 参数

参数类型必填说明
modelImgstring 或 file模特图片。支持三种输入格式:
1. 图片 URL,以 http:// 或 https:// 开头。
2. Base64 编码图片,格式如:data:image/jpeg;base64,/9j/4AAQSkZJR...(注意:也支持 PNG 等其他图片类型,请相应调整 mime-type)
3. 文件对象:图片文件对象。
garmentImgstring 或 file服装图片。支持与 modelImg 相同的三种输入格式。
categorystring服装类别,枚举值: upper_body, lower_body, dresses
garmentDescstring可选,服装英文描述

响应 JSON 格式

字段类型说明
codenumber响应状态码。200 表示成功。
msgstring响应信息,提供额外说明
dataobject响应数据对象,code 为 200 时返回
data.resultImgUrlstring结果图片的 URL
data.maskImgUrlstring带有修复遮罩的模特图片 URL
data.cacheHitboolean如果命中预设模特和服装图片的缓存则为 true。
仅对预设模特和预设服装缓存
响应码说明
码值信息说明
200OK请求成功
500SERVER_ERROR服务器内部错误
10001NOT_LOGIN用户未登录
10002USER_NOT_EXIST用户不存在
10003INSUFFICIENT_CREDITS积分不足
10004INVALID_PARAM参数无效
10005HARMFUL_CONTENT检测到有害内容
10006INSUFFICIENT_TRAIL_COUNT试用次数已用尽
20001TRY_ON_EXCEPTION处理异常
30001INVALID_API_KEYAPI 密钥无效
30002INVALID_SIGNATURE请求签名无效
响应示例
{
    "code": 200,
    "data":
    {
        "resultImgUrl": "https://persistent.changeclothesai.online/change-clothes-ai/cache/1747493767397255851.webp",
        "maskImgUrl": "https://persistent.changeclothesai.online/change-clothes-ai/cache/1747493770543821630.webp",
        "cacheHit": true
    }
}

代码示例

使用图片 URL 的 Curl 示例

curl --location 'https://changeclothesai.online/api/openapi/change-clothes-ai' \
--header 'Authorization: Bearer ${SECRET_KEY}' \
--form 'garmentImg="https://persistent.changeclothesai.online/change-clothes-ai/assets/examples/garment-tab/dresses/04-01.jpg"' \
--form 'category="dresses"' \
--form 'modelImg="https://persistent.changeclothesai.online/change-clothes-ai/assets/examples/person-tab/women/003.jpg"'

使用本地图片文件的 Curl 示例

curl --location 'https://changeclothesai.online/api/openapi/change-clothes-ai' \
--header 'Authorization: Bearer ${SECRET_KEY}' \
--form 'garmentImg=@"/PATH/TO/YOUR/GARMENT/IMAGE.jpg"' \
--form 'category="dresses"' \
--form 'modelImg=@"/PATH/TO/YOUR/MODEL/IMAGE.png"'

使用 Base64 图片的 Curl 示例

curl --location 'https://changeclothesai.online/api/openapi/change-clothes-ai' \
--header 'Authorization: Bearer ${SECRET_KEY}' \
--form 'garmentImg="data:image/jpeg;base64,/9j……/9k="' \
--form 'category="dresses"' \
--form 'modelImg="data:image/jpeg;base64,/9j……/9k="'

Node.js 示例

async function callChangeClothesApi() {
  const apiKey = 'YOUR_API_KEY'; // Replace with your actual API key

  const formData = new FormData();
  formData.append('modelImg', ...); // Support url, image file, image base64 encode
  formData.append('garmentImg', ...); // Support url, image file, image base64 encode
  formData.append('category', ...); // upper_body, lower_body, dresses
  if (...) { // judge garmentDesc not empty
    formData.append('garmentDesc', ...);
  }

  const apiEndpoint = 'https://changeclothesai.online/api/openapi/change-clothes-ai';
  try {
    const response = await fetch(apiEndpoint, {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${apiKey}`,
      },
      body: formData,
    });

    if (!response.ok) {
      const errorData = await response.json();
      throw new Error(`HTTP error ${response.status}: ${errorData.msg || 'Unknown error'}`);
    }

    const data = await response.json();
    return { resultImgUrl: data.data.resultImgUrl, maskImgUrl: data.data.maskImgUrl, error: null };

  } catch (error) {
    console.error('Error changing clothes:', error);
    return { resultImgUrl: null, maskImgUrl: null, error: error.message };
  }
}

Python 示例


import requests
import base64

async def call_change_clothes_api():
    api_key = 'YOUR_API_KEY'  # Replace with your actual API key

    form_data = {
        'modelImg': 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD...',  # Example base64 image. Replace with your actual image data. Supports url, file, and base64.
        'garmentImg': 'https://example.com/garment.png', # Example url. Supports url, file, and base64.
        'category': 'upper_body',  # upper_body, lower_body, dresses
        'garmentDesc': 'A beautiful red dress' # Example description. Remove this line if garmentDesc is empty
    }

    api_endpoint = 'https://changeclothesai.online/api/openapi/change-clothes-ai'
    try:
        headers = {
            'Authorization': f'Bearer {api_key}',
        }

        response = requests.post(api_endpoint, files=form_data, headers=headers) # Use files= for multipart/form-data
        response.raise_for_status()  # Raise an exception for bad status codes (4xx or 5xx)

        data = response.json()
        return {'resultImgUrl': data.get('data', {}).get('resultImgUrl'), 'maskImgUrl': data.get('data', {}).get('maskImgUrl'), 'error': None}

    except requests.exceptions.RequestException as e:
        print(f'Error changing clothes: {e}')
        return {'resultImgUrl': None, 'maskImgUrl': None, 'error': str(e)}

API 2:通过描述词换装

要使用此接口,你需要提供模特图片和服装描述(prompt)。

API 地址

POST https://changeclothesai.online/api/openapi/change-clothes-by-prompt

接入指南

请求头

Header 名称必填说明
content-type必须为 multipart/form-data
authorization必须为 Bearer ${SECRET_KEY}
${SECRET_KEY} 为你的 API 密钥。

请求体 FormData 参数

参数类型必填说明
modelImgstring 或 file模特图片。支持三种输入格式:
1. 图片 URL,以 http:// 或 https:// 开头。
2. Base64 编码图片,格式如:data:image/jpeg;base64,/9j/4AAQSkZJR...(注意:也支持 PNG 等其他图片类型,请相应调整 mime-type)
3. 文件对象:图片文件对象。
promptstring换装描述词(英文)。
例如:Help the model change into a blue striped shirt.
seedstringAI 生成过程的种子,范围 0 到 2147483647。可选参数,若 randomize_seed 为 true 则会被覆盖。
randomize_seedstring是否生成随机种子,枚举值:true, false。
guidance_scalestringprompt 影响权重,数值型,范围 1-100,数值越大权重越高。可选,默认 50。仅建议有需要时调整此参数
num_inference_stepsstring图像生成迭代步数,数值型,范围 1-50。可选,默认 28,仅建议有需要时调整此参数

响应 JSON 格式

字段类型说明
codenumber响应状态码。200 表示成功。
msgstring响应信息,提供额外说明
dataobject响应数据对象,code 为 200 时返回
data.resultImgUrlstring结果图片的 URL
data.seednumber生成图片的种子
响应码说明
码值信息说明
200OK请求成功
500SERVER_ERROR服务器内部错误
10001NOT_LOGIN用户未登录
10002USER_NOT_EXIST用户不存在
10003INSUFFICIENT_CREDITS积分不足
10004INVALID_PARAM参数无效
10005HARMFUL_CONTENT检测到有害内容
10006INSUFFICIENT_TRAIL_COUNT试用次数已用尽
20001TRY_ON_EXCEPTION处理异常
30001INVALID_API_KEYAPI 密钥无效
30002INVALID_SIGNATURE请求签名无效
响应示例
{
    "code": 200,
    "data":
    {
        "resultImgUrl": "https://r2.changeclothesai.online/1748486113268661990.webp",
        "seed": 627512067
    }
}

代码示例

使用图片 URL 的 Curl 示例

curl --location 'https://changeclothesai.online/api/openapi/change-clothes-by-prompt' \
--header 'Authorization: Bearer ${SECRET_KEY}' \
--form 'modelImg="https://persistent.changeclothesai.online/change-clothes-ai/assets/examples/person-tab/women/003.jpg"' \
--form 'prompt="Help the model change into a blue striped shirt."'

使用本地图片文件的 Curl 示例

# curl with image url
curl --location 'https://changeclothesai.online/api/openapi/change-clothes-by-prompt' \
--header 'Authorization: Bearer ${SECRET_KEY}' \
--form 'modelImg=@"/PATH/TO/YOUR/MODEL/IMAGE.png"' \
--form 'prompt="Help the model change into a blue striped shirt."'

使用 Base64 图片的 Curl 示例

# curl with image url
curl --location 'https://changeclothesai.online/api/openapi/change-clothes-by-prompt' \
--header 'Authorization: Bearer ${SECRET_KEY}' \
--form 'modelImg="data:image/jpeg;base64,/9j……/9k="' \
--form 'prompt="Help the model change into a blue striped shirt."'

Node.js 示例

async function callChangeClothesApi() {
  const apiKey = 'YOUR_API_KEY'; // Replace with your actual API key

  const formData = new FormData();
  formData.append('modelImg', ...); // Support url, image file, image base64 encode
  formData.append('prompt', 'Help the model change into a blue striped shirt.');
  

  const apiEndpoint = 'https://changeclothesai.online/api/openapi/change-clothes-by-prompt';
  try {
    const response = await fetch(apiEndpoint, {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${apiKey}`,
      },
      body: formData,
    });

    if (!response.ok) {
      const errorData = await response.json();
      throw new Error(`HTTP error ${response.status}: ${errorData.msg || 'Unknown error'}`);
    }

    const data = await response.json();
    return { resultImgUrl: data.data.resultImgUrl, seed: data.data.seed };

  } catch (error) {
    console.error('Error changing clothes:', error);
    return { resultImgUrl: null, maskImgUrl: null, error: error.message };
  }
}

Python 示例


import requests
import base64

async def call_change_clothes_api():
    api_key = 'YOUR_API_KEY'  # Replace with your actual API key

    form_data = {
        'modelImg': 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD...',  # Example base64 image. Replace with your actual image data. Supports url, file, and base64.
        'prompt': 'Help the model change into a blue striped shirt.'
    }

    api_endpoint = 'https://changeclothesai.online/api/openapi/change-clothes-by-prompt'
    try:
        headers = {
            'Authorization': f'Bearer {api_key}',
        }

        response = requests.post(api_endpoint, files=form_data, headers=headers) # Use files= for multipart/form-data
        response.raise_for_status()  # Raise an exception for bad status codes (4xx or 5xx)

        data = response.json()
        return {'resultImgUrl': data.get('data', {}).get('resultImgUrl'), 'seed': data.get('data', {}).get('seed')}

    except requests.exceptions.RequestException as e:
        print(f'Error changing clothes: {e}')
        return {'resultImgUrl': None, 'seed': None, 'error': str(e)}

计费说明

API 调用会消耗你账户的积分。你可以在我们的定价页面购买积分。

查看定价 →

帮助与支持

如有任何疑问或需要帮助,请随时联系我们的支持团队。

邮箱:[email protected]