Index or match thousands of photos in bulk with the SightRadar face recognition batch API and signed webhooks. Use when the user wants to load a large gallery, event or photo archive for face search, process photo URLs asynchronously, receive per-photo results on a webhook, verify webhook signatures, poll batch status, or retry failed photos.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of face-batch-indexing?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/sightradar-hq-face-batch-indexing)
---
name: face-batch-indexing
description: Index or match thousands of photos in bulk with the SightRadar face recognition batch API and signed webhooks. Use when the user wants to load a large gallery, event or photo archive for face search, process photo URLs asynchronously, receive per-photo results on a webhook, verify webhook signatures, poll batch status, or retry failed photos.
license: MIT
compatibility: Needs network access to api.sightradar.com, a SightRadar API key in SIGHTRADAR_API_KEY, and curl. Photos must be reachable by public or signed URL.
metadata:
author: SightRadar team
version: "1.0.0"
homepage: https://sightradar.com
---
# Batch indexing: load a large gallery
One `POST /v1/batches` call takes up to 1,000 photo URLs and processes them in the background. It costs 62 credits per photo instead of 93, and photos that fail are not charged. Results come per photo on a webhook, or by polling.
Use batch when there are more than a few hundred photos and they are reachable by URL. For local files or a handful of photos, use the real-time index call (see the `face-search` skill).
## Before you start
- Key: `export SIGHTRADAR_API_KEY="frs_..."` (create one at https://sightradar.com/dashboard/keys). Never print or commit it. If it is missing, ask the user to set it; do not ask them to paste it in chat.
- Cost: 62 credits per photo, 1 credit = $0.00001, so 10,000 photos cost about $6.20. **Tell the user the total and get a yes before submitting.** Check the balance with `GET /v1/wallet` (free).
- URLs only. Base64 and file uploads are rejected. Private buckets work with signed URLs that stay valid for a few hours.
```bash
B="https://api.sightradar.com"; AUTH="Authorization: Bearer $SIGHTRADAR_API_KEY"; J="Content-Type: application/json"
```
## 1. Register a webhook (optional, free, once)
```bash
curl -s -X POST "$B/v1/webhooks" -H "$AUTH" -H "$J" -d '{"url":"https://api.example.com/sightradar/webhook"}'
# {"webhook_endpoint_id":"whe_...","secret":"whsec_...","status":"active"}
```
The URL must be public HTTPS. The `secret` is returned once: have the user store it as a server secret. Do not print it again.
## 2. Submit
```bash
curl -s -X POST "$B/v1/batches" -H "$AUTH" -H "$J" -d '{
"collection_id": "event-2026",
"op": "index",
"webhook_endpoint_id": "whe_...",
"photos": [
{"url": "https://cdn.example.com/1.jpg", "external_id": "1"},
{"url": "https://cdn.example.com/2.jpg", "external_id": "2"}
]
}'
# 202 {"batch_id":"...","total_photos":2,"status":"processing"}
```
- `op`: `index` stores the faces of each photo. `match` searches each photo against the collection.
- `external_id`: the user's own photo key. It comes back on every result and is the `photo_id` that searches return. Avoid `/` in it: a photo id with a slash cannot be addressed by the per-photo delete route.
- More than 1,000 photos: split into several batches. Build the JSON with a script, not by hand:
```bash
# urls.txt: one "url,external_id" per line
split -l 1000 urls.txt chunk_
for f in chunk_*; do
jq -Rn --arg c "event-2026" '{collection_id:$c, op:"index",
photos:[inputs | select(length>0) | split(",") | {url:.[0], external_id:(.[1] // .[0])}]}' "$f" \
| curl -s -X POST "$B/v1/batches" -H "$AUTH" -H "$J" -d @-
echo
done
```
Keep every `batch_id` that comes back.
## 3. Get the results
**Polling** (works with or without a webhook):
```bash
curl -s "$B/v1/batches/<batch_id>" -H "$AUTH"
# {"status":"processing","total_photos":1000,"succeeded":990,"failed":3,"pending":7}
curl -s "$B/v1/batches/<batch_id>/photos?limit=500" -H "$AUTH"
# {"photos":[{"external_id":"1","photo_index":0,"status":"succeeded","face_count":2}],"has_more":true,"next_after_index":499}
curl -s "$B/v1/batches/<batch_id>/photos?limit=500&after_index=499" -H "$AUTH"
```
The batch is finished when `status` is `completed` (`pending` is 0). Poll every 10 to 30 seconds, not in a tight loop. The photos list is the authoritative per-photo record; use it to reconcile after a webhook outage.
**Webhook**: each photo produces one signed `POST` to the registered URL.
```json
{ "batch_id": "...", "external_id": "1", "photo_index": 0, "status": "succeeded", "charged": true,
"processed_at": "2026-07-01T10:00:00Z", "result": { "face_count": 2 } }
```
A failed photo has `status: "failed"`, `charged: false` and an `error.code` such as `image_fetch_failed`, `image_access_denied`, `image_corrupt` or `image_too_large` (the polling route shows the same value as `reason_code`). Treat unknown codes as a generic failure. `face_count: 0` with `succeeded` means a valid photo with no usable face.
## Verify the webhook signature
| Header | Value |
| --- | --- |
| `X-SightRadar-Timestamp` | Unix seconds |
| `X-SightRadar-Signature` | `hex(HMAC-SHA256(secret, "<timestamp>.<raw body>"))` |
| `X-SightRadar-Idempotency-Key` | Stable per result. Delivery is at least once, so skip keys already seen. |
```python
import hashlib, hmac, time
def verify(secret: str, timestamp: str, raw_body: bytes, signature: str) -> bool:
if abs(time.time() - int(timestamp)) > 300: # reject old deliveries
return False
expected = hmac.new(secret.encode(), timestamp.encode() + b"." + raw_body, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, signature)
```
Compute the HMAC over the **raw** request body, before any JSON parsing. Return 2xx only after the result is saved. The Node SDK exports `verifyWebhookSignature`.
## Recover from failures
- Photos that failed because of the image (`image_fetch_failed`, `image_access_denied`, `image_corrupt`, `image_too_large`): fix the URL or the file and submit them in a new batch.
- Photos that failed for a temporary reason (`insufficient_credits`, `internal_error`, `retry_exhausted`): `POST /v1/batches/failed/requeue` with `{"reason_code":"insufficient_credits","limit":500,"execute":false}` returns a preview. Send `{"preview_id":"...","execute":true}` to run it.
- Deliveries that ran out of retries: `GET /v1/webhooks/dead-letters` lists them, `POST /v1/webhooks/dead-letters/replay` queues them again.
## Errors
400 bad body, more than 1,000 photos, or base64 in a batch. 401 bad key. 402 out of credits: top up, then requeue. 429: wait and retry. Guide: https://sightradar.com/docs/guides/batch-and-webhooks and full docs at https://sightradar.com/llms.txt