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

# Delete File

> Permanently erase a file and everything produced from it.

Permanently deletes a file, along with its analysis, its reports, and every conversation that used it, including file comparisons. You can delete a file that is live or already archived. A successful call returns `204 No Content`.

> [!NOTE]
>
> This endpoint requires the permanent file deletion feature to be enabled for your organisation. Without it, the API returns `403` with `request.organisations.feature-flag.not-enabled`. [Learn more](/guides/feature-modules.md).

> [!WARNING]
>
> Deletion is **irreversible**; there is no restore endpoint. Confirm the action before calling this endpoint.

## Permission

Requires `organisation_files:purge`, which the Owner role holds by default. A caller without it receives `403` with `request.cases.case-file.action-not-permitted`.

To delete a file you did not upload, you also need `organisation_files:read`; otherwise the API returns `404`.

An API key never counts as the uploader of a file, so it always needs both permissions. A key granted `organisation_files:purge` is treated as also holding `organisation_files:read`, so purge alone is enough.

## Archive or Delete

| | [Archive File](/api-reference/endpoints/files-archive.md) | Delete File |
| - | - | - |
| Permission | `organisation_files:delete` | `organisation_files:purge` |
| Effect | Hides the file from all live API responses | Erases the file and everything produced from it |
| File data, analysis, and conversations | Kept | Erased |
| Reversible | No | No |

Archive a file to remove it from view and keep its data. Delete it when the data itself must be erased.

If the same document was uploaded more than once, its uploads can share some analysis outputs, such as reports. A shared output is erased when the last file that uses it is deleted.

## Best Practices

1. **Wait for processing to finish**: A file can only be deleted once its analysis has finished. Deleting it earlier returns `409 Conflict` with `request.cases.case-file.not-ready-for-deletion`; try again shortly.
2. **Call again after a `502`**: If the API cannot erase every stored copy, it returns `502` with `request.cases.case-file.delete-failed`. The file is already hidden and cannot be used again. Call the endpoint again to finish deleting it.
3. **Treat `404` after a retry as done**: Once a deletion has completed, further calls return `404 Not Found`.

## Audit Log

Each deletion is recorded in your organisation's audit log as `file.deleted`, with the file ID, the case, and the conversations that were deleted. The file name is not recorded.

## Related

* [Archive File](/api-reference/endpoints/files-archive.md) hides a file and keeps its data.
* [Case Management](/guides/case-management.md#permanently-deleting-a-file) covers deletion in context.


## OpenAPI

````yaml DELETE /cases/{caseId}/files/{fileId}
openapi: 3.1.0
info:
  title: Veridox Core API
  description: Veridox Core Platform API
  version: 0.0.1
  contact: {}
servers:
  - url: https://api.uk.veridox.ai
    description: Live (UK)
  - url: https://api.ca.veridox.ai
    description: Live (CA)
security: []
tags:
  - name: Status
    description: System status and health check endpoints
  - name: Cases
    description: Case and case file management
  - name: Organisations
    description: Organisation management
  - name: Document Requests
    description: Document request management
  - name: Search
    description: Search functionality
  - name: Admin
    description: Administrative endpoints
paths:
  /cases/{caseId}/files/{fileId}:
    delete:
      tags:
        - Case Files
      summary: Permanently delete a file
      description: >-
        Permanently deletes a file: every stored version of it and of its
        analysis outputs, its database record, and every conversation that used
        it, including file comparisons. Outputs another file still uses through
        the analysis cache (an upload of the same document) are kept until that
        file is deleted. This cannot be undone. Requires
        organisation_files:purge (archive is organisation_files:delete); a
        non-owned file additionally requires organisation_files:read. Live and
        archived files can be deleted once analysis has finished. If storage
        cannot be cleared the request returns 502 and the file stays hidden;
        calling again finishes the deletion.
      operationId: CaseFilesController_deleteFile
      parameters:
        - name: fileId
          required: true
          in: path
          description: File ID
          schema:
            type: string
        - name: caseId
          required: true
          in: path
          description: Case ID
          schema:
            type: string
      responses:
        '204':
          description: File permanently deleted
        '400':
          description: Invalid caseId or fileId (must be a valid UUID)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorDto'
        '401':
          description: Unauthorized (invalid or missing authentication token)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorDto'
        '403':
          description: Caller lacks organisation_files:purge, or the feature is not enabled
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorDto'
        '404':
          description: >-
            File not found, does not belong to this organisation, or caller
            lacks reach to it
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorDto'
        '409':
          description: Analysis has not finished yet
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorDto'
        '429':
          description: Too many requests (rate limit exceeded)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorDto'
        '502':
          description: >-
            Stored objects could not be removed; the file is hidden and a retry
            finishes it
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorDto'
      security:
        - api-key: []
components:
  schemas:
    ErrorDto:
      type: object
      properties:
        error_code:
          type: string
          description: Machine-readable error code for programmatic handling
          examples:
            - request.cases.file.missing-risk-score
            - request.authentication.invalid-token
            - request.forbidden
            - request.cases.case.not-found
            - request.cases.case.already-locked
        error_message:
          type: string
          description: Human-readable error message explaining what went wrong
          example: >-
            User tried to perform an invalid operation on a file without a risk
            score.
        error_details:
          type: object
          example:
            field: email_address
      required:
        - error_code
        - error_message
  securitySchemes:
    api-key:
      type: apiKey
      in: header
      name: x-api-key

````

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