from magic_hour import Client
from os import getenv
client = Client(token=getenv("MAGIC_HOUR_API_KEY"))
res = client.v1.character_replace.generate(
assets={
"image_file_path": "/path/to/5678.png",
"video_file_path": "/path/to/1234.mp4",
},
end_seconds=5.0,
model="wan-animate",
name="My Character Replace video",
resolution="480p",
start_seconds=0.0,
style={"mode": "replace", "selection_mode": "auto"},
wait_for_completion=True,
download_outputs=True,
download_directory="."
)import { Client } from "magic-hour";
const client = new Client({ token: process.env["MAGIC_HOUR_API_KEY"] });
const res = await client.v1.characterReplace.generate(
{
assets: {
imageFilePath: "/path/to/5678.png",
videoFilePath: "/path/to/1234.mp4",
},
endSeconds: 5.0,
name: "My Character Replace video",
resolution: "480p",
startSeconds: 0.0,
style: { mode: "replace", selectionMode: "auto" },
},
{
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"
character_replace "github.com/magichourhq/magic-hour-go/resources/v1/character_replace"
types "github.com/magichourhq/magic-hour-go/types"
)
func main() {
client := sdk.NewClient(
sdk.WithBearerAuth(os.Getenv("MAGIC_HOUR_API_KEY")),
)
res, err := client.V1.CharacterReplace.Create(character_replace.CreateRequest{
Assets: types.V1CharacterReplaceCreateBodyAssets{
ImageFilePath: "api-assets/id/5678.png",
VideoFilePath: "api-assets/id/1234.mp4",
},
EndSeconds: 5.0,
Model: nullable.NewValue(types.V1CharacterReplaceCreateBodyModelEnumWanAnimate),
Name: nullable.NewValue("My Character Replace video"),
Resolution: nullable.NewValue(types.V1CharacterReplaceCreateBodyResolutionEnum480p),
StartSeconds: nullable.NewValue(0.0),
Style: nullable.NewValue(types.V1CharacterReplaceCreateBodyStyle{
Mode: nullable.NewValue(types.V1CharacterReplaceCreateBodyStyleModeEnumReplace),
SelectionMode: nullable.NewValue(types.V1CharacterReplaceCreateBodyStyleSelectionModeEnumAuto),
}),
})
}let client = magic_hour::Client::default()
.with_bearer_auth(&std::env::var("MAGIC_HOUR_API_KEY").unwrap());
let res = client
.v1()
.character_replace()
.create(magic_hour::resources::v1::character_replace::CreateRequest {
assets: magic_hour::models::V1CharacterReplaceCreateBodyAssets {
image_file_path: "api-assets/id/5678.png".to_string(),
video_file_path: "api-assets/id/1234.mp4".to_string(),
},
end_seconds: 5.0,
model: Some(
magic_hour::models::V1CharacterReplaceCreateBodyModelEnum::WanAnimate,
),
name: Some("My Character Replace video".to_string()),
resolution: Some(
magic_hour::models::V1CharacterReplaceCreateBodyResolutionEnum::Enum480p,
),
start_seconds: Some(0.0),
style: Some(magic_hour::models::V1CharacterReplaceCreateBodyStyle {
mode: Some(
magic_hour::models::V1CharacterReplaceCreateBodyStyleModeEnum::Replace,
),
selection_mode: Some(
magic_hour::models::V1CharacterReplaceCreateBodyStyleSelectionModeEnum::Auto,
),
..Default::default()
}),
})
.await;curl --request POST \
--url https://api.magichour.ai/v1/character-replace \
--header 'accept: application/json' \
--header "authorization: Bearer $MAGIC_HOUR_API_KEY" \
--header 'content-type: application/json' \
--data '
{
"name": "My Character Replace video",
"start_seconds": 0,
"end_seconds": 5,
"model": "wan-animate",
"resolution": "480p",
"assets": {
"video_file_path": "api-assets/id/1234.mp4",
"image_file_path": "api-assets/id/5678.png"
},
"style": {
"mode": "replace",
"selection_mode": "auto"
}
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.magichour.ai/v1/character-replace",
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 Character Replace video',
'start_seconds' => 0,
'end_seconds' => 5,
'model' => 'wan-animate',
'resolution' => '480p',
'assets' => [
'video_file_path' => 'api-assets/id/1234.mp4',
'image_file_path' => 'api-assets/id/5678.png'
],
'style' => [
'mode' => 'replace',
'selection_mode' => 'auto'
]
]),
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/character-replace")
.header("accept", "application/json")
.header("content-type", "application/json")
.header("authorization", "Bearer <token>")
.body("{\"name\":\"My Character Replace video\",\"start_seconds\":0,\"end_seconds\":5,\"model\":\"wan-animate\",\"resolution\":\"480p\",\"assets\":{\"video_file_path\":\"api-assets/id/1234.mp4\",\"image_file_path\":\"api-assets/id/5678.png\"},\"style\":{\"mode\":\"replace\",\"selection_mode\":\"auto\"}}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.magichour.ai/v1/character-replace")
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 \"end_seconds\": 5,\n \"assets\": {\n \"video_file_path\": \"api-assets/id/1234.mp4\",\n \"image_file_path\": \"api-assets/id/5678.png\"\n },\n \"name\": \"My Character Replace video\",\n \"start_seconds\": 0,\n \"model\": \"wan-animate\",\n \"resolution\": \"480p\",\n \"style\": {\n \"mode\": \"replace\",\n \"selection_mode\": \"auto\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "cuid-example",
"credits_charged": 450
}{
"code": "invalid_request",
"message": "<string>"
}{
"code": "unauthorized",
"message": "<string>"
}{
"code": "insufficient_credits",
"message": "<string>",
"credit_shortfall": 123,
"credits_available": 123,
"credits_required": 123,
"next_action": {
"type": "check_balance",
"reason": "auto_reload_pending"
}
}{
"code": "not_found",
"message": "<string>"
}{
"code": "unprocessable_entity",
"message": "<string>"
}{
"code": "internal_server_error",
"message": "<string>"
}Character Replace
What this API does
Create the same Character Replace you can make in the browser, but programmatically, so you can automate it, run it at scale, or connect it to your own app or workflow.
Good for
- Automation and batch processing
- Adding character replace into apps, pipelines, or tools
How it works (3 steps)
- Upload your inputs (video, image, or audio) with Generate Upload URLs and copy the
file_path. - Send a request to create a character replace job with the basic fields.
- Check the job status until it’s
complete, then download the result fromdownloads.
Key options
- Inputs: usually a file, sometimes a YouTube link, depending on project type
- Resolution: output size and plan requirements vary by workflow and model. Some workflows derive output size from the input video.
- Extra fields: e.g.
face_swap_mode,start_seconds/end_seconds, or a text prompt
Cost
Credits are charged when the job is queued (credits_charged in the response). Tools billed per frame charge an estimate and settle to the frames that actually render once the job finishes; tools billed per second charge the final amount upfront. Failed jobs are refunded.
For detailed examples, see the product page.
from magic_hour import Client
from os import getenv
client = Client(token=getenv("MAGIC_HOUR_API_KEY"))
res = client.v1.character_replace.generate(
assets={
"image_file_path": "/path/to/5678.png",
"video_file_path": "/path/to/1234.mp4",
},
end_seconds=5.0,
model="wan-animate",
name="My Character Replace video",
resolution="480p",
start_seconds=0.0,
style={"mode": "replace", "selection_mode": "auto"},
wait_for_completion=True,
download_outputs=True,
download_directory="."
)import { Client } from "magic-hour";
const client = new Client({ token: process.env["MAGIC_HOUR_API_KEY"] });
const res = await client.v1.characterReplace.generate(
{
assets: {
imageFilePath: "/path/to/5678.png",
videoFilePath: "/path/to/1234.mp4",
},
endSeconds: 5.0,
name: "My Character Replace video",
resolution: "480p",
startSeconds: 0.0,
style: { mode: "replace", selectionMode: "auto" },
},
{
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"
character_replace "github.com/magichourhq/magic-hour-go/resources/v1/character_replace"
types "github.com/magichourhq/magic-hour-go/types"
)
func main() {
client := sdk.NewClient(
sdk.WithBearerAuth(os.Getenv("MAGIC_HOUR_API_KEY")),
)
res, err := client.V1.CharacterReplace.Create(character_replace.CreateRequest{
Assets: types.V1CharacterReplaceCreateBodyAssets{
ImageFilePath: "api-assets/id/5678.png",
VideoFilePath: "api-assets/id/1234.mp4",
},
EndSeconds: 5.0,
Model: nullable.NewValue(types.V1CharacterReplaceCreateBodyModelEnumWanAnimate),
Name: nullable.NewValue("My Character Replace video"),
Resolution: nullable.NewValue(types.V1CharacterReplaceCreateBodyResolutionEnum480p),
StartSeconds: nullable.NewValue(0.0),
Style: nullable.NewValue(types.V1CharacterReplaceCreateBodyStyle{
Mode: nullable.NewValue(types.V1CharacterReplaceCreateBodyStyleModeEnumReplace),
SelectionMode: nullable.NewValue(types.V1CharacterReplaceCreateBodyStyleSelectionModeEnumAuto),
}),
})
}let client = magic_hour::Client::default()
.with_bearer_auth(&std::env::var("MAGIC_HOUR_API_KEY").unwrap());
let res = client
.v1()
.character_replace()
.create(magic_hour::resources::v1::character_replace::CreateRequest {
assets: magic_hour::models::V1CharacterReplaceCreateBodyAssets {
image_file_path: "api-assets/id/5678.png".to_string(),
video_file_path: "api-assets/id/1234.mp4".to_string(),
},
end_seconds: 5.0,
model: Some(
magic_hour::models::V1CharacterReplaceCreateBodyModelEnum::WanAnimate,
),
name: Some("My Character Replace video".to_string()),
resolution: Some(
magic_hour::models::V1CharacterReplaceCreateBodyResolutionEnum::Enum480p,
),
start_seconds: Some(0.0),
style: Some(magic_hour::models::V1CharacterReplaceCreateBodyStyle {
mode: Some(
magic_hour::models::V1CharacterReplaceCreateBodyStyleModeEnum::Replace,
),
selection_mode: Some(
magic_hour::models::V1CharacterReplaceCreateBodyStyleSelectionModeEnum::Auto,
),
..Default::default()
}),
})
.await;curl --request POST \
--url https://api.magichour.ai/v1/character-replace \
--header 'accept: application/json' \
--header "authorization: Bearer $MAGIC_HOUR_API_KEY" \
--header 'content-type: application/json' \
--data '
{
"name": "My Character Replace video",
"start_seconds": 0,
"end_seconds": 5,
"model": "wan-animate",
"resolution": "480p",
"assets": {
"video_file_path": "api-assets/id/1234.mp4",
"image_file_path": "api-assets/id/5678.png"
},
"style": {
"mode": "replace",
"selection_mode": "auto"
}
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.magichour.ai/v1/character-replace",
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 Character Replace video',
'start_seconds' => 0,
'end_seconds' => 5,
'model' => 'wan-animate',
'resolution' => '480p',
'assets' => [
'video_file_path' => 'api-assets/id/1234.mp4',
'image_file_path' => 'api-assets/id/5678.png'
],
'style' => [
'mode' => 'replace',
'selection_mode' => 'auto'
]
]),
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/character-replace")
.header("accept", "application/json")
.header("content-type", "application/json")
.header("authorization", "Bearer <token>")
.body("{\"name\":\"My Character Replace video\",\"start_seconds\":0,\"end_seconds\":5,\"model\":\"wan-animate\",\"resolution\":\"480p\",\"assets\":{\"video_file_path\":\"api-assets/id/1234.mp4\",\"image_file_path\":\"api-assets/id/5678.png\"},\"style\":{\"mode\":\"replace\",\"selection_mode\":\"auto\"}}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.magichour.ai/v1/character-replace")
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 \"end_seconds\": 5,\n \"assets\": {\n \"video_file_path\": \"api-assets/id/1234.mp4\",\n \"image_file_path\": \"api-assets/id/5678.png\"\n },\n \"name\": \"My Character Replace video\",\n \"start_seconds\": 0,\n \"model\": \"wan-animate\",\n \"resolution\": \"480p\",\n \"style\": {\n \"mode\": \"replace\",\n \"selection_mode\": \"auto\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "cuid-example",
"credits_charged": 450
}{
"code": "invalid_request",
"message": "<string>"
}{
"code": "unauthorized",
"message": "<string>"
}{
"code": "insufficient_credits",
"message": "<string>",
"credit_shortfall": 123,
"credits_available": 123,
"credits_required": 123,
"next_action": {
"type": "check_balance",
"reason": "auto_reload_pending"
}
}{
"code": "not_found",
"message": "<string>"
}{
"code": "unprocessable_entity",
"message": "<string>"
}{
"code": "internal_server_error",
"message": "<string>"
}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".
Headers
A unique string for this request, such as a UUID. Sending the same key again within 24 hours returns the original project instead of creating and charging for a new one. A key applies across all video, image, and audio endpoints on your account, so use a new key for every project.
"5f3c1b9e-8a41-4a0e-9d3e-2f6a1c7b9e10"
Body
Body
Model to use. Defaults to wan-animate.
wan-animate: 480p, 720p. Supportspointssubject selection.kling-3.0: 720p, 1080p. Clips of 3–30 seconds inanimatemode or 3–10 seconds inreplacemode. Picks the main person automatically, sopointsare rejected.kling-4.0: 720p, 1080p. Clips of 3–30 seconds inreplacemode. Picks the main person automatically, sopointsare rejected.minimax-h3: 480p, 720p, 1080p. Clips of 1–60 seconds inanimatemode or 1–30 seconds inreplacemode. Subjectpointsarereplace-only;animatewithselection_modepointreturns 422, and withautoor noselection_modethe points are ignored.
wan-animate, kling-3.0, kling-4.0, minimax-h3 "wan-animate"
Response
Success
Success
Unique ID of the video. Use it with the Get video Project API to fetch status and downloads.
"cuid-example"
The amount of credits deducted from your account to generate the video. If the status is not 'complete', this value is an estimate and may be adjusted upon completion based on the actual FPS of the output video.
If video generation fails, credits will be refunded, and this field will be updated to include the refund.
450
Was this page helpful?