Python
from magic_hour import Client
from os import getenv
client = Client(token=getenv("API_TOKEN"))
res = client.v1.face_detection.generate(
assets={"target_file_path": "/path/to/1234.png"}, confidence_score=0.5
wait_for_completion=True,
download_outputs=True,
download_directory="."
)import { Client } from "magic-hour";
const client = new Client({ token: process.env["API_TOKEN"]!! });
const client = new Client({ token: process.env["API_TOKEN"]!! });
const res = await client.v1.faceDetection.generate(
{
assets: { targetFilePath: "/path/to/1234.png" },
confidenceScore: 0.5,
},
{
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"
face_detection "github.com/magichourhq/magic-hour-go/resources/v1/face_detection"
types "github.com/magichourhq/magic-hour-go/types"
)
func main() {
client := sdk.NewClient(
sdk.WithBearerAuth(os.Getenv("API_TOKEN")),
)
res, err := client.V1.FaceDetection.Create(face_detection.CreateRequest{
Assets: types.V1FaceDetectionCreateBodyAssets{
TargetFilePath: "api-assets/id/1234.png",
},
ConfidenceScore: nullable.NewValue(0.5),
})
}let client = magic_hour::Client::default()
.with_bearer_auth(&std::env::var("API_TOKEN").unwrap());
let res = client
.v1()
.face_detection()
.create(magic_hour::resources::v1::face_detection::CreateRequest {
assets: magic_hour::models::V1FaceDetectionCreateBodyAssets {
target_file_path: "api-assets/id/1234.png".to_string(),
},
confidence_score: Some(0.5),
})
.await;curl --request POST \
--url https://api.magichour.ai/v1/face-detection \
--header 'accept: application/json' \
--header 'authorization: Bearer <token>' \
--header 'content-type: application/json' \
--data '
{
"confidence_score": 0.5,
"assets": {
"target_file_path": "api-assets/id/1234.png"
}
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.magichour.ai/v1/face-detection",
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([
'confidence_score' => 0.5,
'assets' => [
'target_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/face-detection")
.header("accept", "application/json")
.header("content-type", "application/json")
.header("authorization", "Bearer <token>")
.body("{\"confidence_score\":0.5,\"assets\":{\"target_file_path\":\"api-assets/id/1234.png\"}}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.magichour.ai/v1/face-detection")
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 \"assets\": {\n \"target_file_path\": \"api-assets/id/1234.png\"\n },\n \"confidence_score\": 0.5\n}"
response = http.request(request)
puts response.read_body{
"id": "uuid-example",
"credits_charged": 123
}{
"message": "Missing request body"
}{
"message": "Unauthorized"
}{
"message": "Payment required"
}{
"message": "Not Found"
}{
"message": "Unable to trigger face detection"
}Files
Face Detection API Reference - Magic Hour Docs
Detect faces in an image or video.
Use this API to get the list of faces detected in the image or video to use in the face swap photo or face swap video API calls for multi-face swaps.
Note: Face detection is free to use for the near future. Pricing may change in the future.
POST
/
v1
/
face-detection
Python
from magic_hour import Client
from os import getenv
client = Client(token=getenv("API_TOKEN"))
res = client.v1.face_detection.generate(
assets={"target_file_path": "/path/to/1234.png"}, confidence_score=0.5
wait_for_completion=True,
download_outputs=True,
download_directory="."
)import { Client } from "magic-hour";
const client = new Client({ token: process.env["API_TOKEN"]!! });
const client = new Client({ token: process.env["API_TOKEN"]!! });
const res = await client.v1.faceDetection.generate(
{
assets: { targetFilePath: "/path/to/1234.png" },
confidenceScore: 0.5,
},
{
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"
face_detection "github.com/magichourhq/magic-hour-go/resources/v1/face_detection"
types "github.com/magichourhq/magic-hour-go/types"
)
func main() {
client := sdk.NewClient(
sdk.WithBearerAuth(os.Getenv("API_TOKEN")),
)
res, err := client.V1.FaceDetection.Create(face_detection.CreateRequest{
Assets: types.V1FaceDetectionCreateBodyAssets{
TargetFilePath: "api-assets/id/1234.png",
},
ConfidenceScore: nullable.NewValue(0.5),
})
}let client = magic_hour::Client::default()
.with_bearer_auth(&std::env::var("API_TOKEN").unwrap());
let res = client
.v1()
.face_detection()
.create(magic_hour::resources::v1::face_detection::CreateRequest {
assets: magic_hour::models::V1FaceDetectionCreateBodyAssets {
target_file_path: "api-assets/id/1234.png".to_string(),
},
confidence_score: Some(0.5),
})
.await;curl --request POST \
--url https://api.magichour.ai/v1/face-detection \
--header 'accept: application/json' \
--header 'authorization: Bearer <token>' \
--header 'content-type: application/json' \
--data '
{
"confidence_score": 0.5,
"assets": {
"target_file_path": "api-assets/id/1234.png"
}
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.magichour.ai/v1/face-detection",
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([
'confidence_score' => 0.5,
'assets' => [
'target_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/face-detection")
.header("accept", "application/json")
.header("content-type", "application/json")
.header("authorization", "Bearer <token>")
.body("{\"confidence_score\":0.5,\"assets\":{\"target_file_path\":\"api-assets/id/1234.png\"}}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.magichour.ai/v1/face-detection")
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 \"assets\": {\n \"target_file_path\": \"api-assets/id/1234.png\"\n },\n \"confidence_score\": 0.5\n}"
response = http.request(request)
puts response.read_body{
"id": "uuid-example",
"credits_charged": 123
}{
"message": "Missing request body"
}{
"message": "Unauthorized"
}{
"message": "Payment required"
}{
"message": "Not Found"
}{
"message": "Unable to trigger face detection"
}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
application/json
Body
Provide the assets for face detection
Show child attributes
Show child attributes
Confidence threshold for filtering detected faces.
- Higher values (e.g., 0.9) include only faces detected with high certainty, reducing false positives.
- Lower values (e.g., 0.3) include more faces, but may increase the chance of incorrect detections.
Required range:
0 <= x <= 1Must be a multiple of 0.05Example:
0.5
Response
200
The id of the task. Use this value in the get face detection details API to get the details of the face detection task.
Example:
"uuid-example"
The credits charged for the task.
Was this page helpful?
⌘I