Skip to navigation

The AnalyzeAsyncClient.TasksClient class provides methods to analyze videos or images asynchronously, generate text, and extract structured, timestamped segments. Each request must contain a video or one or more images, but not both.

The platform supports two analysis modes:

  • General analysis: Prompt-based text generation with a video or one or more images.
  • Video segmentation: Timestamped metadata with custom segment definitions.

When to use this class:

  • Generate custom text from your video or one or more images using a prompt (general analysis)
  • Extract timestamped metadata with custom segment definitions from your video
  • Analyze videos longer than 1 hour, or a portion of a video up to 4 hours long
  • Process videos or images asynchronously without blocking your application

Do not use this class for:

  • Videos or images for which you need immediate results or real-time streaming. Use the analyze method instead.

Videos

  • The video can be up to 2 hours long, or up to 4 hours when you analyze only a portion of it. You can analyze between 1 second and 2 hours of the video. HLS and base64 videos are limited to 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

Images

  • You can provide one to twenty images per request.
  • Formats: JPEG, PNG, WebP, GIF, and BMP.
  • Maximum size: 20 MB per image.
  • Maximum pixel count: 16,777,216 pixels per image (width × height).

In legacy billing, on the Free plan, analysis hours count toward a shared limit that also covers indexing - the number of segment definitions does not affect this limit. On paid plans, you pay based on how much video you process and how many segment definitions you include - see the Frequently asked questions page for examples. In the new billing, the allowances of your plan apply. See Plans, allowances, and overage.

Analyzing content asynchronously requires three steps:

  1. Create an analysis task using the create method. The platform returns a task identifier.
  2. Poll the status of the task using the retrieve method. Wait until the status is ready, failed, or canceled.
  3. When the status is ready, retrieve the results 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:

def list(
self,
*,
page: typing.Optional[int] = None,
page_limit: typing.Optional[int] = None,
status: typing.Optional[AnalyzeTaskStatus] = None,
video_url: typing.Optional[str] = None,
asset_id: typing.Optional[str] = None,
analysis_mode: typing.Optional[TasksListRequestAnalysisMode] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> TasksListResponse:

Parameters:

NameTypeRequiredDescription
pageintNoA number that identifies the page to retrieve. Default: 1.
page_limitintNoThe number of items to return on each page. Default: 10. Max: 50.
statusAnalyzeTaskStatusNoFilter analysis tasks by status. Values: queued, pending, processing, ready, failed, canceled.
video_urlstrNoFilter tasks by exact video source URL.
asset_idstrNoFilter tasks by asset ID.
analysis_modeTasksListRequestAnalysisModeNoFilter tasks by the analysis mode used when creating the task. Values: "general", "time_based_metadata".
request_optionsRequestOptionsNoRequest-specific configuration.

Return value: Returns a TasksListResponse object.

The TasksListResponse class contains the following properties:

NameTypeDescription
dataList[AnalyzeTaskResponse]An array that contains up to page_limit analysis tasks.
page_infoPageInfoAn object that provides information about pagination.

The PageInfo class contains the following properties:

NameTypeDescription
limit_per_pageOptional[int]The number of items returned per page.
pageOptional[int]The current page number.
total_pageOptional[int]The total number of pages.
total_resultsOptional[int]The 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 analyzes a video or one or more images asynchronously. Each request must contain a video or one or more images, but not both.

The method supports two analysis modes:

  • General analysis: Prompt-based text generation with a video or one or more images.
  • Video segmentation: Timestamped metadata with custom segment definitions.

On the Free plan in legacy billing, you have a total of 600 minutes (10 hours) shared across indexing, analysis, and segmentation. For details, see the Video hours and video count limits section. In the new billing, the allowances of your plan apply in place of this limit. See Plans, allowances, and overage.

Note

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

Function signature and example:

def create(
self,
*,
model_name: typing.Optional[CreateAsyncAnalyzeRequestModelName] = OMIT,
custom_id: typing.Optional[str] = OMIT,
video: typing.Optional[VideoContext] = OMIT,
image: typing.Optional[typing.Sequence[AnalyzeImageInput]] = OMIT,
prompt: typing.Optional[str] = OMIT,
prompt_v_2: typing.Optional[AnalyzePromptV2] = OMIT,
analysis_mode: typing.Optional[CreateAsyncAnalyzeRequestAnalysisMode] = OMIT,
temperature: typing.Optional[AnalyzeTemperature] = OMIT,
max_tokens: typing.Optional[CreateAsyncAnalyzeRequestMaxTokens] = OMIT,
response_format: typing.Optional[AsyncResponseFormat] = OMIT,
min_segment_duration: typing.Optional[float] = OMIT,
max_segment_duration: typing.Optional[float] = OMIT,
start_time: typing.Optional[float] = OMIT,
end_time: typing.Optional[float] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> CreateAnalyzeTaskResponse:

Parameters:

NameTypeRequiredDescription
model_nameCreateAsyncAnalyzeRequestModelNameNoThe video understanding model to use for analysis. Values:
- "pegasus1.6": For details about this version, see the Pegasus 1.6 page.
- "pegasus1.5": For details about this version, see the Pegasus 1.5 page.
Default: "pegasus1.5"
custom_idstrNoAn optional identifier that you set when you create the task. Use this field to correlate tasks across responses, for example, to distinguish tasks by type or environment. Must match the pattern ^[a-zA-Z0-9_-]{1,64}$.
videoVideoContextNoAn object that specifies the source of the video. Mutually exclusive with the image parameter. See VideoContext for details.
imageOptional[Sequence[AnalyzeImageInput]]NoA list of up to twenty objects containing the images to analyze. For each image, include exactly one source. Requires Pegasus 1.6. Using any other model returns a parameter_invalid error.

Mutually exclusive with the video and prompt_v_2 parameters. The prompt parameter is required when you provide images. See AnalyzeImageInput for details.
promptstrNoNatural-language instructions for analyzing the video or one or more images. Required for general analysis (prompt-based text generation). Not supported when analysis_mode is "time_based_metadata". To include reference images in your prompt, use the prompt_v_2 parameter instead. Mutually exclusive with the prompt_v_2 parameter.
prompt_v_2AnalyzePromptV2NoA structured prompt that uses the <@name> placeholders to reference images. Not supported when the analysis_mode parameter is "time_based_metadata". Mutually exclusive with the prompt and image parameters. See AnalyzePromptV2.
analysis_modeCreateAsyncAnalyzeRequestAnalysisModeNoThe analysis mode for this task. Values:
- "general": Analyze the video and generate a response based on your prompt. Supports both free-form text and structured output via response_format.
- "time_based_metadata": Segment the video into time-based intervals and extract custom metadata for each segment. Requires response_format.type set to "segment_definitions".
Default: "general"
temperaturefloatNoControls the randomness of the text output. Default: 0.2, Min: 0, Max: 1
max_tokensCreateAsyncAnalyzeRequestMaxTokensNoThe maximum response length, in tokens. Provide an integer or the "unlimited" value. The allowed integer range and default depend on the analysis mode: "general" (Min: 512, Max: 98,304, Default: 4,096); "time_based_metadata" (Min: 2,048, Max: 98,304, Default: 32,768). The input and response must fit within the context window.
- Integer: With video segmentation, the task fails if the output exceeds the limit. No partial output is returned.
- Unlimited: Removes the token limit from video segmentation. It requires analysis_mode set to "time_based_metadata" and model_name set to "pegasus1.6". Mutually exclusive with response_format.segment_definitions[].time_ranges.
The platform extracts as many segments as it can. If it stops before extracting every segment, the task still completes with the status field set to "ready". The error field contains the warning that the results may be incomplete.
response_formatAsyncResponseFormatNoControls the response format. When you omit this parameter, you receive unstructured text.
min_segment_durationfloatNoMinimum duration for each extracted segment, in seconds. Prevents the model from creating very short segments. Requires analysis_mode set to "time_based_metadata". Min: 2.
max_segment_durationfloatNoMaximum duration for each extracted segment, in seconds. Breaks long continuous sections into shorter segments. Must be greater than or equal to the min_segment_duration parameter. Requires analysis_mode set to "time_based_metadata". Min: 2.
start_timefloatNoStart of the analysis window, as an absolute timestamp in seconds, based on the internal metadata of the video. Use with end_time to analyze only a portion of the video. If omitted, defaults to the internal start time of the video. Most videos start at 0, but some (for example, from cameras or broadcast recordings) may have a non-zero start time. To find the value, run ffprobe -v error -show_entries format=start_time,duration -of default=noprint_wrappers=1 your_video.mp4. Must be less than end_time and the video duration. The window (end_time - start_time) must be at least 1 second and at most 2 hours. The video may be up to 4 hours as long as the window stays within that limit. Mutually exclusive with response_format.segment_definitions[].time_ranges. Together with end_time, this parameter determines the billable video duration. If you omit both, billing uses the full video duration. For details, see the Frequently asked questions page.
end_timefloatNoEnd of the analysis window, as an absolute timestamp in seconds, based on the internal metadata of the video. Use with start_time to analyze only a portion of the video. If omitted, defaults to the internal start time of the video plus its duration. Most videos start at 0, but some (for example, from cameras or broadcast recordings) may have a non-zero start time. To find the value, run ffprobe -v error -show_entries format=start_time,duration -of default=noprint_wrappers=1 your_video.mp4. Must be greater than start_time and less than or equal to the video duration. The window (end_time - start_time) must be at least 1 second and at most 2 hours. The video may be up to 4 hours as long as the window stays within that limit. Mutually exclusive with response_format.segment_definitions[].time_ranges. Together with start_time, this parameter determines the billable video duration. If you omit both, billing uses the full video duration. For details, see the Frequently asked questions page.
request_optionsRequestOptionsNoRequest-specific configuration.

VideoContext

The VideoContext type specifies the source of the video. Provide exactly one of the following. Mutually exclusive with the image parameter.

ClassFieldTypeDescription
VideoContext_UrlurlstrThe publicly accessible URL of the video file or HLS manifest. Use direct links to raw media files, or the URL of a VOD HLS manifest. Live video streams are rejected with a 400 error. Video hosting platforms and cloud storage sharing links are not supported. For HLS sources, if the duration cannot be determined, the platform calculates it from the manifest and the duration limits apply to that value.
VideoContext_AssetIdasset_idstrThe unique identifier of an asset from a direct or multipart upload. The asset status must be ready. Use assets.retrieve to check the status.
VideoContext_Base64Stringbase_64_stringstrThe base64-encoded video data. The maximum size is 30 MB.

AnalyzeImageInput

The AnalyzeImageInput class defines an image to analyze. Provide exactly one of the url, asset_id, or base64_string fields.

NameTypeRequiredDescription
namestrYesThe name of this image. Must be unique within the image array. Can contain only letters, digits, and underscores.

To refer to a specific image in your prompt, use its name as the <@name> placeholder. Reference every image or none of them:
- If the prompt references every image, the platform analyzes each one (Example: Compare <@before> with <@after> and describe what changed.).
- If the prompt references none of them, the platform analyzes every image you provided (Example: List every visible feature in these images.).
- If the prompt references only some of the images, the platform returns a 400 error.
urlOptional[str]NoA publicly accessible HTTPS URL of the image. The platform rejects HTTP URLs.

When you send the request, the platform verifies that the URL is reachable and that the image is within the size, pixel count, and format limits. If either check fails, the platform returns a 400 error.
asset_idOptional[str]NoThe unique identifier of an uploaded asset.
base_64_stringOptional[str]NoBase64-encoded image data. The maximum decoded size is 20 MB. Supported image types: image/jpeg, image/png, image/webp, image/gif, and image/bmp. Standard and unpadded base64 encodings are both accepted.

The AsyncResponseFormat class contains the following properties:

NameTypeDescription
typeAsyncResponseFormatTypeThe response format to use. Values: "json_schema" (structured JSON conforming to a provided schema), "segment_definitions" (timestamped metadata with custom fields, requires analysis_mode set to "time_based_metadata").
json_schemaOptional[Dict[str, Optional[Any]]]Contains the JSON schema that defines the response structure. The schema must adhere to the JSON Schema Draft 2020-12 specification. For details, see the json_schema parameter in the API Reference section.
segment_definitionsOptional[List[SegmentDefinition]]Define the types of segments to extract from your video. Required when type is "segment_definitions". Minimum 1, maximum 20 definitions. The number of segment definitions affects billing. For details, see the Frequently asked questions page. See SegmentDefinition for class details.
segment_time_formatOptional[AsyncResponseFormatSegmentTimeFormat]Set the output format for the automatic start_time and end_time keys returned on each segment. Requires the type parameter set to "segment_definitions". Omitting this parameter is equivalent to setting it to "seconds". Values: "seconds" (JSON number in seconds, Example: 12.5), "hh:mm:ss" (JSON string rounded to the nearest second, Example: "00:00:13"), "hh:mm:ss.fff" (JSON string with millisecond precision, Example: "00:00:12.500"). This parameter applies only to the automatic segment boundaries (start_time and end_time). For a time_array field, it also formats the start_time and end_time of each event inside the segment. Custom timestamp fields always use their own format, regardless of the value of this field.

AnalyzePromptV2

The AnalyzePromptV2 class defines a structured prompt that uses <@name> placeholders to reference images. Mutually exclusive with the prompt and image parameters.

NameTypeRequiredDescription
input_textstrYesThe text of the prompt. Use <@name> placeholders to reference images declared in media_sources (Example: "Is there a <@tiger-1> in the video?"). This text counts toward the context window.
media_sourcesOptional[List[SmeMediaSource]]NoReference images for the <@name> placeholders in the prompt. Maximum 4 sources. See SmeMediaSource.

SegmentDefinition

The SegmentDefinition class defines a type of segment to extract from the video.

NameTypeRequiredDescription
idstrYesA unique identifier for this segment definition.
descriptionstrYesDescribe what this type of segment looks like in the video. The model uses this text to identify matching segments.
fieldsOptional[List[SegmentField]]NoCustom fields to extract for each segment instance. Maximum 20 fields. Set the type field of an item to the time_array value to extract a list of events inside each segment. See SegmentField for details.
media_sourcesOptional[List[SmeMediaSource]]NoReference images that help the model identify segments. Maximum 4 sources. See SmeMediaSource for details.

SegmentField

The SegmentField class defines a custom field to extract for each segment.

NameTypeRequiredDescription
namestrYesThe name of the field.
typeSegmentFieldTypeYesThe data type of the field. Values: "string", "boolean", "number", "integer", "array", "timestamp", "time_array". When set to "timestamp", the format property is required and controls the format of the returned value. When set to the "time_array" value, the field extracts a list of events inside each segment. Requires the items.type field to be "object" and a non-empty items.fields list. Requires Pegasus 1.6. Any other model rejects "time_array" as an invalid type and lists only the types it accepts.
descriptionstrYesInstructions that guide the model on what this field should contain and how to extract it from the video.
formatOptional[SegmentFieldFormat]NoThe output format for timestamp fields. Required when type is "timestamp". Must be omitted for any other type. Values: "seconds" (JSON number in seconds, Example: 10.5), "hh:mm:ss" (JSON string rounded to the nearest second, Example: "00:01:23"), "hh:mm:ss.fff" (JSON string with millisecond precision, Example: "00:01:23.500").
enumOptional[List[str]]NoAllowed values for this field. Maximum 100 values. Not supported when type is "timestamp".
itemsOptional[SegmentFieldItems]NoRequired when type is "array" or "time_array". For "array", specifies the type of array elements. For "time_array", set it to {"type": "object", "fields": [...]}. Not supported when type is "timestamp". See SegmentFieldItems for details.

SegmentFieldItems

The SegmentFieldItems class defines the per-item structure of a segment field whose type is array or time_array. For an array field, the type value specifies the scalar element type. For a time_array field, use object as the type value and declare the fields of each event in the fields array.

NameTypeRequiredDescription
typeSegmentFieldItemsTypeYesThe item type. For an array field, use one of the scalar types (string, number, boolean, integer). For a time_array field, use object and declare the per-event schema in the fields array. Setting object as the type value on a plain array field returns a 400 error. Setting the fields array on a plain array field also returns a 400 error.
fieldsOptional[List[TimeArrayItemField]]NoThe fields to extract from each event. Required when the type of the parent field is time_array, with at least one entry. Not permitted on any other field type.

TimeArrayItemField

The TimeArrayItemField class defines a field inside a time_array item. The platform adds start_time and end_time keys to every event automatically. You cannot declare fields with these names. A time_array field cannot contain another time_array field. The format property is not accepted on per-event fields.

NameTypeRequiredDescription
namestrYesThe name of the field inside each event object. Must be unique within the item. The names start_time, end_time, and metadata are reserved and rejected with a 400 error.
typeTimeArrayItemFieldTypeYesThe data type of this field. It does not accept timestamp or time_array. When set to the array value, the items object is required. Values: "string", "boolean", "number", "integer", "array".
descriptionstrYesInstructions that guide the model on what this field should contain in each event.
enumOptional[List[str]]NoAllowed values for this field. Maximum 100 values. Only supported when type is string; any other type returns a 400 error.
itemsOptional[TimeArrayItemFieldItems]NoThe element type for an array field. Required when type is array; not supported on any other type. The items object has a single property type with values: "string", "number", "boolean", "integer".

SmeMediaSource

The SmeMediaSource class defines a reference image that provides visual context for segment identification. Provide exactly one of the url, asset_id, or base_64_string fields.

NameTypeRequiredDescription
namestrYesA descriptive name for this media source.
media_typeSmeMediaSourceMediaTypeYesThe media type. Value: "image".
urlOptional[str]NoA publicly accessible HTTPS URL of the image.
asset_idOptional[str]NoThe unique identifier of an uploaded asset.
base_64_stringOptional[str]NoBase64-encoded image data. The maximum decoded size is 32 MB.

Return value: Returns a CreateAnalyzeTaskResponse object containing the task details.

The CreateAnalyzeTaskResponse class contains the following properties:

NameTypeDescription
task_idstrThe unique identifier of the analysis task.
statusAnalyzeTaskStatusThe 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 result is available. The error field describes the failure.
  • canceled: The task was canceled. No result is available. The error field describes the cancellation reason, if available.

The ready, failed, and canceled statuses are final.

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

Function signature and example:

def retrieve(
self,
task_id: str,
*,
request_options: typing.Optional[RequestOptions] = None,
) -> AnalyzeTaskResponse:

Parameters:

NameTypeRequiredDescription
task_idstrYesThe unique identifier of the analysis task.
request_optionsRequestOptionsNoRequest-specific configuration.

Return value: Returns an AnalyzeTaskResponse object containing the task status and results.

The AnalyzeTaskResponse class contains the following properties:

NameTypeDescription
task_idstrThe unique identifier of the analysis task.
custom_idOptional[str]The identifier you provided when you created the task, or None if you did not set one. This property is always present.
batch_idOptional[str]The unique identifier of the batch that the task was created in. The platform returns this property only for tasks created as part of a batch.
video_sourceOptional[AnalyzeTaskResponseVideoSource]The video source associated with the task. When the video was uploaded using the POST method of the /tasks endpoint, the source type is video_id. Otherwise, the source type is url, base64_string, or asset_id.
request_paramsOptional[AnalyzeTaskResponseRequestParams]The parameters you sent when creating this task.
statusAnalyzeTaskStatusThe current status of the task. Values: queued, pending, processing, ready, failed, canceled.
created_atdatetimeThe date and time when the task was created, in RFC 3339 format.
completed_atOptional[datetime]The date and time when the task completed, failed, or was canceled, in RFC 3339 format. The platform returns this field only when status is ready, failed, or canceled.
resultOptional[AnalyzeTaskResult]An object that contains the generated text and additional information. The platform returns this object only when status is ready. A failed or canceled task has no result object, so generation_id and usage are absent.
errorOptional[AnalyzeTaskError]A message attached to the task response. The platform sets this field in the following cases:
- status is "failed": The message field describes the failure reason. With video segmentation, a task can fail because the analysis reached the maximum response length or the context window before it could complete. The response contains no result object.
- status is "canceled" and a cancellation reason is available: code identifies the machine-readable reason and message describes it. A task newly canceled through the task cancellation endpoint has code set to "user_canceled". The field is omitted when no cancellation reason is available.
- status is "ready" and the output for some segments could not be recovered (video segmentation): The message field contains the warning that the results may be incomplete. The segments the platform extracted are in result.data.
- status is "ready" and result.finish_reason is "length" (general analysis): The message field describes the truncation cause (either the maximum response length was reached or the context window was reached). The partial output is in result.data.
Not set when status is "ready" and result.finish_reason is "stop", except for the incomplete results warning.
webhooksOptional[List[AnalyzeTaskWebhookInfo]]The delivery status of each webhook endpoint. The platform omits this field when there are no webhooks configured.

The AnalyzeTaskResponseVideoSource class contains the following properties:

NameTypeDescription
typeOptional[AnalyzeTaskResponseVideoSourceType]The type of video source. Values: "url", "base64_string", "asset_id", "video_id".
urlOptional[str]The video URL. Present when type is "url".
asset_idOptional[str]The asset ID. Present when type is "asset_id".
video_idOptional[str]The deprecated video identifier. Present when type is "video_id".
index_idOptional[str]The deprecated identifier of the index associated with the video. Present on a best-effort basis when type is "video_id".
system_metadataOptional[AnalyzeTaskResponseVideoSourceSystemMetadata]Video metadata that the platform extracted during processing, such as its duration. Present on a best-effort basis once the video has been processed.

The AnalyzeTaskResponseVideoSourceSystemMetadata class contains the following properties:

NameTypeDescription
durationOptional[float]The video duration in seconds.

The AnalyzeTaskResponseRequestParams class contains the following properties:

NameTypeDescription
analysis_modeOptional[AnalyzeTaskResponseRequestParamsAnalysisMode]The analysis mode for this task. For a task created with the image parameter, the value is general. Values: "general", "time_based_metadata".
promptOptional[str]The natural-language prompt for this task. Present only when analysis_mode is general and the task was created with prompt (not prompt_v_2). On the List method, truncated to the first 30 characters; on the Retrieve method, returns the full text.
prompt_v_2Optional[AnalyzeTaskResponseRequestParamsPromptV2]The structured prompt for this task. Present only when analysis_mode is general and the task was created with prompt_v_2. When present, the response excludes the flat prompt field. On the List method, input_text is truncated to the first 30 characters; on the Retrieve method, returns the full text.
imageOptional[List[AnalyzeTaskMediaSource]]The image input you provided. Present only when the task was created with the image parameter. When present, the response omits video_source instead of returning it as null.
response_formatOptional[AnalyzeTaskResponseRequestParamsResponseFormat]The response format for this task. Present only when the request included a response format.
temperatureOptional[float]The temperature value for this analysis.
max_tokensOptional[AnalyzeTaskResponseRequestParamsMaxTokens]The maximum response length you set. The value is an integer in tokens or the string unlimited.
min_segment_durationOptional[float]The minimum segment duration you set, in seconds. Present when analysis_mode is "time_based_metadata".
max_segment_durationOptional[float]The maximum segment duration you set, in seconds. Present when analysis_mode is "time_based_metadata".
start_timeOptional[float]The start of the analysis window, in seconds. Present only when the task was created with start_time.
end_timeOptional[float]The end of the analysis window, in seconds. Present only when the task was created with end_time.

The AnalyzeTaskMediaSource class contains the following properties:

NameTypeDescription
namestrThe reference name you supplied.
media_typestrThe media type. The value is always image.
urlOptional[str]Present when the source was provided as a URL.
asset_idOptional[str]Present when the source was provided as an asset identifier.

The AnalyzeTaskResponseRequestParamsResponseFormat class contains the following properties:

NameTypeDescription
typeAnalyzeTaskResponseRequestParamsResponseFormatTypeValues: "json_schema", "segment_definitions".
json_schemaOptional[Dict[str, Optional[Any]]]The JSON schema for this task. Present only when type is json_schema.
- On the List method: omitted.
- On the Retrieve method: returns the full schema.
segment_time_formatOptional[AnalyzeTaskResponseRequestParamsResponseFormatSegmentTimeFormat]The segment_time_format value you set. Omitted when you did not set it. Automatic boundaries are then returned as JSON numbers in seconds. Values: "seconds", "hh:mm:ss", "hh:mm:ss.fff".
segment_definitionsOptional[List[AnalyzeTaskResponseRequestParamsResponseFormatSegmentDefinitionsItem]]The segment definitions for this task. Present only when type is segment_definitions.
- On the List method: returns only the first element.
- On the Retrieve method: returns the full array.

The AnalyzeTaskResult class contains the following properties:

NameTypeDescription
generation_idstrThe unique identifier for the generation session.
datastrThe generated text for this analysis task. When analysis_mode is not set, a plain-text string based on the prompt you provided. When analysis_mode is "time_based_metadata", a JSON-encoded string keyed by segment definition id. Each key maps to an array of segment objects with start_time (number), end_time (number), and metadata (object with your custom fields). The value of a time_array field is an array of event objects, one for each event inside the segment. Each event object contains start_time and end_time, which the platform adds automatically, plus the fields you declared in the items.fields array.
- Segments are within the duration of the video, and events are within the duration of their segment.
- The min_segment_duration and max_segment_duration values limit segments only, not the events inside them.
- Event boundaries use the same format as segment boundaries, set by the segment_time_format value.
finish_reasonFinishReasonThe reason the generation stopped. Values: null (generation has not finished), "stop" (the generation reached the end of the output text), "length" (the generation reached the maximum response length or the context window; with a JSON response format, the output may be truncated and fail to parse). When the task uses general analysis, the partial output is in data, and a warning is in the task’s error field. With video segmentation and a numeric max_tokens, the task fails when the analysis reaches either limit. This field is never "length" for a segmentation task. With max_tokens set to "unlimited", this field is "stop" even when the output is incomplete.
usageAnalyzeTaskResultUsageThe number of tokens used in the generation.

The AnalyzeTaskResultUsage class contains the following properties:

NameTypeDescription
output_tokensintThe number of tokens in the generated text.
input_tokensOptional[int]The number of tokens the input consumed. Together with output_tokens, this value must fit within the context window.

The AnalyzeTaskError class contains the following properties:

NameTypeDescription
codeOptional[str]A machine-readable code that identifies the task’s condition. Cancellation values are "user_canceled", "batch_canceled", and "batch_expired"; "batch_processing_timeout" identifies a batch processing failure. Clients must tolerate unrecognized values. These task condition codes are distinct from API error response codes, even when a string appears in both. The platform omits this field for failures and truncation warnings that have no code.
messagestrA human-readable message for task failure, cancellation, a video-segmentation incomplete-results warning, or a general-analysis truncation warning. Do not parse this field as a discriminator; use status, code, and finish_reason instead. For documented messages, see Error codes.

API Reference: Retrieve analysis task status and results

Cancel an async analysis task

Description: Use this method to cancel an asynchronous analysis task in your account. To cancel a task created as part of a batch, use the analyze_async.batches.cancel method.

You can cancel a task with the queued, pending, or processing status. This action cannot be undone.

Processing that has already started can continue briefly after cancellation.

When you cancel a task, the platform can send an analyze.task.canceled webhook. Delivery is best-effort: a 200 response is not a delivery guarantee. When you receive the event, retrieve the task for its current state.

Function signature and example:

def cancel(
self,
task_id: str,
*,
request_options: typing.Optional[RequestOptions] = None,
) -> CancelAnalyzeTaskResponse

Parameters:

NameTypeRequiredDescription
task_idstrYesThe unique identifier of the analysis task you want to cancel.
request_optionsOptional[RequestOptions]NoRequest-specific configuration.

Return value: Returns a CancelAnalyzeTaskResponse containing task_id and the final status canceled. This response is also returned when the task was canceled by a previous request.

API Reference: Cancel an async analysis task

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:

def delete(
self,
task_id: str,
*,
request_options: typing.Optional[RequestOptions] = None,
) -> None:

Parameters:

NameTypeRequiredDescription
task_idstrYesThe unique identifier of the analysis task.
request_optionsRequestOptionsNoRequest-specific configuration.

Return value: Returns None. If successful, the platform returns a 204 No Content response.

API Reference: Delete an analysis task