> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://docs.twelvelabs.io/v1.3/sdk-reference/node-js/analyze-videos/sync-analysis/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.twelvelabs.io/_mcp/server. 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**: * Analyze videos up to 1 hour * 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 [`analyzeAsync.tasks.create`](/v1.3/sdk-reference/node-js/analyze-videos/async-analysis#create-an-async-analysis-task) method instead. * Video segmentation with custom segment definitions. Use the [`analyzeAsync.tasks.create`](/v1.3/sdk-reference/node-js/analyze-videos/async-analysis#create-an-async-analysis-task) method instead. # Sync analysis **Description**: This method analyzes your videos and returns the results directly in the response. It generates text based on your prompts using Pegasus 1.5 for general analysis (prompt-based text generation). On the Free plan, 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](/v1.3/docs/concepts/indexes#video-hours-and-video-count-limits) section. > **Note** > > This method is rate-limited. For details, see the [Rate limits](/v1.3/docs/get-started/rate-limits) page. **Function signature and example**: **`Function signature`** ```javascript Function signature analyze(request: TwelvelabsApi.AnalyzeRequest, requestOptions?: TwelvelabsApiClient.RequestOptions): core.HttpResponsePromise; ``` **`Node.js example`** ```javascript Node.js example import { TwelveLabs, TwelvelabsApi } from "twelvelabs-js"; const result = await client.analyze({ modelName: "pegasus1.5", video: { type: "url", url: "" }, promptV2: { inputText: "", // To use reference images: "Is there a <@product> in this video?" // mediaSources: [ // { name: "product", mediaType: "image", url: "" }, // ], }, temperature: 0.2 }); console.log(`Result ID: ${result.id}`); console.log(`Generated text: ${result.data}`); if (result.usage !== undefined) { console.log(`Output tokens: ${result.usage.outputTokens}`) }; ``` **Parameters**: | Name | Type | Required | Description | | :--------------- | :----------------------------- | :------- | :----------------------------------------------------------------------- | | `request` | `TwelvelabsApi.AnalyzeRequest` | Yes | The request object containing the parameters for performing an analysis. | | `requestOptions` | `RequestOptions` | No | Request-specific configuration. | The `AnalyzeRequest` interface contains the following properties: | Name | Type | Required | Description | | :------------ | :------------------------------ | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `modelName` | `string` | No | The video understanding model to use for analysis. Values: - `"pegasus1.5"`: General analysis (prompt-based text generation) with video clipping, structured prompts with reference images, and video segmentation (async only). See the [Pegasus](/v1.3/docs/concepts/models/pegasus#context-window) page for token limits. **Default:** `"pegasus1.5"` | | `video` | `TwelvelabsApi.VideoContext` | No | An object specifying the source of the video content. Include exactly one source. See [VideoContext](#videocontext). | | `prompt` | `string` | No | A text prompt that guides the model on the desired format or content. To include reference images in your prompt, use the `promptV2` parameter instead. Mutually exclusive with the `promptV2` parameter. | | `promptV2` | `TwelvelabsApi.AnalyzePromptV2` | No | A structured prompt with the `<@name>` placeholders for referencing images. Mutually exclusive with the `prompt` parameter. See [AnalyzePromptV2](#analyzepromptv2). | | `temperature` | `number` | No | Controls the randomness of the text output. **Default:** 0.2, **Min:** 0, **Max:** 1 | | `startTime` | `number` | No | Start of the analysis window, as an absolute timestamp in seconds, based on the internal metadata of the video. Use with `endTime` 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 `endTime` and the video duration. The window (`endTime - startTime`) must be at least 1 second. | | `endTime` | `number` | No | End of the analysis window, as an absolute timestamp in seconds, based on the internal metadata of the video. Use with `startTime` 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 `startTime` and less than or equal to the video duration. The window (`endTime - startTime`) must be at least 1 second. | The `SyncResponseFormat` class contains the following properties: | Name | Type | Description | | ------------ | -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `type` | `TwelvelabsApi.SyncResponseFormatType` | The response format to use. Value: `"json_schema"` (structured JSON conforming to a provided schema). | | `jsonSchema` | `Record` | Contains the JSON schema that defines the response structure. The schema must adhere to the [JSON Schema Draft 2020-12](https://json-schema.org/draft/2020-12) specification. For details, see the [`json_schema`](/v1.3/docs/guides/analyze-videos#request.body.response_format.json_schema) parameter in the API Reference section. | ### VideoContext 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. | Object | Description | | ------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `{ type: "url", url: string }` | The 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. | | `{ type: "asset_id", assetId: string }` | The unique identifier of an asset from a [direct](/v1.3/sdk-reference/node-js/upload-content/direct-uploads) or [multipart](/v1.3/sdk-reference/node-js/upload-content/multipart-uploads) upload. The asset status must be `ready`. Use [`assets.retrieve`](/v1.3/sdk-reference/node-js/manage-assets#retrieve-an-asset) to check the status. | | `{ type: "base64_string", base64String: string }` | The base64-encoded video data. The maximum size is 30MB. | ### AnalyzePromptV2 The `AnalyzePromptV2` interface defines a structured prompt with image references. | Name | Type | Required | Description | | -------------- | -------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `inputText` | `string` | Yes | The text of the prompt. Use `<@name>` placeholders to reference images declared in `mediaSources` (Example: `"Is there a <@tiger-1> in the video?"`). This text counts toward the [context window](/v1.3/docs/concepts/models/pegasus#context-window). | | `mediaSources` | `TwelvelabsApi.SmeMediaSource[]` | No | Reference images for the `<@name>` placeholders in the prompt. Maximum 4 sources. See [SmeMediaSource](#smemediasource). | ### SmeMediaSource A reference image that provides visual context. Provide exactly one of `url`, `assetId`, or `base64String`. | Name | Type | Required | Description | | -------------- | --------------------------------------- | -------- | ---------------------------------------------------- | | `name` | `string` | Yes | A descriptive name for this media source. | | `mediaType` | `TwelvelabsApi.SmeMediaSourceMediaType` | Yes | The media type. Value: `"image"`. | | `url` | `string` | No | A publicly accessible HTTPS URL of the image. | | `assetId` | `string` | No | The unique identifier of an uploaded asset. | | `base64String` | `string` | No | Base64-encoded image data. The maximum size is 30MB. | **Return value**: Returns a `Promise` that resolves to a `NonStreamAnalyzeResponse` object containing the generated text. The `NonStreamAnalyzeResponse` interface contains the following properties: | Name | Type | Description | | -------------- | ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `id` | `string` | Unique identifier of the response. | | `data` | `string` | The generated text based on the prompt you provided. | | `finishReason` | `TwelvelabsApi.FinishReason` | The reason the generation stopped. Values: - `null`: The generation has not finished yet. - `"stop"`: The generation reached the end of the output text. - `"length"`: The generation reached the maximum response length or the [context window](/v1.3/docs/concepts/models/pegasus#context-window). When you set the `responseFormat` parameter, the output may be truncated and fail to parse. The partial output is in `data`, and a warning is in the `error` field. | | `usage` | `TokenUsage` | The number of tokens used in the generation. | The `TokenUsage` interface contains the following properties: | Name | Type | Description | | -------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `outputTokens` | `number` | The number of tokens in the generated text. | | `inputTokens` | `number` | The number of tokens the input consumed. Together with `outputTokens`, this value must fit within the [context window](/v1.3/docs/concepts/models/pegasus#context-window). | **API Reference**: [Sync analysis](/v1.3/api-reference/analyze-videos/sync-analysis). **Related guide**: [Analyze videos](/v1.3/docs/guides/analyze-videos). # Sync analysis with streaming responses **Description**: This method analyzes your videos and returns the results directly in the response. It generates text based on your prompts using Pegasus 1.5 for general analysis (prompt-based text generation). On the Free plan, 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](/v1.3/docs/concepts/indexes#video-hours-and-video-count-limits) section. > **Note** > > This method is rate-limited. For details, see the [Rate limits](/v1.3/docs/get-started/rate-limits) page. **Function signature and example**: **`Function signature`** ```javascript Function signature async analyzeStream( request: TwelvelabsApi.AnalyzeStreamRequest, requestOptions?: TwelvelabsApiClient.RequestOptions ): core.HttpResponsePromise> ``` **`Node.js example`** ```javascript Node.js example import { TwelveLabs, TwelvelabsApi } from "twelvelabs-js"; const textStream = await client.analyzeStream({ modelName: "pegasus1.5", video: { type: "url", url: "" }, promptV2: { inputText: "", // To use reference images: "Is there a <@product> in this video?" // mediaSources: [ // { name: "product", mediaType: "image", url: "" }, // ], }, temperature: 0.2 }); for await (const chunk of textStream) { if ("text" in chunk) { console.log(chunk.text!); }; }; ``` **Parameters**: | Name | Type | Required | Description | | :--------------- | :----------------------------------- | :------- | :----------------------------------------------------------------------- | | `request` | `TwelvelabsApi.AnalyzeStreamRequest` | Yes | The request object containing the parameters for performing an analysis. | | `requestOptions` | `RequestOptions` | No | Request-specific configuration. | The `AnalyzeStreamRequest` interface contains the following properties: | Name | Type | Required | Description | | :------------ | :------------------------------ | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `modelName` | `string` | No | The video understanding model to use for analysis. Values: - `"pegasus1.5"`: General analysis (prompt-based text generation) with video clipping, structured prompts with reference images, and video segmentation (async only). See the [Pegasus](/v1.3/docs/concepts/models/pegasus#context-window) page for token limits. **Default:** `"pegasus1.5"` | | `video` | `TwelvelabsApi.VideoContext` | No | An object specifying the source of the video content. Include exactly one source. See [VideoContext](#videocontext). | | `prompt` | `string` | No | A text prompt that guides the model on the desired format or content. To include reference images in your prompt, use the `promptV2` parameter instead. Mutually exclusive with the `promptV2` parameter. | | `promptV2` | `TwelvelabsApi.AnalyzePromptV2` | No | A structured prompt with the `<@name>` placeholders for referencing images. Mutually exclusive with the `prompt` parameter. See [AnalyzePromptV2](#analyzepromptv2). | | `temperature` | `number` | No | Controls the randomness of the text output. **Default:** 0.2, **Min:** 0, **Max:** 1 | | `startTime` | `number` | No | Start of the analysis window, as an absolute timestamp in seconds, based on the internal metadata of the video. Use with `endTime` 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 `endTime` and the video duration. The window (`endTime - startTime`) must be at least 1 second. | | `endTime` | `number` | No | End of the analysis window, as an absolute timestamp in seconds, based on the internal metadata of the video. Use with `startTime` 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 `startTime` and less than or equal to the video duration. The window (`endTime - startTime`) must be at least 1 second. | For details about `VideoContext`, `AnalyzePromptV2`, and `SmeMediaSource`, see the [Sync analysis](#sync-analysis) section above. The `SyncResponseFormat` class contains the following properties: | Name | Type | Description | | ------------ | -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `type` | `TwelvelabsApi.SyncResponseFormatType` | The response format to use. Value: `"json_schema"` (structured JSON conforming to a provided schema). | | `jsonSchema` | `Record` | Contains the JSON schema that defines the response structure. The schema must adhere to the [JSON Schema Draft 2020-12](https://json-schema.org/draft/2020-12) specification. For details, see the [`json_schema`](/v1.3/docs/guides/analyze-videos#request.body.response_format.json_schema) parameter in the API Reference section. | **Return value**: Returns a promise that resolves to a `Stream` 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: | Name | Type | Description | | ----------- | ----------------------------- | ---------------------------------------------------------- | | `eventType` | `"stream_start"` | This field is always set to `stream_start` for this event. | | `metadata` | `StreamStartResponseMetadata` | An object containing metadata about the stream. | The `StreamAnalyzeResponse.TextGeneration` interface contains the following properties: | Name | Type | Description | | ----------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | | `eventType` | `"text_generation"` | This field is always set to `text_generation` for this event. | | `text` | `string` | A fragment of the generated text. Text fragments may be split at arbitrary points, not necessarily at word or sentence boundaries. | The `StreamAnalyzeResponse.StreamEnd` interface contains the following properties: | Name | Type | Description | | -------------- | ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `eventType` | `"stream_end"` | This field is always set to `stream_end` for this event. | | `finishReason` | `TwelvelabsApi.FinishReason` | The reason the generation stopped. Values: - `null`: The generation has not finished yet. - `"stop"`: The generation reached the end of the output text. - `"length"`: The generation reached the maximum response length or the [context window](/v1.3/docs/concepts/models/pegasus#context-window). When you set the `responseFormat` parameter, the output may be truncated and fail to parse. The partial output is in `data`, and a warning is in the `error` field. | | `metadata` | `StreamEndResponseMetadata` | An object containing metadata about the stream. | The `StreamStartResponseMetadata` interface contains the following properties: | Name | Type | Description | | -------------- | -------- | ----------------------------------------------- | | `generationId` | `string` | A unique identifier for the generation session. | The `StreamEndResponseMetadata` interface contains the following properties: | Name | Type | Description | | -------------- | ------------ | ---------------------------------------------------------------- | | `generationId` | `string` | The same unique identifier provided in the `stream_start` event. | | `usage` | `TokenUsage` | The number of tokens used in the generation. | The `TokenUsage` interface contains the following properties: | Name | Type | Description | | -------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `outputTokens` | `number` | The number of tokens in the generated text. | | `inputTokens` | `number` | The number of tokens the input consumed. Together with `outputTokens`, this value must fit within the [context window](/v1.3/docs/concepts/models/pegasus#context-window). | **API Reference**: [Sync analysis](/v1.3/api-reference/analyze-videos/sync-analysis). **Related guide**: [Analyze videos](/v1.3/docs/guides/analyze-videos). # 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](/v1.3/docs/concepts/models/pegasus#context-window) and cannot be processed. Reduce the prompt length, use a shorter video, or lower the `max_tokens` value. * `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 `general` mode. The platform returns the partial output and sets `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.` * The request reached the [context window](/v1.3/docs/concepts/models/pegasus#context-window) in `general` mode. The platform returns the partial output and sets `finish_reason` to `"length"`. This message appears in the `error.message` field. * `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_metadata` mode. The task fails with `status` set to `"failed"`, and no partial output is returned. This message appears in the `error.message` field. * `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](/v1.3/docs/concepts/models/pegasus#context-window) in `time_based_metadata` mode. The task fails with `status` set to `"failed"`, and no partial output is returned. This message appears in the `error.message` field. * `index_not_supported_for_generate` * You can only summarize videos uploaded to an index with an engine from the Pegasus family enabled.