> 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/document-services/document-validation/buenas-practicas.md). Agents can also search and read this documentation through its [MCP server](https://docs.facephi.com/~gitbook/mcp).

# Best practices

### Polling strategy

Check the status using phased polling, since resolution time can vary significantly between transactions:

* **Phase 1 (fast polling, first \~10 seconds)**: poll every 1 second. This covers the typical case, where the transaction resolves quickly.
* **Phase 2 (exponential backoff, starting at \~10 seconds if there is still no terminal state)**: progressively increase the interval (e.g., 2s → 4s → 8s → 15s), capped at 15–20 seconds between polls. This covers cases that require additional analysis and may take substantially longer.
* Set a maximum wait time on the consumer side (e.g., several minutes). If it is exceeded, treat the case as indeterminate and retry later or contact support.
* Do not assume a fixed response time: duration can vary substantially between transactions, since some require additional internal analysis before resolving.

### Handling states

* `COMPLETED`: read `diagnostic` and, if it is `DECLINED` or `DOUBTFUL`, `rejectionReason`/`diagnostics[]` to inform the end user. A `DOUBTFUL` is not a rejection: the analysis was inconclusive, and the decision is yours to make (see [Service modalities](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/document-services/document-validation.md#modalidades-del-servicio)).
* `ERROR` / `FAILED`: treat as an integration or service error. Check the submitted data and retry if appropriate.
* `FAILED` with `failureReason = Validation could not be completed`: transient processing failure (including internal analysis timeouts). It is safe to retry by starting a new transaction with the same assets (see [Check status](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/document-services/document-validation/consultar-estado.md)). For other values of `failureReason`, consult its table in [Check status](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/document-services/document-validation/consultar-estado.md#failurereason).

### Security

* Do not store the OAuth2 token on the client. Renew it according to its expiration (see [Authentication](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/autenticacion.md)).
* Use the same `operationId` when uploading assets and in the `operation-id` header when starting validation: all `fileKeys` in a request must belong to the same operation.
* Create the operation **when capture starts**, not before: it expires after 15 minutes by default, and an expired operation requires creating another one and uploading the assets again.
* Resend each `fileKey` exactly as returned by `POST /storage`, without constructing or interpreting it. If you need to retrieve them, use [Get File Keys](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/operations/get-file-keys.md).
* Treat `transactionId` as an opaque identifier. Do not infer information from its format.

### Support traceability

To investigate a specific case with support, keep and provide the following identifiers:

* **`transactionId`**: primary transaction identifier (returned by `POST /document/validate` and in every status query). This is the key piece of information for locating a case.
* **Response header `X-Trace-Id`**: request identifier returned by the API in each response; it allows support to correlate the exact call. We recommend saving it alongside the `transactionId`.
* **`timestamp`** of the transaction (ISO-8601 format) and the identifiers you provide in the headers: `operation-id` and `consumer-id`.

When opening a support ticket, always include the `transactionId` (and the `X-Trace-Id` if you have recorded it). Check with Facephi for the retention periods applicable to your integration.
