Detect Faces
Unified endpoint to detect faces in either video or image from URL or base64-encoded image
Request Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
url | string | Yes* | - | Image or video URL (publicly accessible) |
img | string | Yes* | - | Base64-encoded image data |
num_frames | integer | No | 5 | Number of frames for video analysis |
return_face_url | boolean | No | false | Return cropped face image URLs |
single_face | boolean | No | false | Return only the largest face |
url or img must be provided. If both are provided, url takes priority.Response Format
Response Fields
| Field | Type | Description |
|---|---|---|
error_code | integer | 0 = success, 1 = error |
error_msg | string | Status message |
faces_obj | object | Face data keyed by frame index (“0”, “1”, etc.) |
Face Frame Data
| Field | Type | Description |
|---|---|---|
landmarks | array | 6-point landmarks for each face: Left Eye, Right Eye, Nose, Mouth Center, Left Mouth Corner, Right Mouth Corner |
landmarks_str | array | First 4 landmarks as string format "x1,y1:x2,y2:x3,y3:x4,y4" - use this for Face Swap opts parameter |
region | array | Bounding boxes [x, y, width, height] |
removed | array | Faces no longer visible (video only) |
frame_time | number/null | Timestamp in seconds (video only, null for images) |
face_urls | array/null | Cropped face URLs (when return_face_url=true) |
crop_region | array/null | Crop region in original image coordinates |
crop_landmarks | array/null | Landmarks relative to cropped image |
Examples
Example 1: Basic Image Detection
Request:Example 2: Video Detection
Request:Example 3: Get Cropped Face URLs
Request:Example 4: Single Face Mode
Request:Error Responses
| error_code | error_msg | Description |
|---|---|---|
| 0 | SUCCESS | Success |
| 1 | Either ‘url’ or ‘img’ parameter must be provided | Missing input |
| 1 | Invalid URL format | Bad URL |
| 1 | Failed to download media from URL | Download failed |
Integration with Face Swap
Uselandmarks_str directly as the opts parameter in Face Swap API:
Best Practices
- URL Requirements: Use HTTPS, ensure publicly accessible
- Video num_frames: Short videos (5-10), Medium (10-20), Long (20-50)
- Performance: Use
single_face=truewhen only one face needed
Authorizations
Your API Key used for request authorization. If both Authorization and x-api-key have values, Authorization will be used first and x-api-key will be discarded.
Body
URL of the video or image to process. The media type will be auto-detected based on the file extension.
Either url or img must be provided. If both are provided, url takes priority.
"https://example.com/media.mp4"
Base64-encoded image data. Supports both plain base64 string and data URI format (e.g., "data:image/jpeg;base64,...").
Either url or img must be provided. If both are provided, url takes priority.
"data:image/jpeg;base64,/9j/4AAQSkZJRg..."
Number of frames to extract and analyze (only used for videos, ignored for images)
1 <= x <= 1005
Whether to return cropped face image URLs. When set to true, the response will include:
face_urls: URLs of cropped face imagescrop_region: The region used for cropping in original image coordinatescrop_landmarks: Landmarks relative to the cropped image
false
When set to true, only returns the largest face (by area) in each frame.
Useful when you only need the main/primary face in the image or video.
false
Response
Face detection completed successfully
Error code (0: success, 1: error)
0
Error message or success message
"SUCCESS"
Dictionary of face detection results keyed by frame index (as string). For images, only frame "0" will be present. For videos, multiple frames will be present (e.g., "0", "5", "10", etc.)
{
"0": {
"landmarks": [
[
[120, 85],
[180, 88],
[150, 130],
[150, 165],
[125, 165],
[175, 168]
]
],
"landmarks_str": ["120,85:180,88:150,130:150,165"],
"region": [[80, 50, 150, 180]],
"removed": [],
"frame_time": null,
"face_urls": null,
"crop_region": null,
"crop_landmarks": null
}
}