--- name: face-search description: Find every photo a person appears in from one selfie, using the SightRadar face recognition API. Use when the user wants to find a person in a folder or gallery of photos, search faces in event, wedding, school or sports photos, deliver each guest their own pictures, group or tag photos by person, build 1:N face search, register a selfie and search by a stored face id, or index faces into a collection. license: MIT compatibility: Needs network access to api.sightradar.com and a SightRadar API key in SIGHTRADAR_API_KEY. The helper script needs Python 3.8+ (standard library only); the curl examples need curl. metadata: author: SightRadar team version: "1.0.0" homepage: https://sightradar.com --- # Face search: find a person's photos from one selfie Two steps. **Index** the photos once: the faces of each photo are stored in a collection under your `photoId`. Then **search** with a selfie: the API returns the `photo_id`s that contain that person, ranked by similarity. Photos themselves are not stored. ## 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: 93 credits per photo indexed and per search by image, 62 per search by a stored id. 1 credit = $0.00001, so 1,000 photos cost about $0.93. Tell the user the cost before indexing a folder and check the balance (`GET /v1/wallet`, free). - Consent: index and search faces only for people who agreed to it and for the purpose they expect. Do not use this to identify strangers. ## Local folder: use the script `scripts/find_person.py` (Python standard library, no install) indexes a folder and searches it. Each photo id is the file path relative to the folder with `/` written as `:`, and every search result carries the file path. ```bash python3 scripts/find_person.py estimate ./photos # count + cost, no API call python3 scripts/find_person.py balance # free python3 scripts/find_person.py index my-event ./photos --yes # 93 credits per photo python3 scripts/find_person.py search my-event ./selfie.jpg --limit 50 ``` `index` prints a JSON summary: photos indexed, faces stored, photos with no usable face, failures. A second run on the same folder skips files that were already indexed and does not charge for them. `search` prints: ```json { "collection_id": "my-event", "matches": [ { "photo_id": "ceremony:IMG_0012.jpg", "score": 0.91, "file": "ceremony/IMG_0012.jpg" } ] } ``` Show the user the matched files with their scores. An empty `matches` with a `reason` means the selfie was the problem: `no_face` or `low_quality_selfie`. Ask for a clearer, front-facing photo. ## With curl ```bash B="https://api.sightradar.com"; AUTH="Authorization: Bearer $SIGHTRADAR_API_KEY"; J="Content-Type: application/json" # Index a local file, or a public URL. The collection is created on first use. curl -s -X POST "$B/v1/collections/my-event/index" -H "$AUTH" -H "Idempotency-Key: idx-my-event-001" \ -F "file=@./photos/001.jpg" -F "photoId=001" curl -s -X POST "$B/v1/collections/my-event/index" -H "$AUTH" -H "$J" \ -d '{"url":"https://cdn.example.com/001.jpg","photoId":"001"}' # {"photo_id":"001","indexed":3,"detected_face_count":3,"rejected_face_count":0,"faces":[{"point_id":"...","bbox":{...}}]} # Search with a selfie curl -s -X POST "$B/v1/collections/my-event/search" -H "$AUTH" -F "file=@./selfie.jpg" -F "limit=50" curl -s -X POST "$B/v1/collections/my-event/search" -H "$AUTH" -H "$J" \ -d '{"url":"https://cdn.example.com/selfie.jpg","limit":50,"threshold":0.6}' # {"matches":[{"photo_id":"001","score":0.91}],"photo_ids":["001"]} # Collections (free) curl -s "$B/v1/collections" -H "$AUTH" curl -s "$B/v1/collections/my-event" -H "$AUTH" # photo_count, face_count, selfie_count ``` `indexed: 0` is a successful, charged result: no face passed the quality gate (too small, blurry, or turned away). `photoId` is optional and defaults to a hash of the image; always set it to the user's own photo key. Keep `/` out of it: a photo id with a slash cannot be addressed by the per-photo delete route. ## Returning users: register the selfie once, search by id For an app where the same person searches many times, register their selfie once (93) and keep the returned `point_id`. Each later search by id costs 62 and needs no image. ```bash curl -s -X POST "$B/v1/collections/my-event/selfies" -H "$AUTH" -H "Idempotency-Key: reg-u_42" \ -F "file=@./selfie.jpg" -F "userId=u_42" # {"face_found":true,"point_id":"...","selfie_id":"...","quality_passed":true} curl -s -X POST "$B/v1/collections/my-event/search-by-id" -H "$AUTH" -H "$J" \ -d '{"pointId":"","limit":50}' ``` `userId` is required. If `face_found` is false, ask for another photo. A `point_id` belongs to one collection. ## In code ```python # pip install sightradar from sightradar import SightRadar sr = SightRadar() # reads SIGHTRADAR_API_KEY sr.index("my-event", file="photos/001.jpg", photo_id="001") result = sr.search("my-event", file="selfie.jpg") for m in result.matches: print(m.photo_id, round(m.score, 3)) ``` ```ts // npm install sightradar import { SightRadar } from "sightradar"; const sr = new SightRadar(); await sr.index("my-event", { url: "https://cdn.example.com/001.jpg", photoId: "001" }); const result = await sr.search("my-event", { url: "https://cdn.example.com/selfie.jpg" }); for (const m of result.matches) console.log(m.photo_id, m.score); ``` ## Getting good results - Scores are cosine similarity from 0 to 1. There is no universal cut-off: test on a sample of the user's own photos and pick the threshold where right and wrong matches separate. For galleries, a looser threshold plus an "Is this you?" confirmation on borderline scores works better than a strict one. - One collection per event or library keeps searches scoped and makes deletion simple. - More than a few hundred photos that are reachable by URL: use the batch route (62 per photo, 1,000 URLs per call). See the `face-batch-indexing` skill or https://sightradar.com/docs/guides/batch-and-webhooks - When the work is done, or a person asks to be removed, delete the data: `DELETE /v1/collections/{id}` (soft, restorable) or `DELETE /v1/collections/{id}/photos/{photoId}`. See the `face-data-deletion` skill. ## Errors 401 bad key. 402 out of credits (top up, then re-run; indexed photos are not charged again). 404 collection not found on search (index first). 409 the Idempotency-Key was already used: that call already ran. 413 image over 30 MB. 429, 502, 503: wait and retry with the same Idempotency-Key. Full docs: https://sightradar.com/llms.txt