from magic_hour import Client
from os import getenv
client = Client(token=getenv("API_TOKEN"))
res = client.v1.animation.generate(
assets={
"audio_file_path": "/path/to/1234.mp3",
"audio_source": "file",
"image_file_path": "/path/to/1234.png",
},
end_seconds=15.0,
fps=12.0,
height=960,
style={
"art_style": "Painterly Illustration",
"camera_effect": "Simple Zoom In",
"prompt": "Cyberpunk city",
"prompt_type": "custom",
"transition_speed": 5,
},
width=512,
name="Animation video",
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.animation.generate(
{
assets: {
audioFilePath: "/path/to/1234.mp3",
audioSource: "file",
imageFilePath: "/path/to/1234.png",
},
endSeconds: 15.0,
fps: 12.0,
height: 960,
name: "Animation video",
style: {
artStyle: "Painterly Illustration",
cameraEffect: "Simple Zoom In",
prompt: "Cyberpunk city",
promptType: "custom",
transitionSpeed: 5,
},
width: 512,
},
{
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"
animation "github.com/magichourhq/magic-hour-go/resources/v1/animation"
types "github.com/magichourhq/magic-hour-go/types"
)
func main() {
client := sdk.NewClient(
sdk.WithBearerAuth(os.Getenv("API_TOKEN")),
)
res, err := client.V1.Animation.Create(animation.CreateRequest{
Assets: types.V1AnimationCreateBodyAssets{
AudioFilePath: nullable.NewValue("api-assets/id/1234.mp3"),
AudioSource: types.V1AnimationCreateBodyAssetsAudioSourceEnumFile,
ImageFilePath: nullable.NewValue("api-assets/id/1234.png"),
},
EndSeconds: 15.0,
Fps: 12.0,
Height: 960,
Name: nullable.NewValue("My Animation video"),
Style: types.V1AnimationCreateBodyStyle{
ArtStyle: types.V1AnimationCreateBodyStyleArtStyleEnumPainterlyIllustration,
CameraEffect: types.V1AnimationCreateBodyStyleCameraEffectEnumSimpleZoomIn,
Prompt: nullable.NewValue("Cyberpunk city"),
PromptType: types.V1AnimationCreateBodyStylePromptTypeEnumCustom,
TransitionSpeed: 5,
},
Width: 512,
})
}let client = magic_hour::Client::default()
.with_bearer_auth(&std::env::var("API_TOKEN").unwrap());
let res = client
.v1()
.animation()
.create(magic_hour::resources::v1::animation::CreateRequest {
assets: magic_hour::models::V1AnimationCreateBodyAssets {
audio_file_path: Some("api-assets/id/1234.mp3".to_string()),
audio_source: magic_hour::models::V1AnimationCreateBodyAssetsAudioSourceEnum::File,
image_file_path: Some("api-assets/id/1234.png".to_string()),
..Default::default()
},
end_seconds: 15.0,
fps: 12.0,
height: 960,
name: Some("My Animation video".to_string()),
style: magic_hour::models::V1AnimationCreateBodyStyle {
art_style: magic_hour::models::V1AnimationCreateBodyStyleArtStyleEnum::PainterlyIllustration,
camera_effect: magic_hour::models::V1AnimationCreateBodyStyleCameraEffectEnum::SimpleZoomIn,
prompt: Some("Cyberpunk city".to_string()),
prompt_type: magic_hour::models::V1AnimationCreateBodyStylePromptTypeEnum::Custom,
transition_speed: 5,
..Default::default()
},
width: 512,
})
.await;curl --request POST \
--url https://api.magichour.ai/v1/animation \
--header 'accept: application/json' \
--header 'authorization: Bearer <token>' \
--header 'content-type: application/json' \
--data '
{
"name": "My Animation video",
"fps": 12,
"end_seconds": 15,
"height": 960,
"width": 512,
"style": {
"art_style": "Painterly Illustration",
"art_style_custom": "string",
"camera_effect": "Simple Zoom In",
"prompt_type": "custom",
"prompt": "Cyberpunk city",
"transition_speed": 5
},
"assets": {
"audio_source": "file",
"audio_file_path": "api-assets/id/1234.mp3",
"youtube_url": "string",
"image_file_path": "api-assets/id/1234.png"
}
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.magichour.ai/v1/animation",
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 Animation video',
'fps' => 12,
'end_seconds' => 15,
'height' => 960,
'width' => 512,
'style' => [
'art_style' => 'Painterly Illustration',
'art_style_custom' => 'string',
'camera_effect' => 'Simple Zoom In',
'prompt_type' => 'custom',
'prompt' => 'Cyberpunk city',
'transition_speed' => 5
],
'assets' => [
'audio_source' => 'file',
'audio_file_path' => 'api-assets/id/1234.mp3',
'youtube_url' => 'string',
'image_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/animation")
.header("accept", "application/json")
.header("content-type", "application/json")
.header("authorization", "Bearer <token>")
.body("{\"name\":\"My Animation video\",\"fps\":12,\"end_seconds\":15,\"height\":960,\"width\":512,\"style\":{\"art_style\":\"Painterly Illustration\",\"art_style_custom\":\"string\",\"camera_effect\":\"Simple Zoom In\",\"prompt_type\":\"custom\",\"prompt\":\"Cyberpunk city\",\"transition_speed\":5},\"assets\":{\"audio_source\":\"file\",\"audio_file_path\":\"api-assets/id/1234.mp3\",\"youtube_url\":\"string\",\"image_file_path\":\"api-assets/id/1234.png\"}}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.magichour.ai/v1/animation")
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 \"fps\": 12,\n \"end_seconds\": 15,\n \"height\": 960,\n \"width\": 512,\n \"style\": {\n \"art_style\": \"Painterly Illustration\",\n \"camera_effect\": \"Simple Zoom In\",\n \"prompt_type\": \"custom\",\n \"transition_speed\": 5,\n \"art_style_custom\": \"<string>\",\n \"prompt\": \"Cyberpunk city\"\n },\n \"assets\": {\n \"audio_source\": \"file\",\n \"audio_file_path\": \"api-assets/id/1234.mp3\",\n \"youtube_url\": \"<string>\",\n \"image_file_path\": \"api-assets/id/1234.png\"\n },\n \"name\": \"My Animation video\"\n}"
response = http.request(request)
puts response.read_body{
"id": "cuid-example",
"credits_charged": 450
}{
"message": "Missing request body"
}{
"message": "Unauthorized"
}{
"message": "Payment required"
}{
"message": "Not Found"
}{
"message": "Unable to create video"
}Animation API Reference - Magic Hour Docs
Create a Animation video. The estimated frame cost is calculated based on the fps and end_seconds input.
from magic_hour import Client
from os import getenv
client = Client(token=getenv("API_TOKEN"))
res = client.v1.animation.generate(
assets={
"audio_file_path": "/path/to/1234.mp3",
"audio_source": "file",
"image_file_path": "/path/to/1234.png",
},
end_seconds=15.0,
fps=12.0,
height=960,
style={
"art_style": "Painterly Illustration",
"camera_effect": "Simple Zoom In",
"prompt": "Cyberpunk city",
"prompt_type": "custom",
"transition_speed": 5,
},
width=512,
name="Animation video",
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.animation.generate(
{
assets: {
audioFilePath: "/path/to/1234.mp3",
audioSource: "file",
imageFilePath: "/path/to/1234.png",
},
endSeconds: 15.0,
fps: 12.0,
height: 960,
name: "Animation video",
style: {
artStyle: "Painterly Illustration",
cameraEffect: "Simple Zoom In",
prompt: "Cyberpunk city",
promptType: "custom",
transitionSpeed: 5,
},
width: 512,
},
{
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"
animation "github.com/magichourhq/magic-hour-go/resources/v1/animation"
types "github.com/magichourhq/magic-hour-go/types"
)
func main() {
client := sdk.NewClient(
sdk.WithBearerAuth(os.Getenv("API_TOKEN")),
)
res, err := client.V1.Animation.Create(animation.CreateRequest{
Assets: types.V1AnimationCreateBodyAssets{
AudioFilePath: nullable.NewValue("api-assets/id/1234.mp3"),
AudioSource: types.V1AnimationCreateBodyAssetsAudioSourceEnumFile,
ImageFilePath: nullable.NewValue("api-assets/id/1234.png"),
},
EndSeconds: 15.0,
Fps: 12.0,
Height: 960,
Name: nullable.NewValue("My Animation video"),
Style: types.V1AnimationCreateBodyStyle{
ArtStyle: types.V1AnimationCreateBodyStyleArtStyleEnumPainterlyIllustration,
CameraEffect: types.V1AnimationCreateBodyStyleCameraEffectEnumSimpleZoomIn,
Prompt: nullable.NewValue("Cyberpunk city"),
PromptType: types.V1AnimationCreateBodyStylePromptTypeEnumCustom,
TransitionSpeed: 5,
},
Width: 512,
})
}let client = magic_hour::Client::default()
.with_bearer_auth(&std::env::var("API_TOKEN").unwrap());
let res = client
.v1()
.animation()
.create(magic_hour::resources::v1::animation::CreateRequest {
assets: magic_hour::models::V1AnimationCreateBodyAssets {
audio_file_path: Some("api-assets/id/1234.mp3".to_string()),
audio_source: magic_hour::models::V1AnimationCreateBodyAssetsAudioSourceEnum::File,
image_file_path: Some("api-assets/id/1234.png".to_string()),
..Default::default()
},
end_seconds: 15.0,
fps: 12.0,
height: 960,
name: Some("My Animation video".to_string()),
style: magic_hour::models::V1AnimationCreateBodyStyle {
art_style: magic_hour::models::V1AnimationCreateBodyStyleArtStyleEnum::PainterlyIllustration,
camera_effect: magic_hour::models::V1AnimationCreateBodyStyleCameraEffectEnum::SimpleZoomIn,
prompt: Some("Cyberpunk city".to_string()),
prompt_type: magic_hour::models::V1AnimationCreateBodyStylePromptTypeEnum::Custom,
transition_speed: 5,
..Default::default()
},
width: 512,
})
.await;curl --request POST \
--url https://api.magichour.ai/v1/animation \
--header 'accept: application/json' \
--header 'authorization: Bearer <token>' \
--header 'content-type: application/json' \
--data '
{
"name": "My Animation video",
"fps": 12,
"end_seconds": 15,
"height": 960,
"width": 512,
"style": {
"art_style": "Painterly Illustration",
"art_style_custom": "string",
"camera_effect": "Simple Zoom In",
"prompt_type": "custom",
"prompt": "Cyberpunk city",
"transition_speed": 5
},
"assets": {
"audio_source": "file",
"audio_file_path": "api-assets/id/1234.mp3",
"youtube_url": "string",
"image_file_path": "api-assets/id/1234.png"
}
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.magichour.ai/v1/animation",
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 Animation video',
'fps' => 12,
'end_seconds' => 15,
'height' => 960,
'width' => 512,
'style' => [
'art_style' => 'Painterly Illustration',
'art_style_custom' => 'string',
'camera_effect' => 'Simple Zoom In',
'prompt_type' => 'custom',
'prompt' => 'Cyberpunk city',
'transition_speed' => 5
],
'assets' => [
'audio_source' => 'file',
'audio_file_path' => 'api-assets/id/1234.mp3',
'youtube_url' => 'string',
'image_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/animation")
.header("accept", "application/json")
.header("content-type", "application/json")
.header("authorization", "Bearer <token>")
.body("{\"name\":\"My Animation video\",\"fps\":12,\"end_seconds\":15,\"height\":960,\"width\":512,\"style\":{\"art_style\":\"Painterly Illustration\",\"art_style_custom\":\"string\",\"camera_effect\":\"Simple Zoom In\",\"prompt_type\":\"custom\",\"prompt\":\"Cyberpunk city\",\"transition_speed\":5},\"assets\":{\"audio_source\":\"file\",\"audio_file_path\":\"api-assets/id/1234.mp3\",\"youtube_url\":\"string\",\"image_file_path\":\"api-assets/id/1234.png\"}}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.magichour.ai/v1/animation")
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 \"fps\": 12,\n \"end_seconds\": 15,\n \"height\": 960,\n \"width\": 512,\n \"style\": {\n \"art_style\": \"Painterly Illustration\",\n \"camera_effect\": \"Simple Zoom In\",\n \"prompt_type\": \"custom\",\n \"transition_speed\": 5,\n \"art_style_custom\": \"<string>\",\n \"prompt\": \"Cyberpunk city\"\n },\n \"assets\": {\n \"audio_source\": \"file\",\n \"audio_file_path\": \"api-assets/id/1234.mp3\",\n \"youtube_url\": \"<string>\",\n \"image_file_path\": \"api-assets/id/1234.png\"\n },\n \"name\": \"My Animation video\"\n}"
response = http.request(request)
puts response.read_body{
"id": "cuid-example",
"credits_charged": 450
}{
"message": "Missing request body"
}{
"message": "Unauthorized"
}{
"message": "Payment required"
}{
"message": "Not Found"
}{
"message": "Unable to create video"
}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
The desire output video frame rate
x >= 112
This value determines the duration of the output video.
x >= 0.115
The height of the final output video. The maximum height depends on your subscription. Please refer to our pricing page for more details
x >= 64960
The width of the final output video. The maximum width depends on your subscription. Please refer to our pricing page for more details
x >= 64512
Defines the style of the output video
Show child attributes
Show child attributes
Provide the assets for animation.
Show child attributes
Show child attributes
Give your video a custom name for easy identification.
"My Animation video"
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?