---
url: https://api-doc.aive.com/guides/generate-montage.md
---
# Generate a montage

The Aive API allows you to automatically generate a video montage from one or more analyzed source streams, then save the result as a montage.

Generating a montage is a two-step process:

1. Use the `generateMontageContent` mutation to have Aive assemble montage content from your source footage, according to a template.
2. Save that content by either creating a new montage with `createMontage`, or replacing the content of an existing montage with `updateMontage`.

## Prerequisites

Before generating montage content:

* You know your workspace ID and have listed the available templates. Retrieving a workspace ID and listing templates works exactly the same way as for scoring — follow [steps 1 and 2 of Score a container](/guides/score-container#step-1-get-your-workspace-id) if you haven't done so yet. The same templates are used for montage generation; the selected template drives the montage's target format and duration.
* The container(s) whose footage you want to use have completed upload and analysis with at least `manifestLevel: S`, since shot detection is required to generate montage content. The analysis must be finished, with every stream's `analysisStatus` at `succeeded`: generating while it is still running fails. See [Analyse a container](/guides/analyse-container#monitor-analysis-status).
* You know the ID of at least one video stream to base the montage on, and, optionally, the ID of an audio stream to pair with it.
* If you plan to save the result with `updateMontage`, you know the ID of the existing montage to update.

## Step 1 - Identify your source streams

Each container exposes its underlying streams. Query them to find the `id` of the video (and, optionally, audio) stream you want to use.

### ContainerStreams query

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

### ContainerStreams variables

```json
{
  "id": "<container_id>"
}
```

### ContainerStreams response

```json
{
  "data": {
    "container": {
      "streams": [
        { "id": "<video_stream_id>", "__typename": "VideoStream" },
        { "id": "<audio_stream_id>", "__typename": "AudioStream" }
      ]
    }
  }
}
```

Keep the `id` of the video stream, and of the audio stream if you want a synced audio lane generated for it.

## Step 2 - Generate montage content

Use the `generateMontageContent` mutation to have Aive run AI video suggestion against your linked streams and assemble montage content matching the selected template's target format.

You can link streams from more than one container to combine footage from several source videos into a single generated montage.

### GenerateMontageContent mutation

```graphql
mutation GenerateMontageContent($input: GenerateMontageContentInput!) {
  generateMontageContent(input: $input) {
    ... on GenerateMontageContentResult {
      content
    }
  }
}
```

### GenerateMontageContent variables

```json
{
  "input": {
    "workspaceId": "<workspace_id>",
    "templateId": "<template_id>",
    "linkedStreams": [
      {
        "videoStreamId": "<video_stream_id>",
        "audioStreamId": "<audio_stream_id>"
      }
    ]
  }
}
```

### GenerateMontageContent input parameters

| Parameter                       | Type                 | Description                                                                                                                                      |
|---------------------------------|----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|
| `workspaceId`                   | ID                   | The workspace you're working within.                                                                                                             |
| `templateId`                    | ID                   | The template used to drive the generated montage's format, duration, and content rules.                                                          |
| `linkedStreams`                 | \[LinkedStreamInput!] | The video (and optionally paired audio) streams to generate the montage from. Must contain at least one entry.                                   |
| `linkedStreams[].videoStreamId` | ID                   | The ID of the video stream to use.                                                                                                               |
| `linkedStreams[].audioStreamId` | ID                   | Optional. The ID of an audio stream to pair with the video stream — when set, Aive generates an AI-synced audio lane following the video's cuts. |

### GenerateMontageContent response

The mutation returns a `MontageContent` value: an opaque JSON object describing the generated lanes (video, audio, text, image, subtitle), time markers, and settings. See the [`MontageContent`](/api/types/scalars/montage-content) reference for its full shape.

You don't need to construct or modify this content yourself — pass it as-is to `createMontage` or `updateMontage` in the next step.

## Step 3 - Save the montage

Once you have generated montage content, save it either by creating a new montage or by updating an existing one.

### Option A - Create a new montage

Use `createMontage` to save the generated content as a brand-new montage in a folder.

#### CreateMontage mutation

```graphql
mutation CreateMontage($input: CreateMontageInput!) {
  createMontage(input: $input) {
    ... on CreateMontageResult {
      id
    }
  }
}
```

#### CreateMontage variables

```json
{
  "input": {
    "folderId": "<folder_id>",
    "name": "<montage_name>",
    "content": "<generated_montage_content>"
  }
}
```

`content` is the `MontageContent` JSON object itself, not a string: replace the placeholder, quotes included, with the `content` object returned by `generateMontageContent`.

#### CreateMontage input parameters

| Parameter  | Type           | Description                                                                    |
|------------|----------------|--------------------------------------------------------------------------------|
| `folderId` | ID             | The destination folder for the new montage.                                    |
| `name`     | String         | The name of the montage.                                                       |
| `content`  | MontageContent | The initial content, typically the value returned by `generateMontageContent`. |

#### CreateMontage response

```json
{
  "data": {
    "createMontage": {
      "id": "<montage_id>"
    }
  }
}
```

### Option B - Update an existing montage

Use `updateMontage` to replace an existing montage's content wholesale with freshly generated content.

#### UpdateMontage mutation

```graphql
mutation UpdateMontage($input: UpdateMontageInput!) {
  updateMontage(input: $input) {
    ... on UpdateMontageResult {
      ack
    }
    ... on UpdateMontageError {
      code
      message
    }
  }
}
```

#### UpdateMontage variables

```json
{
  "input": {
    "id": "<montage_id>",
    "content": "<generated_montage_content>"
  }
}
```

#### UpdateMontage input parameters

| Parameter | Type           | Description                                                        |
|-----------|----------------|--------------------------------------------------------------------|
| `id`      | ID             | The ID of the montage to update.                                   |
| `content` | MontageContent | The new content, replacing the montage's current content entirely. |

#### UpdateMontage response

```json
{
  "data": {
    "updateMontage": {
      "ack": true
    }
  }
}
```

## Errors

`generateMontageContent` and `createMontage` do not return mutation-specific typed errors — failures such as a missing permission, insufficient credits, or a folder/template/stream that doesn't exist surface as [standard errors](/getting-started/error-handling#standard-errors).

`updateMontage` returns a typed error through its output union:

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

See [Error handling](/getting-started/error-handling) for how these errors are returned.

## Best practices

* Analyze source containers with at least `manifestLevel: S` before generating montage content, and prefer higher levels for richer results.
* Treat the `content` value returned by `generateMontageContent` as opaque — pass it straight through to `createMontage`/`updateMontage` rather than modifying it, unless you specifically need to adjust the [`MontageContent`](/api/types/scalars/montage-content) structure.
* Use `createMontage` to save a new montage, and `updateMontage` to regenerate and replace the content of a montage you've already created.
* Expect `updateMontage` to fail with `MontageIsLocked` if another user currently has the montage locked; only the montage's creator can update it while it's locked.
