Magic Hour’s API allows you to upload various types of assets needed for video generation. This guide explains how to manage these assets effectively.

Supported asset types

The follow file extensions are supported by our APIs:

Video

mp4, m4v, mov, webm

Audio

mp3, mpeg, wav, aac, aiff, flac

Image

png, jpg, jpeg, webp, avif, jp2, tiff, bmp

gif extension is only supported by face swap API’s video_file_path field.

Available options for assets

You have two options when it come to using input files:

  • Pass a URL as the input (simplest)
  • Upload to our storage (do not require hosting files yourself)

Passing a file URL

This is the simplest method if you have the files hosted somewhere. When calling our APIs, you can simply pass the URL as the video_file_path, image_file_path, or audio_file_path.

For Example

{
  "assets": {
    "video_file_file": "https://cdn.yourwebsite.com/video.mp4"
  }
}

The URL can be an authenticated url, as long as we can validate the file extension is supported.

Upload to Magic Hour storage

To upload assets for video generation, you’ll need to follow these steps:

  1. Request upload URLs for your assets, you need to specificy the file extension and the type of the file.
  2. Upload the files to the provided URLs by sending a PUT request.
  3. Use the file_path value from the original upload url response in your API calls.

The following code samples provide a full example of how to upload a video file to Magic Hour storage.

from magic_hour import Client
import requests

client = Client(token="YOUR_API_KEY") # change to your API key

response = client.v1.files.upload_urls.create(
    items=[
        {"extension": "mp4", "type": "video"},
        # if you have multiple files to upload, you can request multiple upload urls
        # the order of the response will be in the same order as the request
        # {"extension": "mp3", "type": "audio"},
        # {"extension": "png", "type": "image"},
    ]
)

local_path = "/path/to/file/video.mp4" # change to your local file path
with open(local_path, 'rb') as file:
    response = requests.put(
        response.items[0].upload_url,
        data=file,
        headers={'Content-Type': 'application/octet-stream'}
    )

file_path = response.items[0].file_path

# now you can use `file_path` in your API calls for
# `video_file_path`, `image_file_path`, or `audio_file_path

Make sure to include Content-type: 'application/octet-stream' header in the PUT request.

Uploaded file lifecycle

Uploaded files are automatically cleaned up after 7 days.

You can reference the value in .items.[].file_path in multiple API calls before the file is cleaned up.

If you have use cases where having more permanent storage is required, please reach out to our team at support@magichour.ai.