Python
from magic_hour import Client
from os import getenv
client = Client(token=getenv("API_TOKEN"))
res = client.v1.ai_clothes_changer.generate(
assets={
"garment_file_path": "/path/to/outfit.png",
"garment_type": "upper_body",
"person_file_path": "/path/to/model.png",
},
name="Clothes Changer image",
wait_for_completion=True,
download_outputs=True,
download_directory=".",
)import { Client } from "magic-hour";
const client = new Client({ token: process.env["API_TOKEN"]!! });
const res = await client.v1.aiClothesChanger.generate(
{
assets: {
garmentFilePath: "/path/to/outfit.png",
garmentType: "upper_body",
personFilePath: "/path/to/model.png",
},
name: "Clothes Changer image",
},
{
waitForCompletion: true,
downloadOutputs: true,
downloadDirectory: ".",
},
);package main
import (
os "os"
sdk "github.com/magichourhq/magic-hour-go/client"
nullable "github.com/magichourhq/magic-hour-go/nullable"
ai_clothes_changer "github.com/magichourhq/magic-hour-go/resources/v1/ai_clothes_changer"
types "github.com/magichourhq/magic-hour-go/types"
)
func main() {
client := sdk.NewClient(
sdk.WithBearerAuth(os.Getenv("API_TOKEN")),
)
res, err := client.V1.AiClothesChanger.Create(ai_clothes_changer.CreateRequest{
Assets: types.V1AiClothesChangerCreateBodyAssets{
GarmentFilePath: "api-assets/id/outfit.png",
GarmentType: nullable.NewValue(types.V1AiClothesChangerCreateBodyAssetsGarmentTypeEnumEntireOutfit),
PersonFilePath: "api-assets/id/model.png",
},
Name: nullable.NewValue("My Clothes Changer image"),
})
}let client = magic_hour::Client::default()
.with_bearer_auth(&std::env::var("API_TOKEN").unwrap());
let res = client
.v1()
.ai_clothes_changer()
.create(magic_hour::resources::v1::ai_clothes_changer::CreateRequest {
assets: magic_hour::models::V1AiClothesChangerCreateBodyAssets {
garment_file_path: "api-assets/id/outfit.png".to_string(),
garment_type: Some(
magic_hour::models::V1AiClothesChangerCreateBodyAssetsGarmentTypeEnum::EntireOutfit,
),
person_file_path: "api-assets/id/model.png".to_string(),
},
name: Some("My Clothes Changer image".to_string()),
})
.await;curl --request POST \
--url https://api.magichour.ai/v1/ai-clothes-changer \
--header 'accept: application/json' \
--header 'authorization: Bearer <token>' \
--header 'content-type: application/json' \
--data '
{
"name": "My Clothes Changer image",
"assets": {
"person_file_path": "api-assets/id/model.png",
"garment_file_path": "api-assets/id/outfit.png",
"garment_type": "entire_outfit"
}
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.magichour.ai/v1/ai-clothes-changer",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'My Clothes Changer image',
'assets' => [
'person_file_path' => 'api-assets/id/model.png',
'garment_file_path' => 'api-assets/id/outfit.png',
'garment_type' => 'entire_outfit'
]
]),
CURLOPT_HTTPHEADER => [
"accept: application/json",
"authorization: Bearer <token>",
"content-type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.magichour.ai/v1/ai-clothes-changer")
.header("accept", "application/json")
.header("content-type", "application/json")
.header("authorization", "Bearer <token>")
.body("{\"name\":\"My Clothes Changer image\",\"assets\":{\"person_file_path\":\"api-assets/id/model.png\",\"garment_file_path\":\"api-assets/id/outfit.png\",\"garment_type\":\"entire_outfit\"}}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.magichour.ai/v1/ai-clothes-changer")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"assets\": {\n \"person_file_path\": \"api-assets/id/model.png\",\n \"garment_file_path\": \"api-assets/id/outfit.png\",\n \"garment_type\": \"entire_outfit\"\n },\n \"name\": \"My Clothes Changer image\"\n}"
response = http.request(request)
puts response.read_body{
"id": "cuid-example",
"credits_charged": 25
}{
"message": "Missing request body"
}{
"message": "Unauthorized"
}{
"message": "Payment required"
}{
"message": "Not Found"
}{
"message": "Unable to create image"
}Image Projects
AI Clothes Changer API Reference - Magic Hour Docs
Change outfits in photos in seconds with just a photo reference. Each photo costs 25 credits.
POST
/
v1
/
ai-clothes-changer
Python
from magic_hour import Client
from os import getenv
client = Client(token=getenv("API_TOKEN"))
res = client.v1.ai_clothes_changer.generate(
assets={
"garment_file_path": "/path/to/outfit.png",
"garment_type": "upper_body",
"person_file_path": "/path/to/model.png",
},
name="Clothes Changer image",
wait_for_completion=True,
download_outputs=True,
download_directory=".",
)import { Client } from "magic-hour";
const client = new Client({ token: process.env["API_TOKEN"]!! });
const res = await client.v1.aiClothesChanger.generate(
{
assets: {
garmentFilePath: "/path/to/outfit.png",
garmentType: "upper_body",
personFilePath: "/path/to/model.png",
},
name: "Clothes Changer image",
},
{
waitForCompletion: true,
downloadOutputs: true,
downloadDirectory: ".",
},
);package main
import (
os "os"
sdk "github.com/magichourhq/magic-hour-go/client"
nullable "github.com/magichourhq/magic-hour-go/nullable"
ai_clothes_changer "github.com/magichourhq/magic-hour-go/resources/v1/ai_clothes_changer"
types "github.com/magichourhq/magic-hour-go/types"
)
func main() {
client := sdk.NewClient(
sdk.WithBearerAuth(os.Getenv("API_TOKEN")),
)
res, err := client.V1.AiClothesChanger.Create(ai_clothes_changer.CreateRequest{
Assets: types.V1AiClothesChangerCreateBodyAssets{
GarmentFilePath: "api-assets/id/outfit.png",
GarmentType: nullable.NewValue(types.V1AiClothesChangerCreateBodyAssetsGarmentTypeEnumEntireOutfit),
PersonFilePath: "api-assets/id/model.png",
},
Name: nullable.NewValue("My Clothes Changer image"),
})
}let client = magic_hour::Client::default()
.with_bearer_auth(&std::env::var("API_TOKEN").unwrap());
let res = client
.v1()
.ai_clothes_changer()
.create(magic_hour::resources::v1::ai_clothes_changer::CreateRequest {
assets: magic_hour::models::V1AiClothesChangerCreateBodyAssets {
garment_file_path: "api-assets/id/outfit.png".to_string(),
garment_type: Some(
magic_hour::models::V1AiClothesChangerCreateBodyAssetsGarmentTypeEnum::EntireOutfit,
),
person_file_path: "api-assets/id/model.png".to_string(),
},
name: Some("My Clothes Changer image".to_string()),
})
.await;curl --request POST \
--url https://api.magichour.ai/v1/ai-clothes-changer \
--header 'accept: application/json' \
--header 'authorization: Bearer <token>' \
--header 'content-type: application/json' \
--data '
{
"name": "My Clothes Changer image",
"assets": {
"person_file_path": "api-assets/id/model.png",
"garment_file_path": "api-assets/id/outfit.png",
"garment_type": "entire_outfit"
}
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.magichour.ai/v1/ai-clothes-changer",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'My Clothes Changer image',
'assets' => [
'person_file_path' => 'api-assets/id/model.png',
'garment_file_path' => 'api-assets/id/outfit.png',
'garment_type' => 'entire_outfit'
]
]),
CURLOPT_HTTPHEADER => [
"accept: application/json",
"authorization: Bearer <token>",
"content-type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.magichour.ai/v1/ai-clothes-changer")
.header("accept", "application/json")
.header("content-type", "application/json")
.header("authorization", "Bearer <token>")
.body("{\"name\":\"My Clothes Changer image\",\"assets\":{\"person_file_path\":\"api-assets/id/model.png\",\"garment_file_path\":\"api-assets/id/outfit.png\",\"garment_type\":\"entire_outfit\"}}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.magichour.ai/v1/ai-clothes-changer")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"assets\": {\n \"person_file_path\": \"api-assets/id/model.png\",\n \"garment_file_path\": \"api-assets/id/outfit.png\",\n \"garment_type\": \"entire_outfit\"\n },\n \"name\": \"My Clothes Changer image\"\n}"
response = http.request(request)
puts response.read_body{
"id": "cuid-example",
"credits_charged": 25
}{
"message": "Missing request body"
}{
"message": "Unauthorized"
}{
"message": "Payment required"
}{
"message": "Not Found"
}{
"message": "Unable to create image"
}Authorizations
Bearer authentication header of the form Bearer <api_key>, where <api_key> is your API key. To get your API key, go to Developer Hub and click "Create new API Key".
Body
application/json
Body
Response
Success
Success
Unique ID of the image. Use it with the Get image Project API to fetch status and downloads.
Example:
"cuid-example"
The amount of credits deducted from your account to generate the image. We charge credits right when the request is made.
If an error occurred while generating the image(s), credits will be refunded and this field will be updated to include the refund.
Example:
25
Was this page helpful?
⌘I