Async analysis

The AnalyzeAsync.Tasks interface provides methods to analyze videos asynchronously and generate text based on their content. Use these methods for videos longer than 1 hour.

When to use this interface:

  • Analyze videos longer than 1 hour
  • Process videos up to 2 hours
  • Avoid blocking your application during video processing

Do not use this interface for:

  • Videos under 1 hour for which you need immediate results or real-time streaming. Use the analyze method instead.
  • Minimum duration: 4 seconds
  • Maximum duration: 2 hours
  • Formats: FFmpeg supported formats
  • Resolution: 360x360 to 5184x2160 pixels
  • Aspect ratio: Between 1:1 and 1:2.4, or between 2.4:1 and 1:1

Analyzing videos asynchronously requires three steps:

  1. Create an analysis task using the create method. The platform returns a task ID.
  2. Poll the status of the task using the retrieve method. Wait until the status is ready.
  3. Retrieve the results from the response when the status is ready using the retrieve method.

Methods

List analysis tasks

Description: This method returns a list of the analysis tasks in your account. The platform returns your analysis tasks sorted by creation date, with the newest at the top of the list.

Function signature and example:

1list(
2 request?: TwelvelabsApi.analyzeAsync.TasksListRequest,
3 requestOptions?: Tasks.RequestOptions
4): core.HttpResponsePromise<TwelvelabsApi.analyzeAsync.TasksListResponse>

Parameters:

NameTypeRequiredDescription
requestTwelvelabsApi.analyzeAsync.TasksListRequestNoParameters for listing analysis tasks.
requestOptionsTasks.RequestOptionsNoRequest-specific configuration.

The TwelvelabsApi.analyzeAsync.TasksListRequest 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.AnalyzeTaskStatusNoFilter analysis tasks by status. Values: queued, pending, processing, ready, failed.

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

The TwelvelabsApi.analyzeAsync.TasksListResponse interface contains the following properties:

NameTypeDescription
dataTwelvelabsApi.AnalyzeTaskResponse[]An array that contains up to pageLimit analysis tasks.
pageInfoTwelvelabsApi.PageInfoAn object that provides information about pagination.

The TwelvelabsApi.PageInfo interface contains the following properties:

NameTypeDescription
limitPerPagenumberThe number of items returned per page.
pagenumberThe current page number.
totalPagenumberThe total number of pages.
totalResultsnumberThe total number of analysis tasks in your account.

For details about AnalyzeTaskResponse, see Retrieve task status and results.

API Reference: List async analysis tasks

Create an async analysis task

Description: This method asynchronously analyzes a video and generates text based on its content.

Note

This method is rate-limited. For details, see the Rate limits page.

Function signature and example:

1create(
2 request: TwelvelabsApi.analyzeAsync.CreateAsyncAnalyzeRequest,
3 requestOptions?: Tasks.RequestOptions
4): core.HttpResponsePromise<TwelvelabsApi.CreateAnalyzeTaskResponse>

Parameters:

NameTypeRequiredDescription
requestTwelvelabsApi.analyzeAsync.CreateAsyncAnalyzeRequestYesParameters for creating an async analysis task.
requestOptionsTasks.RequestOptionsNoRequest-specific configuration.

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

NameTypeRequiredDescription
videoTwelvelabsApi.VideoContextYesAn object that specifies the source of the video. See VideoContext for details.
promptstringYesA prompt that guides the model on the desired format or content. Your prompts can be instructive or descriptive, or you can also phrase them as questions. The maximum length is 2,000 tokens.
temperaturenumberNoControls the randomness of the text output. Higher values generate more creative text, while lower values produce more deterministic output. Default: 0.2. Min: 0. Max: 1.
maxTokensnumberNoThe maximum number of tokens to generate. Min: 1. Max: 4096.
responseFormatTwelvelabsApi.ResponseFormatNoSpecifies the format of the response. If you omit this parameter, the platform returns unstructured text.

VideoContext

The TwelvelabsApi.VideoContext type specifies the source of the video. Provide exactly one of the following:

TypeFieldTypeDescription
VideoContext.UrlurlstringThe publicly accessible URL of the video file. Use direct links to raw media files. Video hosting platforms and cloud storage sharing links are not supported.
VideoContext.AssetIdassetIdstringThe unique identifier of an asset from a direct or multipart upload.
VideoContext.Base64Stringbase64StringstringThe base64-encoded video data. The maximum size is 30 MB.

Set the type discriminator field to "url", "asset_id", or "base64_string" to indicate which source you are providing.

Return value: Returns an HttpResponsePromise that resolves to a TwelvelabsApi.CreateAnalyzeTaskResponse object containing the task details.

The TwelvelabsApi.CreateAnalyzeTaskResponse interface contains the following properties:

NameTypeDescription
taskIdstringThe unique identifier of the analysis task.
statusTwelvelabsApi.AnalyzeTaskStatusThe initial status of the task. Value: queued.

API Reference: Create an async analysis task

Retrieve task status and results

Description: This method retrieves the status and results of an analysis task.

Task statuses:

  • queued: The task is waiting to be processed.
  • pending: The task is queued and waiting to start.
  • processing: The platform is analyzing the video.
  • ready: Processing is complete. Results are available in the response.
  • failed: The task failed. No results were generated.

Call this method repeatedly until status is ready or failed. When status is ready, use the results from the response.

Function signature and example:

1retrieve(
2 taskId: string,
3 requestOptions?: Tasks.RequestOptions
4): core.HttpResponsePromise<TwelvelabsApi.AnalyzeTaskResponse>

Parameters:

NameTypeRequiredDescription
taskIdstringYesThe unique identifier of the analysis task.
requestOptionsTasks.RequestOptionsNoRequest-specific configuration.

Return value: Returns an HttpResponsePromise that resolves to a TwelvelabsApi.AnalyzeTaskResponse object containing the task status and results.

The TwelvelabsApi.AnalyzeTaskResponse interface contains the following properties:

NameTypeDescription
taskIdstringThe unique identifier of the analysis task.
statusTwelvelabsApi.AnalyzeTaskStatusThe current status of the task. Values: queued, pending, processing, ready, failed.
createdAtDateThe date and time when the task was created, in RFC 3339 format.
completedAtDateThe date and time when the task completed or failed, in RFC 3339 format. The platform returns this field only when status is ready or failed.
resultTwelvelabsApi.AnalyzeTaskResultAn object that contains the generated text and additional information. The platform returns this object only when status is ready.
errorTwelvelabsApi.AnalyzeTaskErrorDetails about why the task failed. The platform returns this object only when status is failed.
webhooksTwelvelabsApi.AnalyzeTaskWebhookInfo[]The delivery status of each webhook endpoint. The platform omits this field when there are no webhooks configured.

The TwelvelabsApi.AnalyzeTaskResult interface contains the following properties:

NameTypeDescription
generationIdstringThe unique identifier for the generation session.
datastringThe generated text based on the prompt you provided.
finishReasonTwelvelabsApi.FinishReasonThe reason the generation stopped. Values: null (generation has not finished), stop (the model reached the end of the response).
usageTwelvelabsApi.AnalyzeTaskResultUsageThe number of tokens used in the generation.

The TwelvelabsApi.AnalyzeTaskResultUsage interface contains the following properties:

NameTypeDescription
outputTokensnumberThe number of tokens in the generated text.
inputTokensnumberThe number of tokens in the input prompt.

The TwelvelabsApi.AnalyzeTaskError interface contains the following properties:

NameTypeDescription
messagestringA message that describes why the task failed.

API Reference: Retrieve analysis task status and results

Delete an analysis task

Description: This method deletes an analysis task. You can only delete tasks that are not currently being processed.

Function signature and example:

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

Parameters:

NameTypeRequiredDescription
taskIdstringYesThe unique identifier of the analysis task.
requestOptionsTasks.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 an analysis task