> 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/storage/save-asset.md).

# Save Asset

Service that stores an asset in the context of an operation and returns the key used to reference it later.

### Endpoint

```
POST /storage
```

### Headers

| Name              | Type   | Required | Description                                                                                                                             |
| ----------------- | ------ | -------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| **Authorization** | string | **Yes**  | Consumer token in `Bearer <token>`. See [Authentication](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/autenticacion.md). |
| **consumer-id**   | string | **Yes**  | Consumer identifier.                                                                                                                    |

### Request body

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

#### Parameters

| Parameter       | Type   | Required | Description                                                                                                                                                                                                                                                                                                                                                                                                     |
| --------------- | ------ | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `operationId`   | string | **Yes**  | Identifier of the operation to which the asset belongs, as returned by [Create Operation](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/operations/create-operation.md).                                                                                                                                                                                                                          |
| `asset`         | object | **Yes**  | Asset to store.                                                                                                                                                                                                                                                                                                                                                                                                 |
| `asset.context` | string | **Yes**  | Asset context. Supports `TOKEN_FRONT_DOCUMENT`, `TOKEN_BACK_DOCUMENT`, `TOKEN_FACE_IMAGE`, `TOKEN_BEST_IMAGE`, `TOKEN_BIN_IAD` and `RAW_IMAGE`. `TOKEN_RAW_IMAGE` is not supported here: it is the context in which an upload is stored `RAW_IMAGE`, and specifying it is rejected with `400`. See [Asset contexts](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/storage.md#contextos-de-asset). |
| `asset.file`    | string | **Yes**  | Asset content encoded in **Base64**, in the format required by its context.                                                                                                                                                                                                                                                                                                                                     |

{% hint style="warning" %}
Each context requires a specific format. The four tokenized contexts, `TOKEN_FRONT_DOCUMENT`, `TOKEN_BACK_DOCUMENT`, `TOKEN_FACE_IMAGE` and `TOKEN_BEST_IMAGE`, require the tokenized buffer generated by the capture SDK; a JPEG or PNG image in Base64 is rejected in these contexts with `400`. `TOKEN_BIN_IAD` accepts the capture binary. `RAW_IMAGE` is the only context that accepts an unencrypted JPEG or PNG image in Base64.
{% endhint %}

The maximum size per asset is **10 MiB**, applied to the encoded content.

#### Request example

```json
{
  "operationId": "0192a3f4-7b21-7c44-9e1a-3f5b8c2d1e04",
  "asset": {
    "context": "TOKEN_FRONT_DOCUMENT",
    "file": "<base64>"
  }
}
```

### Responses

#### `200` Success

#### Response parameters

| Parameter        | Type   | Description                                                                                                                                                                                    |
| ---------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `fileKey`        | string | Asset key, in the form `{operationId}/{CONTEXTO}`. It is forwarded unchanged when referencing the asset.                                                                                       |
| `derivedFileKey` | string | Key of the asset derived by this upload, in the same format. It only appears in an upload `TOKEN_BIN_IAD` from which the best image was derived. See [Derived contexts](#contextos-derivados). |
| `timestamp`      | string | Response timestamp in **ISO 8601**.                                                                                                                                                            |

#### Example response

```json
{
  "fileKey": "0192a3f4-7b21-7c44-9e1a-3f5b8c2d1e04/TOKEN_FRONT_DOCUMENT",
  "timestamp": "2026-06-26T12:00:03.000Z"
}
```

On upload, `RAW_IMAGE` the key's context is not the one declared: the unencrypted image is tokenized upon receipt, and the response returns `TOKEN_RAW_IMAGE`, which is the context used to reference the asset from then on.

```json
{
  "fileKey": "0192a3f4-7b21-7c44-9e1a-3f5b8c2d1e04/TOKEN_RAW_IMAGE",
  "timestamp": "2026-06-26T12:00:03.000Z"
}
```

#### Derived contexts

When storing an asset, `TOKEN_BIN_IAD` the context `TOKEN_BEST_IMAGE` from the same operation is also made available, containing the best image from that capture. You can store your own `TOKEN_BEST_IMAGE` later; if one is already stored, it is kept.

The response returns the key for that best image in `derivedFileKey`, ready to use in validations that accept it, such as a liveness check or facial comparison:

```json
{
  "fileKey": "0192a3f4-7b21-7c44-9e1a-3f5b8c2d1e04/TOKEN_BIN_IAD",
  "derivedFileKey": "0192a3f4-7b21-7c44-9e1a-3f5b8c2d1e04/TOKEN_BEST_IMAGE",
  "timestamp": "2026-06-26T12:00:03.000Z"
}
```

`derivedFileKey` identifies what that upload derived, so it does not appear when the operation already had its own `TOKEN_BEST_IMAGE` stored: in that case, nothing is derived and the existing one is kept. It also does not appear when uploading any other context.

Check [Get File Keys](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/operations/get-file-keys.md) to confirm which contexts are available in the operation.

#### Other responses

| Code  | Description                                                                                                                                                                                                                                                                     |
| ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `400` | The `operationId` is not in the expected format, the content does not match the declared context, the declared context is not supported for upload (`TOKEN_RAW_IMAGE`, which can only be obtained by uploading `RAW_IMAGE`), or the asset is empty or exceeds the maximum size. |
| `403` | The consumer is not provisioned with the `STORAGE`.                                                                                                                                                                                                                             |
| `404` | service. The operation does not exist or belongs to another consumer.                                                                                                                                                                                                           |
| `409` | An asset with that context already exists in the operation, or the submitted content has already been stored.                                                                                                                                                                   |
| `410` | The operation has expired.                                                                                                                                                                                                                                                      |
| `429` | The consumer has exceeded its request rate limit. The response includes `Retry-After` with the number of seconds to wait, and `X-RateLimit-Limit` and `X-RateLimit-Burst` with the current thresholds.                                                                          |
| `503` | The unencrypted image from a `RAW_IMAGE` upload could not be tokenized. Nothing is stored.                                                                                                                                                                                      |

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