Batch analysis

Requires Pegasus 1.5

The AnalyzeAsync.Batches interface provides methods to submit up to 1,000 video analysis requests in a single call, monitor batch progress, retrieve per-item results, and cancel or delete batches.

When to use this interface:

  • Run the same model and analysis settings across many videos.
  • Track a single batch instead of many individual analysis tasks.

Do not use this interface for:

  • Single videos that require immediate results. Use the analyze method instead.
  • Background processing of a single video. Use the analyzeAsync.tasks.create method instead.
Model requirement

Batch analysis requires Pegasus 1.5. Set the modelName parameter to pegasus1.5.

Working with batches involves the following steps:

  1. Create the batch using the create method. The platform returns a batch identifier and one analysis task identifier per request.
  2. Monitor the batch using the retrieve method. Wait until the status reaches completed, canceled, or expired.
  3. Retrieve the per-item results using the results method.
  4. (Optional) Cancel the batch using the cancel method while the status is pending or processing.
  5. (Optional) Delete the batch using the delete method after the status reaches completed, canceled, or expired.

For schema details and status definitions, see the The batch object page.

Methods

Create a batch

Description: Use this method to submit many video analysis requests in a single call. Each request creates an analysis task. The response contains one batch identifier and one task identifier per request. Use the batch identifier to check progress and retrieve results.

Limits:

  • Up to 1,000 requests per batch.
  • Up to 2,000 total content hours per batch.
  • Up to 5 active batches per account.

Retention: Batches expire 24 hours after creation. You can retrieve results for 30 days after creation. If processing does not finish for some items in time, resubmit them in a new batch.

Function signature and example:

1create(
2 request: TwelvelabsApi.analyzeAsync.CreateAnalyzeBatchRequest,
3 requestOptions?: Batches.RequestOptions
4): core.HttpResponsePromise<TwelvelabsApi.CreateAnalyzeBatchResponse>

Parameters:

NameTypeRequiredDescription
requestTwelvelabsApi.analyzeAsync.CreateAnalyzeBatchRequestYesParameters for creating a batch. See CreateAnalyzeBatchRequest.
requestOptionsBatches.RequestOptionsNoRequest-specific configuration.

CreateAnalyzeBatchRequest

The TwelvelabsApi.analyzeAsync.CreateAnalyzeBatchRequest interface has the following properties:

NameTypeRequiredDescription
modelNameTwelvelabsApi.analyzeAsync.CreateAnalyzeBatchRequestModelNameYesThe video understanding model to use for every item in this batch. Batch analysis requires Pegasus 1.5. Value: "pegasus1.5".
analysisModeTwelvelabsApi.analyzeAsync.CreateAnalyzeBatchRequestAnalysisModeYesThe analysis approach for every item in this batch. Values:
- "general": Generate text from each video based on the prompt (the item’s prompt field if set, otherwise defaults.prompt). Supports structured JSON output by using json_schema in the responseFormat.type field.
- "time_based_metadata": Extract timestamped metadata by using segment_definitions in the responseFormat.type field.
Batches with mixed modes are not supported.
requestsTwelvelabsApi.BatchItemRequest[]YesThe analysis requests in the batch. Provide 1 to 1,000 requests, with a combined video duration of up to 2,000 hours. See BatchItemRequest.
defaultsTwelvelabsApi.BatchDefaultsNoDefault values applied to every item that does not override them. See BatchDefaults.

BatchItemRequest

The TwelvelabsApi.BatchItemRequest interface describes a single analysis request inside a batch. Identify the asset in the video field. Every other field is optional and overrides the matching field in the defaults object.

NameTypeRequiredDescription
videoTwelvelabsApi.BatchVideoContextYesThe asset to analyze. See BatchVideoContext.
customIdstringNoAn optional identifier you set per item when you create the batch. Use this field to map batch results back to records in your system, for example, to correlate each result with the source video in your database. The platform stores this value unchanged and returns it in batch responses and task responses. Format: 1 to 64 characters. Alphanumeric, hyphens (-), and underscores (_) only. The value must be unique within a batch.
promptTwelvelabsApi.BatchPromptNoOverride the defaults.prompt value for this item. See BatchPrompt.
responseFormatTwelvelabsApi.AsyncResponseFormatNoOverride the defaults.responseFormat value for this item. For the type definition, see the Create an async analysis task method.
temperaturenumberNoOverride the defaults.temperature value for this item.
maxTokensnumberNoOverride the defaults.maxTokens value for this item.
minSegmentDurationnumberNoOverride the defaults.minSegmentDuration value for this item.
maxSegmentDurationnumberNoOverride the defaults.maxSegmentDuration value for this item.
startTimenumberNoOverride the defaults.startTime value for this item.
endTimenumberNoOverride the defaults.endTime value for this item.

BatchVideoContext

The TwelvelabsApi.BatchVideoContext interface identifies the asset to analyze. Batch analysis accepts only assets. URLs and base64-encoded video data are not supported.

NameTypeRequiredDescription
typestringYesSet this field to "asset_id".
assetIdstringYesThe unique identifier of an asset from a direct or multipart upload. The asset status must be ready. Use assets.retrieve to check the status.

BatchDefaults

The TwelvelabsApi.BatchDefaults interface defines default values applied to every item that does not override them. Every field is optional. Items in the requests array override these values. To override the prompt or responseFormat field, provide the full object on the item. You cannot change only some of its nested fields.

NameTypeRequiredDescription
promptTwelvelabsApi.BatchPromptNoThe default prompt applied to every item. See BatchPrompt.
responseFormatTwelvelabsApi.AsyncResponseFormatNoThe default response format applied to every item. For the type definition, see the Create an async analysis task method.
temperaturenumberNoControls the randomness of the text output. Default: 0.2. Min: 0. Max: 1.
maxTokensnumberNoThe maximum number of tokens to generate per item. For Pegasus 1.5 general mode: Min: 512, Max: 98,304. For Pegasus 1.5 time_based_metadata mode: Min: 2,048, Max: 98,304.
minSegmentDurationnumberNoMinimum duration for each extracted segment, in seconds. Applies only when the analysisMode field is "time_based_metadata". Min: 2.
maxSegmentDurationnumberNoMaximum duration for each extracted segment, in seconds. Must be greater than or equal to the minSegmentDuration field. Applies only when the analysisMode field is "time_based_metadata". Min: 2.
startTimenumberNoStart of the analysis window, in seconds, applied to every item. Use with endTime to analyze only the [startTime, endTime) portion of each video. If omitted, defaults to 0. Must be less than endTime. Mutually exclusive with responseFormat.segmentDefinitions[].timeRanges.
endTimenumberNoEnd of the analysis window, in seconds, applied to every item. Use with startTime to analyze only the [startTime, endTime) portion of each video. If omitted, defaults to the video duration. Must be greater than startTime. Mutually exclusive with responseFormat.segmentDefinitions[].timeRanges.

BatchPrompt

The TwelvelabsApi.BatchPrompt interface defines a structured prompt with <@name> placeholders for referencing images. Not supported when the analysisMode field is "time_based_metadata".

NameTypeRequiredDescription
inputTextstringYesThe text of the prompt. Use <@name> placeholders to reference images declared in mediaSources. This text counts toward the context window.
mediaSourcesTwelvelabsApi.SmeMediaSource[]NoReference images for the <@name> placeholders in the prompt. Maximum 4 sources. For the type definition, see SmeMediaSource on the Async analysis page.

Return value: Returns an HttpResponsePromise that resolves to a TwelvelabsApi.CreateAnalyzeBatchResponse object.

The TwelvelabsApi.CreateAnalyzeBatchResponse interface contains the following properties:

NameTypeDescription
batchIdstringThe unique identifier of the batch.
statusTwelvelabsApi.BatchStatusThe initial status of the batch. Values: pending, processing, canceling, canceled, completed, expired.
totalItemsnumberThe number of items submitted in the batch.
createdAtDateThe date and time, in the RFC 3339 format, when the batch was created.
expiresAtDateThe date and time, in the RFC 3339 format, when the batch expires. Unfinished items at expiration are canceled.
itemsTwelvelabsApi.CreatedBatchItem[]One entry per submitted item. Each entry pairs the unique task identifier generated by the platform with the custom identifier you provided. See CreatedBatchItem.

CreatedBatchItem

The TwelvelabsApi.CreatedBatchItem interface contains the following properties:

NameTypeDescription
taskIdstringThe unique task identifier generated by the platform for this item. Use this value with analyzeAsync.tasks.retrieve to retrieve the task’s status and results.
customIdstringThe custom identifier you provided when you created the batch. If you did not provide one, this field is null.

API Reference: Create a batch

List batches

Description: This method returns a list of the batch objects in your account. The platform returns your batches sorted by creation date, with the newest batch first.

Function signature and example:

1list(
2 request?: TwelvelabsApi.analyzeAsync.BatchesListRequest,
3 requestOptions?: Batches.RequestOptions
4): Promise<core.Page<TwelvelabsApi.AnalyzeBatchStatusResponse>>

Parameters:

NameTypeRequiredDescription
requestTwelvelabsApi.analyzeAsync.BatchesListRequestNoParameters for listing batches.
requestOptionsBatches.RequestOptionsNoRequest-specific configuration.

The TwelvelabsApi.analyzeAsync.BatchesListRequest interface has the following properties:

NameTypeRequiredDescription
pagenumberNoA number that identifies the page to retrieve. Default: 1.
pageLimitnumberNoThe number of items to return on each page. Default: 10. Max: 50.
statusTwelvelabsApi.BatchStatus | TwelvelabsApi.BatchStatus[]NoFilter batches by status. Provide one or more values to include batches matching any of them. If omitted, the response includes batches in all statuses.
analysisModeTwelvelabsApi.analyzeAsync.BatchesListRequestAnalysisModeItem | TwelvelabsApi.analyzeAsync.BatchesListRequestAnalysisModeItem[]NoFilter batches by analysis mode. Provide one or more values to include batches matching any of them. Values: "general", "time_based_metadata". If omitted, the response includes batches in all analysis modes.

Return value: Returns a promise that resolves to a core.Page<TwelvelabsApi.AnalyzeBatchStatusResponse> object. The page is an async iterable that yields batches across pages. For the per-batch object schema, see Retrieve batch status below.

API Reference: List batches

Retrieve batch status

Description: Use this method to monitor a batch. The response includes the current batch status and counts for queued, processing, ready, failed, and canceled items.

Poll this method until the batch reaches the completed, canceled, or expired status. To retrieve the results, call the results method.

Note

Do not treat the completed status as a success signal. It means processing has finished for every item, not that every analysis succeeded. To see how many items succeeded, failed, or were canceled, check the readyItems, failedItems, and canceledItems fields. A batch never has the failed status.

Function signature and example:

1retrieve(
2 batchId: string,
3 requestOptions?: Batches.RequestOptions
4): core.HttpResponsePromise<TwelvelabsApi.AnalyzeBatchStatusResponse>

Parameters:

NameTypeRequiredDescription
batchIdstringYesThe unique identifier of the batch.
requestOptionsBatches.RequestOptionsNoRequest-specific configuration.

Return value: Returns an HttpResponsePromise that resolves to a TwelvelabsApi.AnalyzeBatchStatusResponse object.

The TwelvelabsApi.AnalyzeBatchStatusResponse interface contains the following properties:

NameTypeDescription
batchIdstringThe unique identifier of the batch.
analysisModestringThe analysis mode applied to every item in this batch. Values: "general", "time_based_metadata".
modelNamestringThe model used for every item in this batch.
statusTwelvelabsApi.BatchStatusThe current batch status. Values: pending, processing, canceling, canceled, completed, expired.
totalItemsnumberThe number of items submitted in the batch.
queuedItemsnumberThe number of items in the queued status.
processingItemsnumberThe number of items in the processing status.
readyItemsnumberThe number of items that completed successfully.
failedItemsnumberThe number of items that failed.
canceledItemsnumberThe number of items that were canceled, either because the batch was canceled while the item was in the queued status, or because the batch expired before the item finished processing.
createdAtDateThe date and time, in the RFC 3339 format, when the batch was created.
expiresAtDateThe date and time, in the RFC 3339 format, when the batch expires.
completedAtDateThe date and time, in the RFC 3339 format, when the batch status became completed. Present only when the status is completed.
canceledAtDateThe date and time, in the RFC 3339 format, when the batch status became canceled. Present only when the status is canceled.
expiredAtDateThe date and time, in the RFC 3339 format, when the batch status became expired. Present only when the status is expired.
webhooksTwelvelabsApi.AnalyzeTaskWebhookInfo[]The delivery status of each webhook endpoint for the batch completion notification. Present only after the platform sends the webhook notifications. To register webhooks, see the Webhooks page.

API Reference: Retrieve batch status

Retrieve batch results

Description: Use this method to retrieve the results for each item in a batch. You can call it while the batch has the pending or processing status.

Each result entry has a status. For details on each status, see the Item statuses section on the The batch object page.

Each result entry includes a task identifier in the taskId field. Use this value with analyzeAsync.tasks.retrieve if you need the full analysis task response.

You can retrieve results for 30 days after batch creation.

The method streams the response. Iterate over the resolved stream to receive one BatchResultItem per batch item.

Function signature and example:

1results(
2 batchId: string,
3 requestOptions?: Batches.RequestOptions
4): core.HttpResponsePromise<core.Stream<TwelvelabsApi.BatchResultItem>>

Parameters:

NameTypeRequiredDescription
batchIdstringYesThe unique identifier of the batch.
requestOptionsBatches.RequestOptionsNoRequest-specific configuration.

Return value: Returns an HttpResponsePromise that resolves to a core.Stream<TwelvelabsApi.BatchResultItem> object. The stream is an async iterable that yields one BatchResultItem per batch item.

The TwelvelabsApi.BatchResultItem interface contains the following properties:

NameTypeDescription
taskIdstringThe unique task identifier generated by the platform for this item.
customIdstringThe custom identifier you provided when you created the batch. If you did not provide one, this field is null.
statusTwelvelabsApi.BatchItemStatusThe current status of the result entry. Values: queued, processing, ready, failed, canceled.
dataTwelvelabsApi.AnalyzeTaskResultThe analysis result for an entry in the ready status. The analysis text is in this object’s nested data field. The envelope uses the same schema as the result field on analyzeAsync.tasks.retrieve.
errorTwelvelabsApi.BatchItemErrorFailure details for an entry in the failed status. See BatchItemError.

BatchItemError

The TwelvelabsApi.BatchItemError interface contains the following properties:

NameTypeDescription
codestringA machine-readable error code identifying the failure category. May be omitted.
messagestringA human-readable explanation of the failure.

API Reference: Retrieve batch results

Cancel a batch

Description: Use this method to request cancellation for a batch with the pending or processing status.

When you invoke this method, the platform performs the following steps:

  • Cancels the items in the queued status.
  • Finishes the analysis for the items in the processing status.

The batch status changes to canceling immediately, and to canceled after every item reaches ready, failed, or canceled. You are not billed for canceled or failed items.

Function signature and example:

1cancel(
2 batchId: string,
3 requestOptions?: Batches.RequestOptions
4): core.HttpResponsePromise<TwelvelabsApi.AnalyzeBatchStatusResponse>

Parameters:

NameTypeRequiredDescription
batchIdstringYesThe unique identifier of the batch.
requestOptionsBatches.RequestOptionsNoRequest-specific configuration.

Return value: Returns an HttpResponsePromise that resolves to a TwelvelabsApi.AnalyzeBatchStatusResponse object that reflects the batch state at the time of the request. The batch status is canceling until every item reaches ready, failed, or canceled, then becomes canceled. To confirm the batch is fully canceled, call the retrieve method. For the return type properties, see Retrieve batch status.

API Reference: Cancel a batch

Delete a batch

Description: Use this method to delete a batch and all the tasks associated with it. You can only delete batches with status completed, canceled, or expired.

Deleting a batch does not affect billing. You are billed for every completed analysis regardless of whether you delete the batch afterward.

To stop a batch with the pending or processing status, use the cancel method.

Batches are deleted 30 days after creation.

Function signature and example:

1delete(
2 batchId: string,
3 requestOptions?: Batches.RequestOptions
4): core.HttpResponsePromise<void>

Parameters:

NameTypeRequiredDescription
batchIdstringYesThe unique identifier of the batch.
requestOptionsBatches.RequestOptionsNoRequest-specific configuration.

Return value: Returns an HttpResponsePromise that resolves to void. If successful, the platform returns a 204 No Content response.

API Reference: Delete a batch