Change Clothes AI API 文档
2025-05-28
Posted byChange Clothes AI API 文档
简介与应用场景
Change Clothes AI API 让开发者可以通过简单的 API 调用,将虚拟服装轻松叠加到模特图片上。非常适用于电商、虚拟试衣、时尚搭配和内容创作等场景。无论是为用户提供在线试衣体验,还是帮助内容创作者批量生成服装搭配图片,该 API 都能极大提升效率和用户体验。
常见应用场景
- 电商平台提供虚拟试衣,提升转化率
- 时尚搭配类 App 生成穿搭预览
- 内容创作者批量生成服装组合图片
- 时装设计师预览新服装设计效果
- AI 虚拟形象或虚拟角色换装
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 参数
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
modelImg | string 或 file | 是 | 模特图片。支持三种输入格式: 1. 图片 URL,以 http:// 或 https:// 开头。 2. Base64 编码图片,格式如:data:image/jpeg;base64,/9j/4AAQSkZJR...(注意:也支持 PNG 等其他图片类型,请相应调整 mime-type) 3. 文件对象:图片文件对象。 |
garmentImg | string 或 file | 是 | 服装图片。支持与 modelImg 相同的三种输入格式。 |
category | string | 是 | 服装类别,枚举值: upper_body, lower_body, dresses |
garmentDesc | string | 否 | 可选,服装英文描述 |
响应 JSON 格式
字段 | 类型 | 说明 |
---|---|---|
code | number | 响应状态码。200 表示成功。 |
msg | string | 响应信息,提供额外说明 |
data | object | 响应数据对象,code 为 200 时返回 |
data.resultImgUrl | string | 结果图片的 URL |
data.maskImgUrl | string | 带有修复遮罩的模特图片 URL |
data.cacheHit | boolean | 如果命中预设模特和服装图片的缓存则为 true。 仅对预设模特和预设服装缓存 |
响应码说明
码值 | 信息 | 说明 |
---|---|---|
200 | OK | 请求成功 |
500 | SERVER_ERROR | 服务器内部错误 |
10001 | NOT_LOGIN | 用户未登录 |
10002 | USER_NOT_EXIST | 用户不存在 |
10003 | INSUFFICIENT_CREDITS | 积分不足 |
10004 | INVALID_PARAM | 参数无效 |
10005 | HARMFUL_CONTENT | 检测到有害内容 |
10006 | INSUFFICIENT_TRAIL_COUNT | 试用次数已用尽 |
20001 | TRY_ON_EXCEPTION | 处理异常 |
30001 | INVALID_API_KEY | API 密钥无效 |
30002 | INVALID_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 参数
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
modelImg | string 或 file | 是 | 模特图片。支持三种输入格式: 1. 图片 URL,以 http:// 或 https:// 开头。 2. Base64 编码图片,格式如:data:image/jpeg;base64,/9j/4AAQSkZJR...(注意:也支持 PNG 等其他图片类型,请相应调整 mime-type) 3. 文件对象:图片文件对象。 |
prompt | string | 是 | 换装描述词(英文)。 例如:Help the model change into a blue striped shirt. |
seed | string | 否 | AI 生成过程的种子,范围 0 到 2147483647。可选参数,若 randomize_seed 为 true 则会被覆盖。 |
randomize_seed | string | 否 | 是否生成随机种子,枚举值:true, false。 |
guidance_scale | string | 否 | prompt 影响权重,数值型,范围 1-100,数值越大权重越高。可选,默认 50。仅建议有需要时调整此参数 |
num_inference_steps | string | 否 | 图像生成迭代步数,数值型,范围 1-50。可选,默认 28,仅建议有需要时调整此参数 |
响应 JSON 格式
字段 | 类型 | 说明 |
---|---|---|
code | number | 响应状态码。200 表示成功。 |
msg | string | 响应信息,提供额外说明 |
data | object | 响应数据对象,code 为 200 时返回 |
data.resultImgUrl | string | 结果图片的 URL |
data.seed | number | 生成图片的种子 |
响应码说明
码值 | 信息 | 说明 |
---|---|---|
200 | OK | 请求成功 |
500 | SERVER_ERROR | 服务器内部错误 |
10001 | NOT_LOGIN | 用户未登录 |
10002 | USER_NOT_EXIST | 用户不存在 |
10003 | INSUFFICIENT_CREDITS | 积分不足 |
10004 | INVALID_PARAM | 参数无效 |
10005 | HARMFUL_CONTENT | 检测到有害内容 |
10006 | INSUFFICIENT_TRAIL_COUNT | 试用次数已用尽 |
20001 | TRY_ON_EXCEPTION | 处理异常 |
30001 | INVALID_API_KEY | API 密钥无效 |
30002 | INVALID_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 调用会消耗你账户的积分。你可以在我们的定价页面购买积分。
帮助与支持
如有任何疑问或需要帮助,请随时联系我们的支持团队。