face detection API
Detect faces from images programmatically with a single API call. Built for developers who need accurate labels, confidence scores, and optional bounding boxes at scale.
Why Use This API
AI face detection
Advanced AI models trained on broad visual datasets. Accurately identifies common face categories from real-world scenes.
Confidence Scoring
Returns confidence values for each detection so you can filter low-certainty predictions in production pipelines.
Bounding Box Output
Optionally includes bounding box coordinates so you can draw overlays or crop detected faces.
Multi-face detection
Detect and identify multiple different faces within a single image. Perfect for analyzing complex designs.
Quick Start
Start identifying faces in under a minute. Here's how:
- Get your API key — Sign up free to receive your key
- Send a request — POST an image containing one or more faces to the endpoint
- Get the result — Receive identified faces as JSON with confidence scores
curl -X POST https://precisioncounter.com/api/v1/detect-faces \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "image=@sample.png"
import requests
response = requests.post(
"https://precisioncounter.com/api/v1/detect-faces",
headers={"Authorization": "Bearer YOUR_API_KEY"},
files={"image": open("sample.png", "rb")}
)
data = response.json()
for face in data["faces"]:
print(f"{face['name']} ({face['confidence']:.0%})")
const fs = require("fs");
const FormData = require("form-data");
const form = new FormData();
form.append("image", fs.createReadStream("sample.png"));
const response = await fetch(
"https://precisioncounter.com/api/v1/detect-faces",
{
method: "POST",
headers: {
"Authorization": "Bearer YOUR_API_KEY",
...form.getHeaders()
},
body: form
}
);
const data = await response.json();
data.faces.forEach(f => console.log(`${f.name} (${f.confidence})`));
API Reference
Base URL
https://precisioncounter.com/api/v1
Authentication
All requests require an API key passed in the Authorization header:
Authorization: Bearer YOUR_API_KEY
Detect faces
Detects faces from an uploaded image and returns structured detection results as JSON.
Request Parameters
| Parameter | Type | Description |
|---|---|---|
| image required | file | Image file to analyze for face detection. Accepted formats: PNG, JPG, JPEG, WebP. Max size: 10 MB. |
| max_faces optional | integer | Max number of face detections to return. Default: 5. Range: 1-20. |
| include_boxes optional | boolean | Include bounding box coordinates for each detection. Default: true. |
Response
200 OK — Returns identified face data as JSON.
{
"faces": [
{
"name": "person",
"confidence": 0.94,
"category": "person",
"box": {
"x": 124,
"y": 52,
"width": 300,
"height": 540
}
}
],
"image_width": 1280,
"image_height": 720,
"processing_time_ms": 450
}
Response Headers
| Header | Value |
|---|---|
| Content-Type | application/json |
| X-Credits-Remaining | Number of API credits remaining |
| X-Processing-Time | Processing time in milliseconds |
Code Examples
Full Examples (with error handling)
curl -X POST https://precisioncounter.com/api/v1/detect-faces \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "image=@sample.png" \
-F "max_faces=5" \
-F "include_boxes=true"
import requests
import sys
API_KEY = "YOUR_API_KEY"
API_URL = "https://precisioncounter.com/api/v1/detect-faces"
def detect_faces(input_path, max_faces=5):
"""Detect faces from an image file."""
with open(input_path, "rb") as img:
response = requests.post(
API_URL,
headers={"Authorization": f"Bearer {API_KEY}"},
files={"image": img},
data={"max_faces": max_faces, "include_boxes": "true"}
)
if response.status_code == 200:
data = response.json()
for face in data["faces"]:
print(f"{face['name']} - {face['confidence']:.0%} confidence")
print(f" Category: {face['category']}")
if face.get("box"):
print(f" Box: {face['box']}")
print(f"Credits remaining: {response.headers.get('X-Credits-Remaining')}")
else:
print(f"Error {response.status_code}: {response.json()['error']}")
detect_faces("sample.png")
const fs = require("fs");
const FormData = require("form-data");
const fetch = require("node-fetch");
const API_KEY = "YOUR_API_KEY";
const API_URL = "https://precisioncounter.com/api/v1/detect-faces";
async function detectfaces(inputPath, maxResults = 5) {
const form = new FormData();
form.append("image", fs.createReadStream(inputPath));
form.append("max_faces", String(maxResults));
form.append("include_boxes", "true");
const response = await fetch(API_URL, {
method: "POST",
headers: {
"Authorization": `Bearer ${API_KEY}`,
...form.getHeaders()
},
body: form
});
if (response.ok) {
const data = await response.json();
data.faces.forEach(face => {
console.log(`${face.name} - ${(face.confidence * 100).toFixed(0)}%`);
console.log(` Category: ${face.category}`);
if (face.box) console.log(` Box: ${JSON.stringify(face.box)}`);
});
console.log(`Credits: ${response.headers.get("x-credits-remaining")}`);
} else {
const error = await response.json();
console.error(`Error ${response.status}: ${error.error}`);
}
}
detectfaces("sample.png");
<?php
$api_key = "YOUR_API_KEY";
$url = "https://precisioncounter.com/api/v1/detect-faces";
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer $api_key"
],
CURLOPT_POSTFIELDS => [
"image" => new CURLFile("sample.png"),
"max_faces" => "5",
"include_boxes" => "true"
]
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 200) {
$data = json_decode($response, true);
foreach ($data["faces"] as $face) {
echo $face["name"] . " - " . ($face["confidence"] * 100) . "% confidence\n";
echo " Category: " . $face["category"] . "\n";
if (isset($face["box"])) {
echo " Box: " . json_encode($face["box"]) . "\n";
}
}
} else {
echo "Error $httpCode: $response\n";
}
?>
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"mime/multipart"
"net/http"
"os"
)
type faceResult struct {
Name string `json:"name"`
Confidence float64 `json:"confidence"`
Category string `json:"category"`
Box map[string]int `json:"box"`
}
type Response struct {
faces []faceResult `json:"faces"`
ImageWidth int `json:"image_width"`
ImageHeight int `json:"image_height"`
ProcessingTime int `json:"processing_time_ms"`
}
func detectfaces(inputPath string) error {
file, _ := os.Open(inputPath)
defer file.Close()
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
part, _ := writer.CreateFormFile("image", inputPath)
io.Copy(part, file)
writer.WriteField("max_faces", "5")
writer.Close()
req, _ := http.NewRequest("POST",
"https://precisioncounter.com/api/v1/detect-faces", body)
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
req.Header.Set("Content-Type", writer.FormDataContentType())
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode == 200 {
var result Response
json.NewDecoder(resp.Body).Decode(&result)
for _, face := range result.faces {
fmt.Printf("%s - %.0f%% confidence\n", face.Name, face.Confidence*100)
}
}
return nil
}
func main() {
detectfaces("sample.png")
}
require "net/http"
require "uri"
require "json"
api_key = "YOUR_API_KEY"
uri = URI("https://precisioncounter.com/api/v1/detect-faces")
form_data = [
["image", File.open("sample.png", "rb")],
["max_faces", "5"],
["include_boxes", "true"]
]
req = Net::HTTP::Post.new(uri)
req["Authorization"] = "Bearer #{api_key}"
req.set_form(form_data, "multipart/form-data")
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(req)
end
if res.code == "200"
data = JSON.parse(res.body)
data["faces"].each do |face|
puts "#{face['name']} - #{(face['confidence'] * 100).round}% confidence"
puts " Category: #{face['category']}"
puts " Box: #{face['box']}" if face['box']
end
else
puts "Error #{res.code}: #{res.body}"
end
using System.Text.Json;
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer YOUR_API_KEY");
using var form = new MultipartFormDataContent();
var imageContent = new ByteArrayContent(File.ReadAllBytes("sample.png"));
imageContent.Headers.ContentType = new("image/png");
form.Add(imageContent, "image", "sample.png");
form.Add(new StringContent("5"), "max_faces");
form.Add(new StringContent("true"), "include_boxes");
var response = await client.PostAsync(
"https://precisioncounter.com/api/v1/detect-faces", form);
if (response.IsSuccessStatusCode)
{
var json = await response.Content.ReadAsStringAsync();
var data = JsonSerializer.Deserialize<JsonElement>(json);
foreach (var face in data.GetProperty("faces").EnumerateArray())
{
Console.WriteLine($"{face.GetProperty("name")} - {face.GetProperty("confidence")}");
}
}
Error Handling
The API returns standard HTTP status codes with JSON error bodies:
| Status | Meaning | Description |
|---|---|---|
| 200 | Success | faces identified successfully. Response body contains JSON with face data. |
| 400 | Bad Request | Missing image file, unsupported format, or file too large. |
| 401 | Unauthorized | Missing or invalid API key. |
| 429 | Rate Limited | Too many requests. Wait and retry with exponential backoff. |
| 500 | Server Error | Internal processing error. Retry the request. |
Error Response Format
{
"error": "Invalid file format. Accepted: png, jpg, jpeg, webp",
"code": "INVALID_FORMAT",
"status": 400
}
Rate Limits
| Plan | Requests / Minute | Max File Size | Max Resolution |
|---|---|---|---|
| Free | 10 | 10 MB | 4096 x 4096 px |
| Pro | 60 | 25 MB | 8192 x 8192 px |
Rate limit headers are included in every response:
X-RateLimit-Limit: 10 X-RateLimit-Remaining: 7 X-RateLimit-Reset: 1708646400
Use Cases
- Design asset management
- Brand consistency checking
- Web scraping face detection
- Accessibility compliance
- Print production
- image analysis research
- Design tool plugins
- detection workflow verification
Pricing
Get free API credits when you sign up. No credit card required.
Frequently Asked Questions
max_faces parameter to control how many face detections are returned, up to 20 per request.include_boxes parameter set to false.