---
url: https://api-doc.aive.com/getting-started/event-handling.md
description: How events are notified by API
---

# Event handling

Several operations of the public GraphQL API are **asynchronous**: they are started with a mutation and run as background jobs. Instead of polling, you can subscribe to **webhook events** to be notified as soon as these operations complete. This page describes the shared status model and the webhook events used to track them.

## Asynchronous operations

The following operations are asynchronous:

* **Container extraction**, started implicitly when calling `uploadContainer`, and notified through the `extractionCompleted` webhook event.
* **Container analysis**, started with the `analyseContainer` mutation (or automatically for some workspaces), and notified through the `analysisCompleted` webhook event.

By contrast, **scoring** a container with `scoreContainer` is a **synchronous** operation: the score is returned immediately in the response.

## Webhooks

Aive can deliver events to a webhook endpoint you configure, so that your integration is notified as soon as an asynchronous operation completes, without needing to poll the API.

Webhooks are configured per workspace, from the **Settings** page of the workspace they belong to. You choose which events a webhook subscribes to when you create it.

Currently supported events:

* `extractionCompleted`
* `analysisCompleted`

### Payload

Aive sends an HTTP `POST` request to your configured endpoint with a JSON body. The body always has an `event` field, plus one field matching that event name with the details:

```json
{
  "event": "extractionCompleted",
  "extractionCompleted": {
    "containerId": "<container_id>",
    "status": "succeeded"
  }
}
```

```json
{
  "event": "analysisCompleted",
  "analysisCompleted": {
    "containerId": "<container_id>",
    "status": "succeeded"
  }
}
```

Both events are emitted **whether the operation succeeds or fails** — check the `status` field to know the outcome.

### `extractionCompleted`

Emitted when a container upload extraction finishes. It is triggered by the `uploadContainer` mutation described in [Upload a container](/guides/upload-container).

Use this event to know when a container is ready to use, instead of polling its status.

### `analysisCompleted`

Emitted when a container analysis finishes. It is triggered by the `analyseContainer` mutation, or automatically for workspaces configured to start analysis right after a successful upload. See [Analyse a container](/guides/analyse-container).

Use this event to know when a container has been analyzed and can be scored, instead of polling its status.

## Status values

The `status` field of the `extractionCompleted` webhook event and the `uploadStatus` field on `Container` share the same set of values:

| Status | Description |
| --------- | ------------- |
| `pending` | Waiting in the processing queue. |
| `running` | The extraction is currently in progress. |
| `succeeded` | The extraction completed successfully. |
| `failed` | The extraction failed. |

The `status` field of the `analysisCompleted` webhook event is either `succeeded` or `failed`, since the event is only sent once the analysis has finished.

The `analysisStatus` field on each stream of a container takes one of `pending`, `running`, `succeeded` or `failed`. It is `null` when the stream has never been analyzed.

A container can only be used for the next step of the workflow once its status is **`succeeded`**.

## Polling for status changes

**Container extraction** can be polled directly, since its status is exposed on the container itself:

```graphql
query GetContainerStatus($id: ID!) {
  container(id: $id) {
    id
    uploadStatus
  }
}
```

Continue polling until the status becomes `succeeded` (or `failed`).

**Container analysis** runs separately for each stream (audio or video) of the container, and each stream exposes its own `analysisStatus`:

```graphql
query GetContainerAnalysisStatus($id: ID!) {
  container(id: $id) {
    id
    streams {
      id
      __typename
      analysisStatus
    }
  }
}
```

Continue polling until every stream's `analysisStatus` is `succeeded` (or one of them is `failed`). The container can be used for the next step once all of its streams are `succeeded`.

## Email notifications

As an alternative (or a complement) to the `analysisCompleted` webhook, the `analyseContainer` mutation accepts a `sendNotification` parameter:

* Set it to `true` to receive an email notification when the analysis completes.
* Set it to `false` if you don't need a notification, for example if you already subscribed to the webhook event.

## Best practices

* Prefer subscribing to the `extractionCompleted` and `analysisCompleted` webhook events over polling. If you poll, do it at a reasonable interval (for example every few seconds) rather than in a tight loop.
* Configure your webhook endpoint from the workspace **Settings** page before relying on these events, and select the events it should receive.
* Use `sendNotification: true` on `analyseContainer` if your integration cannot receive webhooks.
* Treat `failed` as terminal: inspect the upload or analysis inputs before retrying.
