Python
from magic_hour import Client
from os import getenv
client = Client(token=getenv("API_TOKEN"))
res = client.v1.face_swap_photo.generate(
assets={
"face_mappings": [
{
"new_face": "/path/to/1234.png",
"original_face": "api-assets/id/0-0.png",
}
],
"face_swap_mode": "all-faces",
"source_file_path": "/path/to/1234.png",
"target_file_path": "/path/to/1234.png",
},
name="Face Swap 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.faceSwapPhoto.generate(
{
assets: {
faceMappings: [
{
newFace: "api-assets/id/1234.png",
originalFace: "api-assets/id/0-0.png",
},
],
faceSwapMode: "all-faces",
sourceFilePath: "/path/to/1234.png",
targetFilePath: "/path/to/1234.png",
},
name: "Face Swap 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"
face_swap_photo "github.com/magichourhq/magic-hour-go/resources/v1/face_swap_photo"
types "github.com/magichourhq/magic-hour-go/types"
)
func main() {
client := sdk.NewClient(
sdk.WithBearerAuth(os.Getenv("API_TOKEN")),
)
res, err := client.V1.FaceSwapPhoto.Create(face_swap_photo.CreateRequest{
Assets: types.V1FaceSwapPhotoCreateBodyAssets{
FaceMappings: nullable.NewValue([]types.V1FaceSwapPhotoCreateBodyAssetsFaceMappingsItem{
types.V1FaceSwapPhotoCreateBodyAssetsFaceMappingsItem{
NewFace: "api-assets/id/1234.png",
OriginalFace: "api-assets/id/0-0.png",
},
}),
FaceSwapMode: nullable.NewValue(types.V1FaceSwapPhotoCreateBodyAssetsFaceSwapModeEnumAllFaces),
SourceFilePath: nullable.NewValue("api-assets/id/1234.png"),
TargetFilePath: "api-assets/id/1234.png",
},
Name: nullable.NewValue("My Face Swap image"),
})
}let client = magic_hour::Client::default()
.with_bearer_auth(&std::env::var("API_TOKEN").unwrap());
let res = client
.v1()
.face_swap_photo()
.create(magic_hour::resources::v1::face_swap_photo::CreateRequest {
assets: magic_hour::models::V1FaceSwapPhotoCreateBodyAssets {
face_mappings: Some(
vec![
magic_hour::models::V1FaceSwapPhotoCreateBodyAssetsFaceMappingsItem
{ new_face : "api-assets/id/1234.png".to_string(), original_face
: "api-assets/id/0-0.png".to_string() }
],
),
face_swap_mode: Some(
magic_hour::models::V1FaceSwapPhotoCreateBodyAssetsFaceSwapModeEnum::AllFaces,
),
source_file_path: Some("api-assets/id/1234.png".to_string()),
target_file_path: "api-assets/id/1234.png".to_string(),
},
name: Some("My Face Swap image".to_string()),
})
.await;curl --request POST \
--url https://api.magichour.ai/v1/face-swap-photo \
--header 'accept: application/json' \
--header 'authorization: Bearer <token>' \
--header 'content-type: application/json' \
--data '
{
"name": "My Face Swap image",
"assets": {
"face_swap_mode": "all-faces",
"source_file_path": "api-assets/id/1234.png",
"face_mappings": [
{
"original_face": "api-assets/id/0-0.png",
"new_face": "api-assets/id/1234.png"
}
],
"target_file_path": "api-assets/id/1234.png"
}
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.magichour.ai/v1/face-swap-photo",
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 Face Swap image',
'assets' => [
'face_swap_mode' => 'all-faces',
'source_file_path' => 'api-assets/id/1234.png',
'face_mappings' => [
[
'original_face' => 'api-assets/id/0-0.png',
'new_face' => 'api-assets/id/1234.png'
]
],
'target_file_path' => 'api-assets/id/1234.png'
]
]),
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/face-swap-photo")
.header("accept", "application/json")
.header("content-type", "application/json")
.header("authorization", "Bearer <token>")
.body("{\"name\":\"My Face Swap image\",\"assets\":{\"face_swap_mode\":\"all-faces\",\"source_file_path\":\"api-assets/id/1234.png\",\"face_mappings\":[{\"original_face\":\"api-assets/id/0-0.png\",\"new_face\":\"api-assets/id/1234.png\"}],\"target_file_path\":\"api-assets/id/1234.png\"}}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.magichour.ai/v1/face-swap-photo")
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 \"target_file_path\": \"api-assets/id/1234.png\",\n \"face_swap_mode\": \"all-faces\",\n \"source_file_path\": \"api-assets/id/1234.png\",\n \"face_mappings\": [\n {\n \"original_face\": \"api-assets/id/0-0.png\",\n \"new_face\": \"api-assets/id/1234.png\"\n }\n ]\n },\n \"name\": \"My Face Swap image\"\n}"
response = http.request(request)
puts response.read_body{
"id": "cuid-example",
"credits_charged": 10
}{
"message": "Missing request body"
}{
"message": "Unauthorized"
}{
"message": "Payment required"
}{
"message": "Not Found"
}{
"message": "Unable to create image"
}Image Projects
Face Swap Photo API Reference - Magic Hour Docs
Create a face swap photo. Each photo costs 10 credits. The height/width of the output image depends on your subscription. Please refer to our pricing page for more details
POST
/
v1
/
face-swap-photo
Python
from magic_hour import Client
from os import getenv
client = Client(token=getenv("API_TOKEN"))
res = client.v1.face_swap_photo.generate(
assets={
"face_mappings": [
{
"new_face": "/path/to/1234.png",
"original_face": "api-assets/id/0-0.png",
}
],
"face_swap_mode": "all-faces",
"source_file_path": "/path/to/1234.png",
"target_file_path": "/path/to/1234.png",
},
name="Face Swap 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.faceSwapPhoto.generate(
{
assets: {
faceMappings: [
{
newFace: "api-assets/id/1234.png",
originalFace: "api-assets/id/0-0.png",
},
],
faceSwapMode: "all-faces",
sourceFilePath: "/path/to/1234.png",
targetFilePath: "/path/to/1234.png",
},
name: "Face Swap 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"
face_swap_photo "github.com/magichourhq/magic-hour-go/resources/v1/face_swap_photo"
types "github.com/magichourhq/magic-hour-go/types"
)
func main() {
client := sdk.NewClient(
sdk.WithBearerAuth(os.Getenv("API_TOKEN")),
)
res, err := client.V1.FaceSwapPhoto.Create(face_swap_photo.CreateRequest{
Assets: types.V1FaceSwapPhotoCreateBodyAssets{
FaceMappings: nullable.NewValue([]types.V1FaceSwapPhotoCreateBodyAssetsFaceMappingsItem{
types.V1FaceSwapPhotoCreateBodyAssetsFaceMappingsItem{
NewFace: "api-assets/id/1234.png",
OriginalFace: "api-assets/id/0-0.png",
},
}),
FaceSwapMode: nullable.NewValue(types.V1FaceSwapPhotoCreateBodyAssetsFaceSwapModeEnumAllFaces),
SourceFilePath: nullable.NewValue("api-assets/id/1234.png"),
TargetFilePath: "api-assets/id/1234.png",
},
Name: nullable.NewValue("My Face Swap image"),
})
}let client = magic_hour::Client::default()
.with_bearer_auth(&std::env::var("API_TOKEN").unwrap());
let res = client
.v1()
.face_swap_photo()
.create(magic_hour::resources::v1::face_swap_photo::CreateRequest {
assets: magic_hour::models::V1FaceSwapPhotoCreateBodyAssets {
face_mappings: Some(
vec![
magic_hour::models::V1FaceSwapPhotoCreateBodyAssetsFaceMappingsItem
{ new_face : "api-assets/id/1234.png".to_string(), original_face
: "api-assets/id/0-0.png".to_string() }
],
),
face_swap_mode: Some(
magic_hour::models::V1FaceSwapPhotoCreateBodyAssetsFaceSwapModeEnum::AllFaces,
),
source_file_path: Some("api-assets/id/1234.png".to_string()),
target_file_path: "api-assets/id/1234.png".to_string(),
},
name: Some("My Face Swap image".to_string()),
})
.await;curl --request POST \
--url https://api.magichour.ai/v1/face-swap-photo \
--header 'accept: application/json' \
--header 'authorization: Bearer <token>' \
--header 'content-type: application/json' \
--data '
{
"name": "My Face Swap image",
"assets": {
"face_swap_mode": "all-faces",
"source_file_path": "api-assets/id/1234.png",
"face_mappings": [
{
"original_face": "api-assets/id/0-0.png",
"new_face": "api-assets/id/1234.png"
}
],
"target_file_path": "api-assets/id/1234.png"
}
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.magichour.ai/v1/face-swap-photo",
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 Face Swap image',
'assets' => [
'face_swap_mode' => 'all-faces',
'source_file_path' => 'api-assets/id/1234.png',
'face_mappings' => [
[
'original_face' => 'api-assets/id/0-0.png',
'new_face' => 'api-assets/id/1234.png'
]
],
'target_file_path' => 'api-assets/id/1234.png'
]
]),
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/face-swap-photo")
.header("accept", "application/json")
.header("content-type", "application/json")
.header("authorization", "Bearer <token>")
.body("{\"name\":\"My Face Swap image\",\"assets\":{\"face_swap_mode\":\"all-faces\",\"source_file_path\":\"api-assets/id/1234.png\",\"face_mappings\":[{\"original_face\":\"api-assets/id/0-0.png\",\"new_face\":\"api-assets/id/1234.png\"}],\"target_file_path\":\"api-assets/id/1234.png\"}}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.magichour.ai/v1/face-swap-photo")
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 \"target_file_path\": \"api-assets/id/1234.png\",\n \"face_swap_mode\": \"all-faces\",\n \"source_file_path\": \"api-assets/id/1234.png\",\n \"face_mappings\": [\n {\n \"original_face\": \"api-assets/id/0-0.png\",\n \"new_face\": \"api-assets/id/1234.png\"\n }\n ]\n },\n \"name\": \"My Face Swap image\"\n}"
response = http.request(request)
puts response.read_body{
"id": "cuid-example",
"credits_charged": 10
}{
"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:
10
Was this page helpful?
⌘I