The TwelvelabsApiClient interface 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:
Do not use these methods for:
analyzeAsync.tasks.create method instead.analyzeAsync.tasks.create method with modelName set to "pegasus1.5" instead.Description: This method analyzes your videos and returns the results directly in the response. It generates text based on your prompts and supports both Pegasus 1.2 and Pegasus 1.5 for general analysis (prompt-based text generation).
This method is rate-limited. For details, see the Rate limits page.
Function signature and example:
Parameters:
The AnalyzeRequest interface contains the following properties:
| responseFormat | TwelvelabsApi.SyncResponseFormat | No | Specifies the format of the response. When you omit this parameter, the platform returns unstructured text. Only the json_schema type is supported for synchronous analysis. |
| maxTokens | number | No | The maximum response length, in tokens. The allowed range depends on the model: Pegasus 1.2 — Min: 1, Max: 4,096, Default: 4,096. Pegasus 1.5 — Min: 512, Max: 98,304, Default: 4,096. For Pegasus 1.5, the input and response must fit within the context window. |
The SyncResponseFormat class contains the following properties:
The VideoContext type specifies the source of the video content. Provide exactly one of the following. Set the type discriminator field to "url", "asset_id", or "base64_string" to indicate which source you are providing.
The AnalyzePromptV2 interface defines a structured prompt with image references.
A reference image that provides visual context. Provide exactly one of url, assetId, or base64String.
Return value: Returns a Promise that resolves to a NonStreamAnalyzeResponse object containing the generated text.
The NonStreamAnalyzeResponse interface contains the following properties:
The TokenUsage interface contains the following properties:
API Reference: Sync analysis.
Related guide: Analyze videos.
Description: This method analyzes your videos and returns the results directly in the response. It generates text based on your prompts and supports both Pegasus 1.2 and Pegasus 1.5 for general analysis (prompt-based text generation).
This method is rate-limited. For details, see the Rate limits page.
Function signature and example:
Parameters:
The AnalyzeStreamRequest interface contains the following properties:
| responseFormat | TwelvelabsApi.SyncResponseFormat | No | Specifies the format of the response. When you omit this parameter, the platform returns unstructured text. Only the json_schema type is supported for synchronous analysis. |
| maxTokens | number | No | The maximum response length, in tokens. The allowed range depends on the model: Pegasus 1.2 — Min: 1, Max: 4,096, Default: 4,096. Pegasus 1.5 — Min: 512, Max: 98,304, Default: 4,096. For Pegasus 1.5, the input and response must fit within the context window. |
For details about VideoContext, AnalyzePromptV2, and SmeMediaSource, see the Sync analysis section above.
The SyncResponseFormat class contains the following properties:
Return value: Returns a promise that resolves to a Stream<TwelvelabsApi.StreamAnalyzeResponse> object that can be iterated over to receive streaming text chunks.
The StreamAnalyzeResponse can be either a StreamAnalyzeResponse.StreamStart, a StreamAnalyzeResponse.TextGeneration, or a StreamAnalyzeResponse.StreamEnd.
The StreamAnalyzeResponse.StreamStart interface contains the following properties:
The StreamAnalyzeResponse.TextGeneration interface contains the following properties:
The StreamAnalyzeResponse.StreamEnd interface contains the following properties:
The StreamStartResponseMetadata interface contains the following properties:
The StreamEndResponseMetadata interface contains the following properties:
The TokenUsage interface contains the following properties:
API Reference: Sync analysis.
Related guide: Analyze videos.
This section lists the most common error messages you may encounter while analyzing videos.
token_limit_exceeded
max_tokens value.output truncated: the generation reached the configured max_tokens. The partial output is returned; raise max_tokens (up to 98304) if you need a longer response.
finish_reason to "length". This message appears in the error.message field.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.
finish_reason to "length". This message appears in the error.message field.index_not_supported_for_generate