---
url: https://api-doc.aive.com/getting-started/error-handling.md
description: How errors are reported by API
---

# Error handling

This page describes how errors are reported by the public GraphQL API and how to handle the most common failure cases across the upload, analysis, and scoring workflows.

## Typed mutation errors

Mutations do not return GraphQL errors for expected business failures specific to that mutation, such as a container that doesn't exist or is already being analyzed. Instead, each mutation returns a **union** of a success result and one or more typed error results, so your client can branch on a `code` field instead of parsing error strings.

For example, `scoreContainer` returns a `ScoreContainerOutput`, which is either a `ScoreContainerResult` or a `ScoreContainerError`. Always select both branches:

```graphql
mutation ScoreContainer($input: ScoreContainerInput!) {
  scoreContainer(input: $input) {
    ... on ScoreContainerResult {
      score
    }
    ... on ScoreContainerError {
      code
      message
    }
  }
}
```

An unexpected/internal failure (not something your input can cause) is still returned as a regular top-level GraphQL error.

## Standard errors

A fixed set of cross-cutting failures — missing permission, insufficient credit, and invalid input — is common to virtually every mutation (and to some queries too). Unlike the failures above, these are **never** part of a mutation's typed union, no matter which operation triggered them: they are always returned as a regular top-level GraphQL error, with a `code` in the error's `extensions`:

```json
{
  "errors": [
    {
      "message": "Missing permission",
      "extensions": { "code": "MISSING_PERMISSION" }
    }
  ]
}
```

| Code                        | Meaning                                                                                                               |
| --------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| `MISSING_PERMISSION`        | Your account does not have permission to perform this operation on the given resource.                                |
| `INSUFFICIENT_CREDITS`      | The workspace does not have enough credits for this operation.                                                        |
| `GRAPHQL_VALIDATION_FAILED` | The input failed validation (also used for malformed request bodies). `extensions.err` carries the validation detail. |
| `RESOURCE_NOT_FOUND`        | A referenced resource does not exist, or you do not have access to it.                                                |
| `QUERY_COMPLEXITY_EXCEEDED` | The request was rejected for being too expensive to execute; simplify or split it into smaller requests.              |
| `INTERNAL_SERVER_ERROR`     | An unexpected failure on our end, not something your input can fix.                                                   |

Because these codes are identical across every operation, a single generic handler in your client (e.g. redirect on `MISSING_PERMISSION`, prompt a credit top-up on `INSUFFICIENT_CREDITS`) covers all of them, instead of branching per mutation the way you do for [typed mutation errors](#typed-mutation-errors).

## Idempotency

Some mutations are **not idempotent**. Calling them multiple times for the same resource can create duplicate data or trigger unexpected side effects.

* `uploadContainer` is **not idempotent**. Do not call it multiple times for the same upload unless you are explicitly retrying after a failure.

## Retry behavior

Retry behavior depends on the mutation and the state of the resource:

* **Upload**: if an upload is interrupted, only the missing parts need to be uploaded again. If container extraction fails, verify that every part was uploaded and that the multipart upload was finalized successfully, then call `uploadContainer` again to restart extraction.
* **Analysis**: calling `analyseContainer` on a container that is already being analyzed, or has already been analyzed, is ignored — the API does not start a new analysis process in this case.
* **Scoring**: `scoreContainer` can be called multiple times for the same container, for example to compare scores across different templates. Each scoring request is processed independently.

## Common error codes

### `createUpload`

| Error code | Description                    |
| ---------- | ------------------------------ |
| `notFound` | The upload could not be found. |

### `finalizeUpload`

| Error code | Description               |
| ---------- | ------------------------- |
| `notFound` | The upload was not found. |

### `uploadContainer`

| Error code              | Description                                                     |
| ----------------------- | --------------------------------------------------------------- |
| `uploadMaxSizeExceeded` | The uploaded file exceeds the maximum workspace available size. |
| `folderNotFound`        | The destination folder does not exist.                          |
| `depositNotFound`       | The referenced deposit does not exist.                          |

### `analyseContainer`

| Error code          | Description                              |
| ------------------- | ---------------------------------------- |
| `alreadyInProgress` | The container is already being analyzed. |

### `scoreContainer`

| Error code             | Description                                                                           |
| ---------------------- | ------------------------------------------------------------------------------------- |
| `containerNotFound`    | The specified container does not exist.                                               |
| `containerNotAnalyzed` | The container has not been analyzed yet or does not have the required analysis level. |
| `missingVideoStream`   | The container does not contain any video stream.                                      |
| `templateNotFound`     | The specified scoring template does not exist.                                        |

### `createMontageFromContainer`

| Error code             | Description                                                               |
| ---------------------- | ------------------------------------------------------------------------- |
| `containerNotAnalyzed` | At least one stream of the container has not been successfully analyzed.  |
| `missingVideoStream`   | The container does not contain any video stream, e.g. an audio-only file. |

### `updateMontage`

| Error code        | Description                                                                      |
| ----------------- | -------------------------------------------------------------------------------- |
| `MontageIsLocked` | The montage is locked. Only the creator of a locked montage can still update it. |

### `renderMontages` and `renderMontageFromSettings`

| Error code               | Description                                                  |
| ------------------------ | ------------------------------------------------------------ |
| `presetNotAvailable`     | A preset is not available for the montage you are rendering. |
| `invalidRenditionParams` | A preset's settings are not valid for the montage's content. |

## Best practices

* Always select both branches of a mutation's output union (`...Result` and `...Error`) so you can handle typed errors without relying on GraphQL-level errors.
* Always check the status of a container (`uploadStatus`) before triggering the next step in the workflow (analysis, scoring). See [Event handling](/getting-started/event-handling) for the full list of status values.
* Verify that a container has been analyzed with a sufficient `manifestLevel` (at least `L`) before attempting to score it.
* Make sure the container contains a video stream before scoring it.
* Treat non-idempotent mutations, such as `uploadContainer`, with care to avoid duplicate processing.
