Sync analysis
The TwelveLabs class provides methods to analyze videos synchronously and generate text based on their content. These methods return results immediately in the response.
When to use these methods:
- Analyze videos up to 1 hour, or images
- Retrieve immediate results without polling for task completion
- Stream text fragments in real time for immediate processing and feedback
Do not use these methods for:
- Videos longer than 1 hour. Use the
analyze_async.tasks.createmethod instead. - Video segmentation with custom segment definitions. Use the
analyze_async.tasks.createmethod instead.
Sync analysis
Description: This method analyzes a video or one or more images and returns the results directly in the response. Each request must contain a video or one or more images, but not both. You can use general analysis (prompt-based text generation) with either media type.
Input requirements
Videos
- Minimum duration: 1 second
- Maximum duration: 1 hour
- 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).
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.
This method is rate-limited. For details, see the Rate limits page.
Function signature and example:
Parameters:
The SyncResponseFormat class contains the following properties:
VideoContext
The VideoContext type specifies the source of the video content. Provide exactly one of the following:
AnalyzeImageInput
The AnalyzeImageInput class defines an image to analyze. Provide exactly one of the url, asset_id, or base64_string fields.
AnalyzePromptV2
The AnalyzePromptV2 class defines a structured prompt that uses <@name> placeholders to reference images. Mutually exclusive with the prompt and image parameters.
SmeMediaSource
A reference image that provides visual context. Provide exactly one of the url, asset_id, or base_64_string fields.
Return value: Returns a NonStreamAnalyzeResponse object containing the generated text.
The NonStreamAnalyzeResponse class contains the following properties:
The TokenUsage class contains the following properties:
API Reference: Sync analysis.
Related guide: Analyze videos and images.
Sync analysis with streaming responses
Description: This method analyzes a video or one or more images and returns the results directly in the response. Each request must contain a video or one or more images, but not both. You can use general analysis (prompt-based text generation) with either media type.
Input requirements
Videos
- Minimum duration: 1 second
- Maximum duration: 1 hour
- 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).
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.
This method is rate-limited. For details, see the Rate limits page.
Function signature and example:
Parameters:
For details about VideoContext, AnalyzeImageInput, AnalyzePromptV2, and SmeMediaSource, see the Sync analysis section above.
The SyncResponseFormat class contains the following properties:
Return value: Returns an iterator of StreamAnalyzeResponse objects. Each response can be a StreamAnalyzeResponse_StreamStart, StreamAnalyzeResponse_TextGeneration, or StreamAnalyzeResponse_StreamEnd.
The StreamAnalyzeResponse_StreamStart class contains the following properties:
The StreamAnalyzeResponse_TextGeneration class contains the following properties:
The StreamAnalyzeResponse_StreamEnd class contains the following properties:
The StreamStartResponseMetadata class contains the following properties:
The StreamEndResponseMetadata class contains the following properties:
The TokenUsage class contains the following properties:
API Reference: Sync analysis.
Related guide: Analyze videos and images.
Error codes
This section lists the most common error messages you may encounter while analyzing videos.
token_limit_exceeded- The request exceeds the context window and cannot be processed. Reduce the prompt length, use a shorter video, or lower the
max_tokensvalue.
- The request exceeds the context window and cannot be processed. Reduce the prompt length, use a shorter video, or lower the
Live video streams are not supported. Please provide a URL that is not a live stream.- The URL points to a live HLS stream. Only VOD manifests are supported. Provide the URL of a VOD manifest.
output truncated: the generation reached the configured max_tokens. The partial output is returned; raise max_tokens if you need a longer response.- The response reached the maximum response length in
generalmode. The platform returns the partial output and setsfinish_reasonto"length". This message appears in theerror.messagefield.
- The response reached the maximum response length in
output truncated: combined input and output tokens reached the model's context limit. The partial output is returned; consider reducing input size (shorter prompt, smaller video clip, fewer media bindings) or lowering max_tokens.- The request reached the context window in
generalmode. The platform returns the partial output and setsfinish_reasonto"length". This message appears in theerror.messagefield.
- The request reached the context window in
analysis failed: the time_based_metadata output reached the configured max_tokens before a complete result was produced. Raise max_tokens if it is below the per-model maximum; otherwise narrow the request (fewer segment_definitions or fields, a larger min_segment_duration, or a shorter analysis window).- The response reached the maximum response length in
time_based_metadatamode. The task fails withstatusset to"failed", and no partial output is returned. This message appears in theerror.messagefield.
- The response reached the maximum response length in
analysis failed: the time_based_metadata output reached the model's context limit (combined input and output tokens) before a complete result was produced. Narrow the request (fewer segment_definitions or fields, a larger min_segment_duration, a shorter analysis window, fewer media bindings) or lower max_tokens to leave more room for the input.- The request reached the context window in
time_based_metadatamode. The task fails withstatusset to"failed", and no partial output is returned. This message appears in theerror.messagefield.
- The request reached the context window in
user_canceled- An async analysis task was canceled through the task cancellation endpoint. The task has
statusset to"canceled", and no result is returned.
- An async analysis task was canceled through the task cancellation endpoint. The task has
batch_canceled- A queued analysis task was canceled because its batch was canceled. The task has
statusset to"canceled", and no result is returned.
- A queued analysis task was canceled because its batch was canceled. The task has
batch_expired- A queued analysis task was canceled because its batch expired. The task has
statusset to"canceled", and no result is returned.
- A queued analysis task was canceled because its batch expired. The task has
batch_processing_timeout- A processing analysis task failed after reaching its batch’s processing deadline. The task has
statusset to"failed", and no result is returned.
- A processing analysis task failed after reaching its batch’s processing deadline. The task has
index_not_supported_for_generate- You can only summarize videos uploaded to an index with an engine from the Pegasus family enabled.
For a list of general errors that apply to all endpoints, see the Error codes page.