Batch analysis
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
analyzemethod instead. - Background processing of a single video. Use the
analyzeAsync.tasks.createmethod instead.
Model requirement
Batch analysis requires Pegasus 1.5. Set the modelName parameter to pegasus1.5.
Working with batches involves the following steps:
- Create the batch using the
createmethod. The platform returns a batch identifier and one analysis task identifier per request. - Monitor the batch using the
retrievemethod. Wait until the status reachescompleted,canceled, orexpired. - Retrieve the per-item results using the
resultsmethod. - (Optional) Cancel the batch using the
cancelmethod while the status ispendingorprocessing. - (Optional) Delete the batch using the
deletemethod after the status reachescompleted,canceled, orexpired.
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:
Parameters:
CreateAnalyzeBatchRequest
The TwelvelabsApi.analyzeAsync.CreateAnalyzeBatchRequest interface has the following properties:
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.
BatchVideoContext
The TwelvelabsApi.BatchVideoContext interface identifies the asset to analyze. Batch analysis accepts only assets. URLs and base64-encoded video data are not supported.
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.
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".
Return value: Returns an HttpResponsePromise that resolves to a TwelvelabsApi.CreateAnalyzeBatchResponse object.
The TwelvelabsApi.CreateAnalyzeBatchResponse interface contains the following properties:
CreatedBatchItem
The TwelvelabsApi.CreatedBatchItem interface contains the following properties:
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:
Parameters:
The TwelvelabsApi.analyzeAsync.BatchesListRequest interface has the following properties:
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:
Parameters:
Return value: Returns an HttpResponsePromise that resolves to a TwelvelabsApi.AnalyzeBatchStatusResponse object.
The TwelvelabsApi.AnalyzeBatchStatusResponse interface contains the following properties:
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:
Parameters:
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:
BatchItemError
The TwelvelabsApi.BatchItemError interface contains the following properties:
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
queuedstatus. - Finishes the analysis for the items in the
processingstatus.
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:
Parameters:
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:
Parameters:
Return value: Returns an HttpResponsePromise that resolves to void. If successful, the platform returns a 204 No Content response.
API Reference: Delete a batch