from magic_hour import Client
from os import getenv
client = Client(token=getenv("MAGIC_HOUR_API_KEY"))
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=5.0,
fps=12.0,
height=512,
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["MAGIC_HOUR_API_KEY"] });
const res = await client.v1.animation.generate(
{
assets: {
audioFilePath: "/path/to/1234.mp3",
audioSource: "file",
imageFilePath: "/path/to/1234.png",
},
endSeconds: 5.0,
fps: 12.0,
height: 512,
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("MAGIC_HOUR_API_KEY")),
)
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: 5.0,
Fps: 12.0,
Height: 512,
Name: nullable.NewValue("My Animation video"),
Style: types.V1AnimationCreateBodyStyle{
ArtStyle: types.V1AnimationCreateBodyStyleArtStyleEnumPainterlyIllustration,
ArtStyleCustom: nullable.NewValue("Watercolor painting with soft pastel colors"),
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("MAGIC_HOUR_API_KEY").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: 5.0,
fps: 12.0,
height: 512,
name: Some("My Animation video".to_string()),
style: magic_hour::models::V1AnimationCreateBodyStyle {
art_style: magic_hour::models::V1AnimationCreateBodyStyleArtStyleEnum::PainterlyIllustration,
art_style_custom: Some(
"Watercolor painting with soft pastel colors".to_string(),
),
camera_effect: magic_hour::models::V1AnimationCreateBodyStyleCameraEffectEnum::SimpleZoomIn,
prompt: Some("Cyberpunk city".to_string()),
prompt_type: magic_hour::models::V1AnimationCreateBodyStylePromptTypeEnum::Custom,
transition_speed: 5,
},
width: 512,
})
.await;curl --request POST \
--url https://api.magichour.ai/v1/animation \
--header 'accept: application/json' \
--header "authorization: Bearer $MAGIC_HOUR_API_KEY" \
--header 'content-type: application/json' \
--data '
{
"name": "My Animation video",
"fps": 12,
"end_seconds": 5,
"height": 512,
"width": 512,
"style": {
"art_style": "Painterly Illustration",
"art_style_custom": "Watercolor painting with soft pastel colors",
"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",
"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' => 5,
'height' => 512,
'width' => 512,
'style' => [
'art_style' => 'Painterly Illustration',
'art_style_custom' => 'Watercolor painting with soft pastel colors',
'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',
'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\":5,\"height\":512,\"width\":512,\"style\":{\"art_style\":\"Painterly Illustration\",\"art_style_custom\":\"Watercolor painting with soft pastel colors\",\"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\",\"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\": 5,\n \"height\": 512,\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\": \"Watercolor painting with soft pastel colors\",\n \"prompt\": \"Cyberpunk city\"\n },\n \"assets\": {\n \"audio_source\": \"file\",\n \"audio_file_path\": \"api-assets/id/1234.mp3\",\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
}{
"code": "invalid_request",
"message": "<string>"
}{
"code": "unauthorized",
"message": "<string>"
}{
"code": "insufficient_credits",
"message": "<string>"
}{
"code": "not_found",
"message": "<string>"
}{
"code": "unprocessable_entity",
"message": "<string>"
}{
"code": "internal_server_error",
"message": "<string>"
}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("MAGIC_HOUR_API_KEY"))
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=5.0,
fps=12.0,
height=512,
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["MAGIC_HOUR_API_KEY"] });
const res = await client.v1.animation.generate(
{
assets: {
audioFilePath: "/path/to/1234.mp3",
audioSource: "file",
imageFilePath: "/path/to/1234.png",
},
endSeconds: 5.0,
fps: 12.0,
height: 512,
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("MAGIC_HOUR_API_KEY")),
)
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: 5.0,
Fps: 12.0,
Height: 512,
Name: nullable.NewValue("My Animation video"),
Style: types.V1AnimationCreateBodyStyle{
ArtStyle: types.V1AnimationCreateBodyStyleArtStyleEnumPainterlyIllustration,
ArtStyleCustom: nullable.NewValue("Watercolor painting with soft pastel colors"),
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("MAGIC_HOUR_API_KEY").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: 5.0,
fps: 12.0,
height: 512,
name: Some("My Animation video".to_string()),
style: magic_hour::models::V1AnimationCreateBodyStyle {
art_style: magic_hour::models::V1AnimationCreateBodyStyleArtStyleEnum::PainterlyIllustration,
art_style_custom: Some(
"Watercolor painting with soft pastel colors".to_string(),
),
camera_effect: magic_hour::models::V1AnimationCreateBodyStyleCameraEffectEnum::SimpleZoomIn,
prompt: Some("Cyberpunk city".to_string()),
prompt_type: magic_hour::models::V1AnimationCreateBodyStylePromptTypeEnum::Custom,
transition_speed: 5,
},
width: 512,
})
.await;curl --request POST \
--url https://api.magichour.ai/v1/animation \
--header 'accept: application/json' \
--header "authorization: Bearer $MAGIC_HOUR_API_KEY" \
--header 'content-type: application/json' \
--data '
{
"name": "My Animation video",
"fps": 12,
"end_seconds": 5,
"height": 512,
"width": 512,
"style": {
"art_style": "Painterly Illustration",
"art_style_custom": "Watercolor painting with soft pastel colors",
"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",
"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' => 5,
'height' => 512,
'width' => 512,
'style' => [
'art_style' => 'Painterly Illustration',
'art_style_custom' => 'Watercolor painting with soft pastel colors',
'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',
'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\":5,\"height\":512,\"width\":512,\"style\":{\"art_style\":\"Painterly Illustration\",\"art_style_custom\":\"Watercolor painting with soft pastel colors\",\"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\",\"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\": 5,\n \"height\": 512,\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\": \"Watercolor painting with soft pastel colors\",\n \"prompt\": \"Cyberpunk city\"\n },\n \"assets\": {\n \"audio_source\": \"file\",\n \"audio_file_path\": \"api-assets/id/1234.mp3\",\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
}{
"code": "invalid_request",
"message": "<string>"
}{
"code": "unauthorized",
"message": "<string>"
}{
"code": "insufficient_credits",
"message": "<string>"
}{
"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".
Body
Body
The height of the final output video. The maximum height depends on your subscription. Please refer to our pricing page for more details
x >= 64512
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
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?