from magic_hour import Client
from os import getenv
client = Client(token=getenv("API_TOKEN"))
res = client.v1.head_swap.generate(
assets={
"body_file_path": "/path/to/body.png",
"head_file_path": "/path/to/head.png",
},
max_resolution=1024,
name="My Head 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.headSwap.create({
assets: {
bodyFilePath: "api-assets/id/1234.png",
headFilePath: "api-assets/id/5678.png",
},
maxResolution: 1024,
name: "My Head Swap image",
});package main
import (
os "os"
sdk "github.com/magichourhq/magic-hour-go/client"
nullable "github.com/magichourhq/magic-hour-go/nullable"
head_swap "github.com/magichourhq/magic-hour-go/resources/v1/head_swap"
types "github.com/magichourhq/magic-hour-go/types"
)
func main() {
client := sdk.NewClient(
sdk.WithBearerAuth(os.Getenv("API_TOKEN")),
)
res, err := client.V1.HeadSwap.Create(head_swap.CreateRequest{
Assets: types.V1HeadSwapCreateBodyAssets{
BodyFilePath: "api-assets/id/1234.png",
HeadFilePath: "api-assets/id/5678.png",
},
MaxResolution: nullable.NewValue(1024),
Name: nullable.NewValue("My Head Swap image"),
})
}let client = magic_hour::Client::default()
.with_bearer_auth(&std::env::var("API_TOKEN").unwrap());
let res = client
.v1()
.head_swap()
.create(magic_hour::resources::v1::head_swap::CreateRequest {
assets: magic_hour::models::V1HeadSwapCreateBodyAssets {
body_file_path: "api-assets/id/1234.png".to_string(),
head_file_path: "api-assets/id/5678.png".to_string(),
},
max_resolution: Some(1024),
name: Some("My Head Swap image".to_string()),
})
.await;curl --request POST \
--url https://api.magichour.ai/v1/head-swap \
--header 'accept: application/json' \
--header 'authorization: Bearer <token>' \
--header 'content-type: application/json' \
--data '
{
"name": "My Head Swap image",
"max_resolution": 1024,
"assets": {
"body_file_path": "api-assets/id/1234.png",
"head_file_path": "api-assets/id/5678.png"
}
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.magichour.ai/v1/head-swap",
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 Head Swap image',
'max_resolution' => 1024,
'assets' => [
'body_file_path' => 'api-assets/id/1234.png',
'head_file_path' => 'api-assets/id/5678.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/head-swap")
.header("accept", "application/json")
.header("content-type", "application/json")
.header("authorization", "Bearer <token>")
.body("{\"name\":\"My Head Swap image\",\"max_resolution\":1024,\"assets\":{\"body_file_path\":\"api-assets/id/1234.png\",\"head_file_path\":\"api-assets/id/5678.png\"}}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.magichour.ai/v1/head-swap")
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 \"body_file_path\": \"api-assets/id/1234.png\",\n \"head_file_path\": \"api-assets/id/5678.png\"\n },\n \"name\": \"My Head Swap image\",\n \"max_resolution\": 1024\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"
}Head Swap API Reference - Magic Hour Docs
Swap a head onto a body image. Each image costs 10 credits. Output resolution depends on your subscription; you may set max_resolution lower than your plan maximum if desired.
from magic_hour import Client
from os import getenv
client = Client(token=getenv("API_TOKEN"))
res = client.v1.head_swap.generate(
assets={
"body_file_path": "/path/to/body.png",
"head_file_path": "/path/to/head.png",
},
max_resolution=1024,
name="My Head 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.headSwap.create({
assets: {
bodyFilePath: "api-assets/id/1234.png",
headFilePath: "api-assets/id/5678.png",
},
maxResolution: 1024,
name: "My Head Swap image",
});package main
import (
os "os"
sdk "github.com/magichourhq/magic-hour-go/client"
nullable "github.com/magichourhq/magic-hour-go/nullable"
head_swap "github.com/magichourhq/magic-hour-go/resources/v1/head_swap"
types "github.com/magichourhq/magic-hour-go/types"
)
func main() {
client := sdk.NewClient(
sdk.WithBearerAuth(os.Getenv("API_TOKEN")),
)
res, err := client.V1.HeadSwap.Create(head_swap.CreateRequest{
Assets: types.V1HeadSwapCreateBodyAssets{
BodyFilePath: "api-assets/id/1234.png",
HeadFilePath: "api-assets/id/5678.png",
},
MaxResolution: nullable.NewValue(1024),
Name: nullable.NewValue("My Head Swap image"),
})
}let client = magic_hour::Client::default()
.with_bearer_auth(&std::env::var("API_TOKEN").unwrap());
let res = client
.v1()
.head_swap()
.create(magic_hour::resources::v1::head_swap::CreateRequest {
assets: magic_hour::models::V1HeadSwapCreateBodyAssets {
body_file_path: "api-assets/id/1234.png".to_string(),
head_file_path: "api-assets/id/5678.png".to_string(),
},
max_resolution: Some(1024),
name: Some("My Head Swap image".to_string()),
})
.await;curl --request POST \
--url https://api.magichour.ai/v1/head-swap \
--header 'accept: application/json' \
--header 'authorization: Bearer <token>' \
--header 'content-type: application/json' \
--data '
{
"name": "My Head Swap image",
"max_resolution": 1024,
"assets": {
"body_file_path": "api-assets/id/1234.png",
"head_file_path": "api-assets/id/5678.png"
}
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.magichour.ai/v1/head-swap",
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 Head Swap image',
'max_resolution' => 1024,
'assets' => [
'body_file_path' => 'api-assets/id/1234.png',
'head_file_path' => 'api-assets/id/5678.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/head-swap")
.header("accept", "application/json")
.header("content-type", "application/json")
.header("authorization", "Bearer <token>")
.body("{\"name\":\"My Head Swap image\",\"max_resolution\":1024,\"assets\":{\"body_file_path\":\"api-assets/id/1234.png\",\"head_file_path\":\"api-assets/id/5678.png\"}}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.magichour.ai/v1/head-swap")
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 \"body_file_path\": \"api-assets/id/1234.png\",\n \"head_file_path\": \"api-assets/id/5678.png\"\n },\n \"name\": \"My Head Swap image\",\n \"max_resolution\": 1024\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
Body
Provide the body and head images for head swap
Show child attributes
Show child attributes
Give your image a custom name for easy identification.
"My Head Swap image"
Constrains the larger dimension (height or width) of the output. Omit to use the maximum allowed for your plan (capped at 2048px). Values above your plan maximum are clamped down to your plan's maximum.
1024
Response
Success
Success
Unique ID of the image. Use it with the Get image Project API to fetch status and downloads.
"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.
10
Was this page helpful?