> ## Documentation Index
> Fetch the complete documentation index at: https://docs.identifai.net/llms.txt
> Use this file to discover all available pages before exploring further.

# Validate a media file

> Check whether an image, a video or an audio file can be analyzed, **without submitting it for classification**: the file is not stored, no classification is started and **no credits are consumed**.

The file is checked against the requirements of the models that would analyze it. These models are resolved exactly as in the classification endpoints, from your pricing plan and from the options sent with the request: to get a meaningful result, send the same options (e.g. `with_morphing`, `with_heatmap`, `with_audio`) you are going to use for the actual submission.

The checks performed are:

- **File type and size**: the same formats and limits of the corresponding classification endpoint ([image](./submit-an-image-for-classification), [video](./submit-a-video-for-classification), [audio](./submit-a-speech-for-classification)).
- **Minimum resolution** (image and video): the short side of the media must satisfy the minimum size required by every selected model.
- **Minimum video resolution** (video only): the video height must satisfy the minimum resolution supported by the platform (e.g. 720p).

The outcome is always reported in the `valid` field of the response: `true` with status `200` when the media can be analyzed, `false` with status `422` or `413` when it cannot, together with a `detail` explaining the reason.



## OpenAPI

````yaml post /api/validate
openapi: 3.0.0
info:
  title: identifAI API
  version: 1.0.0
  description: >-
    API for integrating identifAI's image and video classification
    capabilities.<br><details><summary>**How to obtain your API
    Key**</summary>To obtain your API key, follow these simple steps:  
    <ol><li><p>**Create a user profile and log in to the platform**</p>If you
    don't have an account yet, visit our platform and create a user profile.
    Once you've completed registration and verified your email, log in with your
    credentials.</li><li><p>**Access the user menu**</p>After logging in, click
    on your name or the user icon in the top-right corner of the
    screen.</li><li><p>**Select the API Key option**</p>In the dropdown menu
    that appears, select the "API Key" option. From there, you can view or
    generate your API key.</li></ol>Now you are ready to use your API key in our
    API!</details><details><summary>**How to use the API**</summary>To use the
    API, first make a **POST** request to start the classification. Then, use
    the provided ***identifier*** from the **POST** request to retrieve the
    results.

    <details>

    <summary>**1. Image Classification**</summary>
      * To classify an image, you need to make a **POST** request to `/api/classification` with the required parameters (for details on the parameters, refer to the *"Classification"* section below).
      * In the response, you will receive the ***identifier*** of the classified image.
      * Use the provided ***identifier*** to retrieve the classification results by making a **GET** request to `/api/classification/{identifier}` (for details on how to structure this request, see the *"Classification"* section below).
      * The response will contain the classification results for the image in JSON format.<br>In the response, you will find a ***results*** array, which includes the classification results for each model used, and a ***verdicts*** array, which contains the results for each heuristic applied.<br>If the classification is not yet complete, continue sending the **GET** request until the result is available.</details><details><summary>**2. Video Classification**</summary>
        * To classify a video, you need to make a **POST** request to `/api/classification_video` with the required parameters (for details on the parameters, refer to the *"Classification"* section below).
        * In the response, you will receive the ***identifier*** of the classified video.
        * Use the provided ***identifier*** to retrieve the classification results by making a **GET** request to `/api/classification_video/{identifier}` (for details on how to structure this request, see the *"Classification"* section below).
        * The response will provide the classification results for the video in JSON format. For video classification, the video is divided into *frames*.<br> In the response, you will find a ***results*** array that includes the classification outcomes for each model applied to each analyzed frame, and a ***verdicts*** array containing the results for each heuristic used.<br> If the classification is not complete, continue sending the **GET** request until the final results are returned.</details><details><summary>**3. All Classifications**</summary>The `/api/classifications` endpoint will return all the image classifications made by a user. This will list the results of all past image classification requests.</details><details><summary>**4. User Management**</summary>  The **POST** `/api/user` endpoint allows you to create a user, while the **DELETE** `/api/user` endpoint is used to delete a user (For the structure of the requests, see more in the user section below).</details></details>
servers:
  - url: https://backend.identifai.net
security: []
tags:
  - name: Classification
    description: Classification routes
  - name: Infrastructure
    description: Infrastructure routes
  - name: User
    description: User actions
  - name: Partner
    description: Partner actions
paths:
  /api/validate:
    post:
      tags:
        - Classification
      summary: Validate a media file
      description: >-
        Check whether an image, a video or an audio file can be analyzed,
        **without submitting it for classification**: the file is not stored, no
        classification is started and **no credits are consumed**.


        The file is checked against the requirements of the models that would
        analyze it. These models are resolved exactly as in the classification
        endpoints, from your pricing plan and from the options sent with the
        request: to get a meaningful result, send the same options (e.g.
        `with_morphing`, `with_heatmap`, `with_audio`) you are going to use for
        the actual submission.


        The checks performed are:


        - **File type and size**: the same formats and limits of the
        corresponding classification endpoint
        ([image](./submit-an-image-for-classification),
        [video](./submit-a-video-for-classification),
        [audio](./submit-a-speech-for-classification)).

        - **Minimum resolution** (image and video): the short side of the media
        must satisfy the minimum size required by every selected model.

        - **Minimum video resolution** (video only): the video height must
        satisfy the minimum resolution supported by the platform (e.g. 720p).


        The outcome is always reported in the `valid` field of the response:
        `true` with status `200` when the media can be analyzed, `false` with
        status `422` or `413` when it cannot, together with a `detail`
        explaining the reason.
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                type:
                  type: string
                  enum:
                    - image
                    - video
                    - audio
                  description: >-
                    The kind of media to validate. Video and audio validation
                    require the same enablement of the corresponding
                    classification endpoints.
                file:
                  type: string
                  format: binary
                  description: >-
                    The media file to validate. Supported formats and maximum
                    size depend on `type` and are the same of the corresponding
                    classification endpoint:
                    [image](./submit-an-image-for-classification),
                    [video](./submit-a-video-for-classification),
                    [audio](./submit-a-speech-for-classification).
                with_morphing:
                  type: boolean
                  description: >-
                    Image and video only. Set it to true to validate the file
                    also against the models used to analyze people's faces
                    (morphing).
                with_tampering:
                  type: boolean
                  description: >-
                    Image and video only. Set it to true to validate the file
                    also against the models used to analyze signs of tampering
                    or manipulation.
                with_heatmap:
                  type: boolean
                  description: >-
                    Image only. Set it to true to validate the file also against
                    the models used to produce the AI content heatmap.
                with_nsfw:
                  type: boolean
                  description: >-
                    Image and video only. Set it to true to validate the file
                    also against the models used for NSFW (Not Safe For Work)
                    content detection.
                with_audio:
                  type: boolean
                  description: >-
                    **[BETA]** Video only. Set it to true to validate the file
                    also against the models used to analyze the audio track of
                    the video. **You must be enabled in your pricing plan to use
                    it**, otherwise the parameter is ignored.
              required:
                - type
                - file
      responses:
        '200':
          description: >-
            The media is valid and can be submitted for classification with the
            given options.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MediaValidation'
              examples:
                image:
                  summary: Valid image
                  value:
                    valid: true
                    filesize: 1048576
                    mimetype: image/jpeg
                    width: 1920
                    height: 1080
                    models:
                      - image_model_a
                      - image_model_b
                audio:
                  summary: Valid audio
                  value:
                    valid: true
                    filesize: 524288
                    mimetype: audio/mpeg
                    width: null
                    height: null
                    models:
                      - audio_model_a
        '400':
          description: >-
            The request contains the wrong parameters: missing or unsupported
            `type`, missing `file`, or a file whose format or size is not
            accepted for the given `type`.
          content:
            application/json:
              examples:
                invalid_type:
                  value:
                    error:
                      type:
                        - The selected type is invalid.
                missing_file:
                  value:
                    error:
                      file:
                        - The file field is required.
                invalid_image_format:
                  value:
                    error:
                      file:
                        - >-
                          The file must be a file of type: png, jpg, jpeg, gif,
                          webp, tif, tiff.
                not_a_video:
                  value:
                    error:
                      file:
                        - The file must be a video file.
        '401':
          description: Invalid or missing API key.
          content:
            application/json:
              example:
                error: Unauthorized
        '403':
          description: >-
            The user is not authorized to access this API, did not accept the
            terms of service, or is not enabled to the classification of the
            requested media `type` (video or audio).
          content:
            application/json:
              example:
                error: Unauthorized
        '413':
          description: >-
            The media is not valid: the file size exceeds the maximum allowed
            size for the requested `type`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MediaValidationError'
              example:
                valid: false
                detail: >-
                  The image file size (73400320 bytes) exceeds the maximum
                  allowed size of 52428800 bytes.
        '422':
          description: >-
            The media is not valid and cannot be analyzed with the given options
            (e.g. corrupted file, resolution too low for the selected models),
            or no models are available for the selected options in your pricing
            plan.
          content:
            application/json:
              examples:
                corrupted_file:
                  summary: Corrupted file
                  value:
                    valid: false
                    detail: >-
                      Invalid or corrupted image file: cannot identify image
                      file
                quality_requirements:
                  summary: Resolution too low for the selected models
                  value:
                    valid: false
                    detail: >-
                      Media does not meet the quality requirements for the
                      requested models: 'image_model_a' requires a minimum size
                      of 256px, got 128px.
                video_resolution:
                  summary: Video resolution too low
                  value:
                    valid: false
                    detail: >-
                      Video resolution too low: got 640x360, minimum required
                      height is 720px (720p).
                not_an_audio:
                  summary: Not an audio file
                  value:
                    valid: false
                    detail: >-
                      Invalid file type. Must be an audio file: sample.mp3,
                      application/octet-stream
                no_models:
                  summary: No models available for the selected options
                  value:
                    message: No available models for the selected options
        '429':
          description: Too many requests.
          content:
            application/json:
              example:
                message: Too Many Attempts.
      security:
        - ApiKeyAuth: []
components:
  schemas:
    MediaValidation:
      type: object
      properties:
        valid:
          type: boolean
          description: >-
            Always `true` for a successful validation: the media can be
            submitted for classification with the given options.
        filesize:
          type: integer
          description: Size of the validated file, in bytes.
        mimetype:
          type: string
          description: >-
            MIME type detected from the file content (e.g. `image/jpeg`,
            `video/mp4`, `audio/mpeg`).
        width:
          type: integer
          nullable: true
          description: Width of the media in pixels. `null` for audio files.
        height:
          type: integer
          nullable: true
          description: Height of the media in pixels. `null` for audio files.
        models:
          type: array
          description: >-
            Identifiers of the models the media has been validated against,
            resolved from your pricing plan and the selected options.
          items:
            type: string
      required:
        - valid
        - filesize
        - mimetype
        - models
    MediaValidationError:
      type: object
      properties:
        valid:
          type: boolean
          description: 'Always `false`: the media cannot be analyzed with the given options.'
        detail:
          type: string
          description: Human-readable reason why the media is not valid.
      required:
        - valid
        - detail
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      name: X-Api-Key
      in: header
      description: Your API key.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.