> 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/security-compliance/injection-attack-detection.md). Agents can also search and read this documentation through its [MCP server](https://docs.facephi.com/~gitbook/mcp).

# Injection Attack Detection (IAD)

Service that analyzes the capture and determines whether the video stream was injected instead of coming from the device's camera.

Accepts the binary inline or by referencing the asset `TOKEN_BIN_IAD`. A single asset slot, interpreted according to `source`.

### Endpoint

```
POST /behavioral/iad
```

### 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 for providing 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). |
| `file`       | string  | **Yes**  | IAD capture: asset key `TOKEN_BIN_IAD` or the binary in Base64.                                                                                                                    |
| `longDetail` | boolean | No       | Requests the engine telemetry in `additionalInfo`. By default `false`. Supported `longDetails` as an alternative name.                                                             |

#### Request example

```json
{
  "source": "FILE_KEY",
  "file": "0192a3f4-7b21-7c44-9e1a-3f5b8c2d1e04/TOKEN_BIN_IAD",
  "longDetail": true
}
```

### Responses

#### `200` Success

#### Response parameters

| Parameter               | Type   | Description                                                                                                                                                                                                                                                                                                   |
| ----------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `consumerId`            | string | ID of the consumer that made the call.                                                                                                                                                                                                                                                                        |
| `transactionId`         | string | Transaction ID.                                                                                                                                                                                                                                                                                               |
| `timestamp`             | string | Response timestamp in **ISO 8601**.                                                                                                                                                                                                                                                                           |
| `message`               | string | Descriptive field containing the result of the service execution.                                                                                                                                                                                                                                             |
| `captureLivenessResult` | string | Service verdict: `ATTACK` when the capture was injected instead of being taken with the camera (or, with [additional deepfake detection](#deteccion-adicional-de-deepfakes), when the image is a deepfake or an AI-generated face), `NO_ATTACK` when it was not, and `ERROR` when it could not be determined. |
| `reason`                | string | Reason behind the verdict. `None` when the capture is accepted. See [Rejection reasons](#motivos-de-rechazo).                                                                                                                                                                                                 |
| `additionalInfo`        | object | Engine telemetry. Returned only if requested with `longDetail`. See [Engine telemetry](#telemetria-del-motor).                                                                                                                                                                                                |

#### Response example

```json
{
  "consumerId": "consumer-web",
  "transactionId": "a29cbe15-2b68-495f-b7eb-be985b21c486",
  "timestamp": "2026-06-26T12:00:05.000Z",
  "message": "OK",
  "captureLivenessResult": "ATTACK",
  "reason": "UntrustedContent",
  "additionalInfo": {
    "id": "6f3b2c18-91a4-4d77-bb02-0c5e9d8a1f36",
    "score": 0.2,
    "probability": 0.2,
    "captureStartTimestamp": "2026-06-26T12:00:01.420Z",
    "captureEndTimestamp": "2026-06-26T12:00:04.870Z"
  }
}
```

Without `longDetail`, the field `additionalInfo` is returned as `null` and the rest of the response is identical.

#### Rejection reasons

`reason` takes one of these values:

| Value                           | Meaning                                                                                                                                                               |
| ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `None`                          | The capture was accepted as `Live`.                                                                                                                                   |
| `UntrustedContent`              | An injection attack was detected.                                                                                                                                     |
| `UntrustedContentLowConfidence` | There are indications of an injection attack, but with lower confidence. The capture is still rejected.                                                               |
| `UntrustedEnvironment`          | The execution environment is not considered trusted.                                                                                                                  |
| `UntrustedDevice`               | The device could not be trusted to be what it claims to be.                                                                                                           |
| `UntrustedCorruptedPayload`     | The capture appears to be corrupted or tampered with.                                                                                                                 |
| `SuspiciousActivity`            | The device exhibited activity patterns associated with an attack.                                                                                                     |
| `SdkIntegrityViolation`         | The capture SDK or its libraries appear to have been tampered with.                                                                                                   |
| `Unknown`                       | The engine could not assign the response to any of the reasons above.                                                                                                 |
| `DeepFakeDetected`              | A deepfake was detected in the image extracted from the capture. This only appears with [additional deepfake detection](#deteccion-adicional-de-deepfakes).           |
| `AiGeneratedDetected`           | An AI-generated face was detected in the image extracted from the capture. This only appears with [additional deepfake detection](#deteccion-adicional-de-deepfakes). |

A capture rejected by replay mitigation returns `reason` with the value `Replay attack detected`, which is not included in this list.

#### Additional deepfake detection

Facephi can enable deepfake detection in your integration as an add-on service, in addition to injection attack detection. It only applies to captures accepted by injection detection: the still image extracted from the capture is checked to determine whether it is a deepfake or an AI-generated face.

* If a deepfake is detected, `captureLivenessResult` becomes `ATTACK` with `reason` `DeepFakeDetected`.
* Otherwise, if an AI-generated face is detected, `captureLivenessResult` becomes `ATTACK` with `reason` `AiGeneratedDetected`.
* If neither is detected, the response remains unchanged.

With additional detection enabled, `captureLivenessResult` reflects the combined result of both checks, so it may indicate `ATTACK` even if injection detection did not identify an attack. The response does not include any new fields: `reason` identifies which check prompted the rejection.

A capture that injection detection has already rejected as `ATTACK`, including one rejected by replay mitigation, is returned as is, with its original `reason` . If the additional check cannot be completed—for example, because the image could not be extracted or no response was received in time—the injection detection verdict is retained, and the request does not return an error as a result. `additionalInfo` continues to reflect the injection detection engine's telemetry.

{% hint style="info" %}
With additional detection enabled, a response to a capture accepted by injection detection may take a few seconds longer.
{% endhint %}

#### Engine telemetry

With `longDetail` set to `true`, the response may include `additionalInfo` with these keys:

| Key                     | Description                                                                                                   |
| ----------------------- | ------------------------------------------------------------------------------------------------------------- |
| `id`                    | Opaque identifier for the engine telemetry record. Useful for referencing a capture when escalating an issue. |
| `score`                 | Verdict score calculated by the engine.                                                                       |
| `probability`           | Verdict score calculated by the engine.                                                                       |
| `captureStartTimestamp` | Start of the capture window, as reported by the capture SDK.                                                  |
| `captureEndTimestamp`   | End of the capture window, as reported by the capture SDK.                                                    |

{% hint style="warning" %}
Requesting telemetry does not guarantee that you will receive it: `additionalInfo` is `null` when no record was available for that request, and each key is omitted independently if the engine did not report it. Do not make your integration dependent on it being present.
{% endhint %}

{% hint style="info" %}
When storing a `TOKEN_BIN_IAD` with [Save Asset](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/storage/save-asset.md) the context `TOKEN_BEST_IMAGE` from the same operation is also made available, so a single call prepares the IAD and selfie assets.
{% endhint %}

#### Other responses

| Code  | Description                                                                                                                                                                                                                                                                                                                                                                                        |
| ----- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `400` | Required field missing or unsupported value; the `operation-id` header is missing despite references being present; a key is not in the form `{operationId}/{CONTEXTO}` or specifies a context that the slot does not accept; or the engine rejected the capture before issuing a verdict, in which case `message` contains the code and details, as in `FACE_NOT_FOUND: NoneBecauseFaceNotFound`. |
| `401` | Token missing, invalid, or expired.                                                                                                                                                                                                                                                                                                                                                                |
| `403` | The consumer is not provisioned with the `CAPTURE_LIVENESS`.                                                                                                                                                                                                                                                                                                                                       |
| `404` | service. The operation specified in `operation-id` does not exist or belongs to another consumer.                                                                                                                                                                                                                                                                                                  |
| `410` | The operation specified in `operation-id` has expired.                                                                                                                                                                                                                                                                                                                                             |
| `422` | A key names an operation different from the one specified in `operation-id`, or no asset is stored for the context.                                                                                                                                                                                                                                                                                |
| `429` | The consumer has exceeded its request rate limit, or a referenced asset has exhausted its invocation budget for 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.                            |
| `502` | The engine could not be reached, returned an unusable response, or reported a license failure. The capture was not evaluated, and the request can be retried.                                                                                                                                                                                                                                      |
| `503` | The engine is not configured in this deployment, so the endpoint cannot handle any requests.                                                                                                                                                                                                                                                                                                       |

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).
