> 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/rest-api/midapi-v2/biometric-services/facial-matching.md). Agents can also search and read this documentation through its [MCP server](https://docs.facephi.com/~gitbook/mcp).

# Facial Matching

Service that compares two faces and returns the match result with its confidence score.

The order of the slots is significant: `sourceImage` is the face from the document, which the comparison starts from, and `targetImage` is the selfie verified against it.

### Endpoint

```
POST /biometric/face/matching
```

### Headers

| Name              | Type   | Required    | Description                                                                                                                                                                                     |
| ----------------- | ------ | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Authorization** | string | **Yes**     | Consumer token in the format `Bearer <token>`. See [Authentication](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/autenticacion.md).                                              |
| **consumer-id**   | string | **Yes**     | Consumer identifier.                                                                                                                                                                            |
| **operation-id**  | string | Conditional | Identifier of the operation to which the referenced assets belong. Required when `source` is `FILE_KEY`. See [Storage](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/storage.md). |

### Request body

**Content-Type:** `application/json`

#### Parameters

| Parameter     | Type   | Required | Description                                                                                                                                                                                                                                                                                                                                                                                                             |
| ------------- | ------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `source`      | string | **Yes**  | Mode used to provide the assets: `FILE_KEY` for stored asset keys, `FILE` for Base64 content. See [Storage](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/storage.md).                                                                                                                                                                                                                                    |
| `sourceImage` | string | **Yes**  | Face the comparison starts from: a cropped face from the document (`TOKEN_FACE_IMAGE`), a token for the front of the document (`TOKEN_FRONT_DOCUMENT`), or a token for an unencrypted uploaded face image (`TOKEN_RAW_IMAGE`). See [Asset contexts](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/storage.md#contextos-de-asset). With `source` equal to `FILE` also accepts a facial template in Base64. |
| `targetImage` | string | **Yes**  | Selfie to verify against it: asset key `TOKEN_BEST_IMAGE`. With `source` equal to `FILE`, its Base64 content, which is the tokenized selfie, or the selfie as an unencoded image (JPEG or PNG).                                                                                                                                                                                                                         |

The unencoded facial image, for example one provided by a civil registry, is stored with the context `RAW_IMAGE` in [Save Asset](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/storage/save-asset.md) and is referenced here by the key returned by that call, which has the context `TOKEN_RAW_IMAGE`. Only supported in `sourceImage`.

#### Request example

```json
{
  "source": "FILE_KEY",
  "sourceImage": "0192a3f4-7b21-7c44-9e1a-3f5b8c2d1e04/TOKEN_FACE_IMAGE",
  "targetImage": "0192a3f4-7b21-7c44-9e1a-3f5b8c2d1e04/TOKEN_BEST_IMAGE"
}
```

### Responses

#### `200` Success

#### Response parameters

| Parameter                  | Type   | Description                                                |
| -------------------------- | ------ | ---------------------------------------------------------- |
| `consumerId`               | string | Identifier of the consumer that made the call.             |
| `transactionId`            | string | Transaction identifier.                                    |
| `timestamp`                | string | Response timestamp in **ISO 8601**.                        |
| `message`                  | string | Descriptive field for the service execution result.        |
| `facialMatchingResult`     | string | Facial matching result: `POSITIVE`, `NEGATIVE` or `ERROR`. |
| `facialMatchingConfidence` | number | Matching confidence. **1.0 = 100%**                        |

#### Response example

```json
{
  "consumerId": "consumer-web",
  "transactionId": "e96e85a4-3f94-4000-b639-15c4f18c345b",
  "timestamp": "2026-06-26T12:00:06.000Z",
  "message": "Service executed ok",
  "facialMatchingResult": "POSITIVE",
  "facialMatchingConfidence": 0.99153554
}
```

#### Other responses

| Code  | Description                                                                                                                                                                                                                                                                                                                                                            |
| ----- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `400` | Required field missing or value not accepted; the header `operation-id` is missing when references are present; a key is not of the form `{operationId}/{CONTEXTO}` or declares a context that the slot does not allow; or a referenced asset could not be resolved to an image.                                                                                       |
| `401` | Token is missing, invalid, or expired.                                                                                                                                                                                                                                                                                                                                 |
| `403` | The consumer is not provisioned for the service `FACIAL_MATCHING`, or the content sent with `source` equal to `FILE` is older than the tenant's configured retention period.                                                                                                                                                                                           |
| `404` | The operation declared in `operation-id` does not exist or belongs to another consumer.                                                                                                                                                                                                                                                                                |
| `410` | The operation declared in `operation-id` has expired.                                                                                                                                                                                                                                                                                                                  |
| `422` | A key names an operation different from the one declared in `operation-id`, or the context has no stored asset.                                                                                                                                                                                                                                                        |
| `429` | The consumer has exceeded its request rate limit, or a referenced asset has exhausted its invocation budget on this endpoint. In the first case, the response includes `Retry-After`, `X-RateLimit-Limit` and `X-RateLimit-Burst`, and waiting resolves the issue; in the second case, it does not. The underlying service is not invoked, and the call is not billed. |

The body of an error response has the form described in [Middleware API v2](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2.md#respuestas-de-error).
