> For the complete documentation index, see [llms.txt](https://docs.facephi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.facephi.com/docs.facephi-en/sdks/backend-sdk/backend1n/technical_documentation/api_reference/search/search-image-collectionid.md).

# /search/image/{collectionId}

Searches for a biometric template, extracted from a raw image, among the specimens (faces) stored in the database, under the same collectionId. The collectionId must correspond to an existing collection; if the collection exists but has no specimens, an empty list is returned (it is not an error). Without `options`, a single candidate is returned (`maxCandidates` = 1) and without filtering by similarity (`minSimilarity` = 0).

```json
{"openapi":"3.0.1","info":{"title":"Backend1n-Service REST API","version":"5.0.0"},"servers":[{"url":"http://127.0.0.1:6982/"}],"security":[{"BearerAuth":[]},{"ApiKeyAuth":[]}],"components":{"securitySchemes":{"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT","description":"JWT signed with HS256 (shared secret `auth_jwt_secret`) and with a non-expired `exp` claim; if it includes `nbf`, it must be currently valid. Only applied if `auth_enabled` is true and `auth_accept_authorization_header` is true. The `Bearer` scheme is case-insensitive.\n"},"ApiKeyAuth":{"type":"apiKey","in":"header","name":"x-api-key","description":"The same JWT sent in an API key header. The default name is `x-api-key` and it can be changed with `auth_api_key_header_name`; only applied if `auth_accept_api_key_header` is true. If both headers are sent, `Authorization` takes precedence.\n"}},"schemas":{"CollectionId":{"type":"string","minLength":1,"pattern":"^[A-Za-z0-9_-]+$","description":"An identifier that allows grouping different images or biometric templates in a common space. It can only contain ASCII letters (A-Z, a-z), digits (0-9), underscore (`_`) and hyphen (`-`); it cannot be empty and it is case-sensitive. The following are **not allowed**: spaces, dots, `+`, `:`, `@`, quotes, `%`, `~`, `/`, or non-ASCII characters (`ñ`, accents, emoji...): the identifier is used as a path parameter and any other character prevents its use. It must correspond to a collection previously created with `POST /collections`.\n"},"SearchImageBody":{"type":"object","description":"Body for the POST request to search by image","properties":{"image":{"$ref":"#/components/schemas/ImageBuffer"},"options":{"$ref":"#/components/schemas/SearchOptions"}},"required":["image"]},"ImageBuffer":{"type":"string","description":"Image buffer in JPEG, PNG or BMP format, encoded in RFC4648 base64."},"SearchOptions":{"type":"object","description":"Options when searching for biometric templates.","properties":{"maxCandidates":{"$ref":"#/components/schemas/MaxCandidates"},"minSimilarity":{"$ref":"#/components/schemas/MinSimilarity"}}},"MaxCandidates":{"type":"integer","minimum":1,"default":1,"description":"The maximum number of candidates wanted in the response. Unsigned integer greater than or equal to 1 (a negative, decimal or textual value, or one greater than the range of a 64-bit unsigned integer, is rejected with 400).\n"},"MinSimilarity":{"type":"number","minimum":0,"maximum":1,"default":0,"description":"The minimum similarity required for a candidate to be included in the response. Number between 0 and 1 (inclusive); any other value is rejected with 400. With the default value (0), candidates of any similarity are returned up to `maxCandidates`: the search does **not** apply the SDK authentication threshold (`FACEPHI_SELPHID_FACIALAUTHENTICATION_THRESHOLD`, 65); to keep only positive matches, sending `minSimilarity: 0.65` is recommended.\n"},"SearchResponse":{"type":"array","description":"A list of specimens (faces) found in the database, sorted by descending similarity and with at most `maxCandidates` items.\n","items":{"$ref":"#/components/schemas/SearchItem"}},"SearchItem":{"type":"object","description":"Specimen found in the database. `templateId` is the `id` of the specimen (face) found.","properties":{"galleryIndex":{"$ref":"#/components/schemas/GalleryIndex"},"similarity":{"$ref":"#/components/schemas/Similarity"},"templateId":{"$ref":"#/components/schemas/FaceId"}}},"GalleryIndex":{"type":"integer","minimum":0,"description":"The position (0-based, unique within the response) that an item occupies in the collection gallery."},"Similarity":{"type":"number","default":0,"description":"A value between 0 and 1 that indicates the similarity between two biometric templates."},"FaceId":{"type":"string","description":"An identifier of a specimen (face) in the database."},"BadRequestResult":{"type":"object","description":"Result when incorrect parameters arrive in the request.","properties":{"status":{"type":"number"},"error":{"type":"string"},"message":{"type":"string","description":"Specific description of the reason for the error. It is the only field that indicates the real cause."},"timeStamp":{"$ref":"#/components/schemas/TimeStamp"}}},"TimeStamp":{"type":"string","description":"A date/time value (UTC) in \"%Y-%m-%dT%H:%M:%SZ\" format."},"UnauthorizedResult":{"type":"object","description":"JWT authentication is enabled and the request does not pass it. It is accompanied by the header `WWW-Authenticate: Bearer`. Values of `message`: `Missing authentication token` (no token or unsupported scheme), `JWT token validation failed` (invalid signature, algorithm or format), `JWT token is expired`, `JWT token does not include exp claim` and `JWT token is not yet valid` (future `nbf`).\n","properties":{"status":{"type":"number"},"error":{"type":"string"},"message":{"type":"string"},"timeStamp":{"$ref":"#/components/schemas/TimeStamp"}}},"ExceptionResult":{"type":"object","description":"An error occurred while calling the backend services.","properties":{"status":{"type":"number"},"error":{"type":"string"},"exception":{"type":"string","description":"Specific description of the reason for the exception (internal service text; it is not part of the contract)."},"timeStamp":{"$ref":"#/components/schemas/TimeStamp"}}}},"responses":{"Unauthorized":{"description":"JWT authentication is enabled and the token is missing or invalid.","headers":{"WWW-Authenticate":{"schema":{"type":"string"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthorizedResult"}}}},"PayloadTooLarge":{"description":"The request body exceeds `client_max_body_size`. It is returned with no body and the connection is closed."}}},"paths":{"/search/image/{collectionId}":{"post":{"description":"Searches for a biometric template, extracted from a raw image, among the specimens (faces) stored in the database, under the same collectionId. The collectionId must correspond to an existing collection; if the collection exists but has no specimens, an empty list is returned (it is not an error). Without `options`, a single candidate is returned (`maxCandidates` = 1) and without filtering by similarity (`minSimilarity` = 0).","tags":["Search"],"parameters":[{"in":"path","name":"collectionId","schema":{"$ref":"#/components/schemas/CollectionId"},"required":true}],"requestBody":{"description":"JSON with the input image encoded in RFC4648 base64 format and the search options.","required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SearchImageBody"}}}},"responses":{"200":{"description":"The result of the search, a list of template ids.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SearchResponse"}}}},"400":{"description":"Incorrect parameters arrive in the request.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/BadRequestResult"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"413":{"$ref":"#/components/responses/PayloadTooLarge"},"500":{"description":"An error occurred in the Backend1N service.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ExceptionResult"}}}}}}}}}
```
