Skip to main content
POST
/
v1
/
files
/
upload-urls
Python
from magic_hour import Client
from os import getenv

client = Client(token=getenv("API_TOKEN"))
res = client.v1.files.upload_urls.create(
    items=[
        {"extension": "mp4", "type_": "video"},
        {"extension": "mp3", "type_": "audio"},
    ]
)
import { Client } from "magic-hour";

const client = new Client({ token: process.env["API_TOKEN"]!! });
const res = await client.v1.files.uploadUrls.create({
items: [
{ extension: "mp4", type: "video" },
{ extension: "mp3", type: "audio" },
],
});
package main

import (
os "os"

sdk "github.com/magichourhq/magic-hour-go/client"
upload_urls "github.com/magichourhq/magic-hour-go/resources/v1/files/upload_urls"
types "github.com/magichourhq/magic-hour-go/types"
)

func main() {
client := sdk.NewClient(
sdk.WithBearerAuth(os.Getenv("API_TOKEN")),
)
res, err := client.V1.Files.UploadUrls.Create(upload_urls.CreateRequest{
Items: []types.V1FilesUploadUrlsCreateBodyItemsItem{
types.V1FilesUploadUrlsCreateBodyItemsItem{
Extension: "mp4",
Type: types.V1FilesUploadUrlsCreateBodyItemsItemTypeEnumVideo,
},
types.V1FilesUploadUrlsCreateBodyItemsItem{
Extension: "mp3",
Type: types.V1FilesUploadUrlsCreateBodyItemsItemTypeEnumAudio,
},
},
})
}
let client = magic_hour::Client::default()
.with_bearer_auth(&std::env::var("API_TOKEN").unwrap());
let res = client
.v1()
.files()
.upload_urls()
.create(magic_hour::resources::v1::files::upload_urls::CreateRequest {
items: vec![
magic_hour::models::V1FilesUploadUrlsCreateBodyItemsItem { extension :
"mp4".to_string(), type_ :
magic_hour::models::V1FilesUploadUrlsCreateBodyItemsItemTypeEnum::Video
}, magic_hour::models::V1FilesUploadUrlsCreateBodyItemsItem { extension :
"mp3".to_string(), type_ :
magic_hour::models::V1FilesUploadUrlsCreateBodyItemsItemTypeEnum::Audio }
],
})
.await;
curl --request POST \
--url https://api.magichour.ai/v1/files/upload-urls \
--header 'accept: application/json' \
--header 'authorization: Bearer <token>' \
--header 'content-type: application/json' \
--data '
{
"items": [
{
"type": "video",
"extension": "mp4"
},
{
"type": "audio",
"extension": "mp3"
}
]
}
'
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.magichour.ai/v1/files/upload-urls",
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([
'items' => [
[
'type' => 'video',
'extension' => 'mp4'
],
[
'type' => 'audio',
'extension' => 'mp3'
]
]
]),
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/files/upload-urls")
.header("accept", "application/json")
.header("content-type", "application/json")
.header("authorization", "Bearer <token>")
.body("{\"items\":[{\"type\":\"video\",\"extension\":\"mp4\"},{\"type\":\"audio\",\"extension\":\"mp3\"}]}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.magichour.ai/v1/files/upload-urls")

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 \"items\": [\n {\n \"type\": \"video\",\n \"extension\": \"mp4\"\n },\n {\n \"type\": \"audio\",\n \"extension\": \"mp3\"\n }\n ]\n}"

response = http.request(request)
puts response.read_body
{
  "items": [
    {
      "upload_url": "https://videos.magichour.ai/api-assets/id/video.mp4?auth-value=1234567890",
      "expires_at": "2024-07-25T16:56:21.932Z",
      "file_path": "api-assets/id/video.mp4"
    },
    {
      "upload_url": "https://videos.magichour.ai/api-assets/id/audio.mp3?auth-value=1234567890",
      "expires_at": "2024-07-25T16:56:21.932Z",
      "file_path": "api-assets/id/audio.mp3"
    }
  ]
}
{
"message": "Missing request body"
}
{
"message": "Unauthorized"
}
{
"message": "Payment required"
}
{
"message": "Not Found"
}
{
"message": "'mp4' is an invalid audio extension. Possible extensions are 'mp3, wav, aac, flac, webm, m4a, opus, ogg, aiff, amr'"
}

Authorizations

Authorization
string
header
required

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

application/json

Body

items
object[]
required

The list of assets to upload. The response array will match the order of items in the request body.

Minimum array length: 1
Example:
[
{ "type": "video", "extension": "mp4" },
{ "type": "audio", "extension": "mp3" }
]

Response

Success

Success

items
object[]
required

The list of upload URLs and file paths for the assets. The response array will match the order of items in the request body. Refer to the Input Files Guide for more details.

Example:
[
{
"upload_url": "https://videos.magichour.ai/api-assets/id/video.mp4?auth-value=1234567890",
"expires_at": "2024-07-25T16:56:21.932Z",
"file_path": "api-assets/id/video.mp4"
},
{
"upload_url": "https://videos.magichour.ai/api-assets/id/audio.mp3?auth-value=1234567890",
"expires_at": "2024-07-25T16:56:21.932Z",
"file_path": "api-assets/id/audio.mp3"
}
]