Tutorial
Video Processing
8 min reading

How to Detect Faces in a Video with JavaScript?

Summarize this article with:

summary
  • The first step is to set Axios, a promise-based HTTP client for the browser and Node.js, that will allow you to call Eden AI API.
  • To perform Video Face Detection in videos, you'll need to create an account on Eden AI for free.
  • We offer a unified API for all providers: simple and standard to use, with a quick switch between providers and an access to the specific features of each provider.
  • With Eden AI you have the possibility to integrate a third party platform: we can quickly develop connectors.
  • With Eden AI's standardized API and ready-to-use code examples, most developers can integrate the feature in under an hour.

In this tutorial, you will learn how to use Face Detection in Videos in 5 minutes using JavaScript. Eden AI provides an easy and developer-friendly API that allows you to detect faces in videos.

‍

What is Video Face Detection?

Video Face Detection is a technology that can automatically identify human faces in digital video footage. This can be used for security or for various purposes like photo editing or cropping. For example, video face detection can be used to automatically unlock a device when the user's face is recognized.

Face Detection API result on Eden AI

‍

Get Started with Video Face Detection API

The first step is to set Axios, a promise-based HTTP client for the browser and Node.js, that will allow you to call Eden AI API.

‍

Next, you'll need to initialize the File System module in order to access local files on your computer.

‍

Finally, you'll need to create your multipart/formdata parameters form:

‍

How to use Video Face Detection API with JavaScript

You are now ready to process your video file into Eden AI Video Face Detection API.

‍

1. Get a Video Face Detection API Key on Eden AI

To perform Video Face Detection in videos, you'll need to create an account on Eden AI for free. Then, you will be able to get your API key directly from the homepage with free credits offered by Eden AI.

‍

‍

‍2. Let’s Detect Faces in your Video File

Now that you have initialized the required JavaScript modules and got your API key, you will be able to detect faces in videos. Face detection in videos now goes through a multimodal LLM that accepts video as input, called with Eden AI’s OpenAI-compatible chat completions endpoint: the model lists the faces with a short description and the time ranges where they appear, rather than frame-by-frame bounding boxes. You can use any model that has video in its input_modalities: see our documentation.

‍

Here is the JavaScript code to add your video to the form data and set your API key:



form.append("file", fs.createReadStream("path/to/your/video.mp4"));
const apiKey = "Your_API_Key";

Once the file is added, you can configure your requests: the video is first uploaded to Eden AI, which returns a file_id, then the request asks a multimodal LLM, here google/gemini-2.5-flash, to detect the faces and to answer in the JSON format set by the schema:



// Step 1: upload your video to Eden AI, which returns a file_id
const uploadOptions = {
method: "POST",
url: "https://api.edenai.run/v3/upload",
headers: {
authorization: `Bearer ${apiKey}`,
...form.getHeaders(),
},
data: form,
};

// Step 2: ask a multimodal LLM to detect the faces, with the JSON format of the answer
const schema = {
type: "object",
properties: {
faces: {
type: "array",
items: {
type: "object",
properties: {
face: { type: "string" },
start_time: { type: "number" },
end_time: { type: "number" },
},
required: ["face", "start_time", "end_time"],
},
},
},
required: ["faces"],
};

const options = (fileId) => ({
method: "POST",
url: "https://api.edenai.run/v3/chat/completions",
headers: {
authorization: `Bearer ${apiKey}`,
},
data: {
model: "google/gemini-2.5-flash", // any model with video in its input_modalities
messages: [
{
role: "user",
content: [
{ type: "text", text: "List the faces that appear in this video, each with a short description and the time range in seconds where it appears." },
{ type: "file", file: { file_id: fileId } },
],
},
],
response_format: { type: "json_schema", json_schema: { name: "faces", schema: schema } },
},
});

‍

Then, you'll need to create launchJob() function that will execute POST request:

‍

Finally, create the run() function that uploads the video, launches the request and reads the answer. There is no job to poll, as the result comes back in the same response:



const run = async () => {
const upload = await axios.request(uploadOptions);
const response = await launchJob(options(upload.data.file_id));
console.log(response.data);

// The answer is a JSON string that follows the schema
const result = JSON.parse(response.data.choices[0].message.content);
console.log(result.faces);
};

run().catch((error) => {
console.error(error.response ? error.response.data : error);
});

‍

You will get this response, where the answer is a JSON string in choices[0].message.content:



{
"status": "success",
"model": "gemini-2.5-flash",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "{\"faces\": [{\"face\": \"Sintel, bundled in scarf in snowy mountains\", \"start_time\": 5.0, \"end_time\": 8.0}, ...]}"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 15635,
"completion_tokens": 3579,
"total_tokens": 19214
},
"provider": "google",
"cost": 0.0148077
}

‍

Once parsed, this JSON string gives the result for Video Face Detection task (the time ranges are estimated by the model, so check them on a few of your own videos before relying on them in production):



[
{
"face": "Sintel, bundled in scarf in snowy mountains",
"start_time": 5,
"end_time": 8
},
{
"face": "Elderly tribal man with grey beard",
"start_time": 12,
"end_time": 13
},
{
"face": "Sintel, pensive indoors",
"start_time": 14,
"end_time": 15
},
{
"face": "Bald attacker with tribal paint, surprised",
"start_time": 17,
"end_time": 17.5
},
...
]

‍

Benefits of using Video Face Detection API with Eden AI

Using Video Face Detection with Eden AI API is quick and easy.

Multiple AIs in one API - Eden AI

‍

Save time and cost

We offer a unified API for all providers: simple and standard to use, with a quick switch between providers and an access to the specific features of each provider.

‍

Easy to integrate

The JSON output format is the same for all suppliers thanks to Eden AI's standardisation work. The response elements are also standardised thanks to Eden AI's powerful matching algorithms.

‍

Customization

With Eden AI you have the possibility to integrate a third party platform: we can quickly develop connectors. To go further and customize your Video Face Detection request with specific parameters, check out our documentation.

‍‍

FAQ — Detect Faces in a Video with JavaScript

You need an API key from your chosen AI provider. Eden AI lets you access multiple providers with a single key, removing the need for separate vendor accounts.
Any language that supports HTTP requests works — Python, JavaScript, PHP, Ruby, Go, and more. Ready-to-use code snippets are available for the most common languages.
Most developers complete a basic integration in under an hour using standardized API endpoints and ready-to-use code examples.
Implement exponential backoff for rate limit errors and use try-catch blocks for network failures. Eden AI's built-in fallback routing automatically redirects requests if a provider is unavailable.
Eden AI supports GDPR-compliant provider filtering and does not store or reuse your data, ensuring compliance with European privacy regulations.

Similar articles

Tutorial
Generative AI
LLM API Security: How to Detect Abnormal Credential Usage
10/9/2026
·
Written byClément Moreau
Tutorial
Generative AI
How to Build an Open Source Software Factory
9/29/2026
·
Written byClément Moreau
let’s start

Start building with Eden AI

A single interface to integrate the best AI technologies into your products.