> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.twelvelabs.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.twelvelabs.io/_mcp/server.

# Sync analysis

POST https://api.twelvelabs.io/v1.3/analyze
Content-Type: application/json

This method analyzes your videos and returns the results directly in the response. It supports general analysis (prompt-based text generation).

* Minimum duration: 1 second
* Maximum duration: 1 hour
* Formats: [FFmpeg supported formats](https://ffmpeg.org/ffmpeg-formats.html)
* Resolution: 360x360 to 5184x2160 pixels
* Aspect ratio: Between 1:1 and 1:2.4, or between 2.4:1 and 1:1.

**When to use this method**:

* 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 this method for**:

* Videos longer than 1 hour. Use the [`POST`](/v1.3/api-reference/analyze-videos/create-async-analysis-task) method of the `/analyze/tasks` endpoint instead.
* Video segmentation with custom segment definitions. Use the [`POST`](/v1.3/api-reference/analyze-videos/create-async-analysis-task) method of the `/analyze/tasks` endpoint instead.

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.

This endpoint is rate-limited. For details, see the [Rate limits](/v1.3/docs/get-started/rate-limits) page.

Reference: https://docs.twelvelabs.io/api-reference/analyze-videos/analyze

## Authentication

- `x-api-key` header (required) — Your API key. You can find your API key on the API Keys page.

## Request

### Body (application/json)

This endpoint expects an object.

- `model_name` (enum, optional, default: pegasus1.5) — The video understanding model to use for analysis. - `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`
  - Allowed values: `pegasus1.5`
- `video` (VideoContext, optional) — An object specifying the source of the video content. Include exactly one source.
- `prompt` (string, optional) — A text prompt that guides the model on the desired format or content. To include reference images in your prompt, use the `prompt_v2` parameter instead. Mutually exclusive with the `prompt_v2` parameter. Your prompts can be instructive or descriptive, or you can phrase them as questions. This text counts toward the [context window](/v1.3/docs/concepts/models/pegasus#context-window).
- `prompt_v2` (AnalyzePromptV2, optional) — A structured prompt with `<@name>` placeholders for referencing images. Mutually exclusive with the `prompt` parameter. The prompt text and reference images count toward the [context window](/v1.3/docs/concepts/models/pegasus#context-window).
- `temperature` (double, optional) — Controls the randomness of the text output. **Default:** 0.2 **Min:** 0 **Max:** 1
- `stream` (boolean, optional, default: true) — Set this parameter to `true` to enable streaming responses in the NDJSON format. **Default:** `true`
- `response_format` (SyncResponseFormat, optional) — 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.
- `max_tokens` (integer, optional, default: 4096) — The maximum response length, in tokens.
- `start_time` (double, optional) — Start 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.
- `end_time` (double, optional) — End 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.

## Response

### 200

The specified video has successfully been analyzed.

- `analyze_Response_200`

## Errors

### 400 Bad Request Error

The request has failed.

- `code` (string, optional) — A string representing the code associated with the error. See the [Error codes](/v1.3/api-reference/error-codes) page for details.
- `message` (string, optional) — A human-readable string describing the error, intended to be suitable for display in a user interface.

### 404 Not Found Error

The specified resource does not exist.

- `code` (string, optional) — Represents the code associated with the error. See the [Error codes](/v1.3/api-reference/error-codes) page for details.
- `message` (string, optional) — A human-readable string describing the error.

### 429 Too Many Requests Error

If the rate limit is reached, the platform returns an `HTTP 429 - Too Many Requests` error response. The response body is empty.

- `any`

## Types

### VideoContext

An object specifying the source of the video content. Include exactly one source.

- `type`: `url` (url)
  - `url` (string, required) — 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 from the media, the platform calculates it from the manifest and the duration limits apply to that value.
- `type`: `asset_id` (asset_id)
  - `asset_id` (string, required) — The unique identifier of an asset from a [direct](/v1.3/api-reference/upload-content/direct-uploads) or [multipart](/v1.3/api-reference/upload-content/multipart-uploads) upload. The asset status must be `ready`. Use the [Retrieve an asset](/v1.3/api-reference/upload-content/direct-uploads/retrieve) method to check the status.
- `type`: `base64_string` (base64_string)
  - `base64_string` (string, required) — The base64-encoded video data. The maximum size is 30MB.

### AnalyzePromptV2

A structured prompt with `<@name>` placeholders for referencing images. Not supported when the `analysis_mode` parameter is `time_based_metadata`. Mutually exclusive with the `prompt` parameter.

- `input_text` (string, required) — The 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](/v1.3/docs/concepts/models/pegasus#context-window).
- `media_sources` (list of SMEMediaSource, optional) — Reference images for the `<@name>` placeholders in the prompt. Maximum 4 sources.

### SyncResponseFormat

Specifies the format of the response. When you omit this parameter, the platform returns unstructured text.

- `type` (enum, required) — Set this parameter to "json_schema" to receive structured JSON responses.
  - Allowed values: `json_schema`
- `json_schema` (SyncResponseFormatJsonSchema, required) — 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. **Supported types** * `array` * `boolean` * `integer` * `null` * `number` * `object` * `string` * `timestamp` **Supported constraints** | Type | Supported keywords | Notes | | ----------- | ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `integer` | `maximum`, `exclusiveMaximum`, `minimum`, `exclusiveMinimum`. | - `maximum`: Sets the highest allowed value (inclusive).- `exclusiveMaximum`: Sets the highest allowed value (exclusive).- `minimum`: Sets the lowest allowed value (inclusive).- `exclusiveMinimum`: Sets the lowest allowed value (exclusive).These constraints are supported only for the `integer` type. | | `string` | `pattern`, `format` | - `pattern`: A regular expression that the string must match.- `format`: Validates predefined formats. It accepts the following values: `uuid`, `date-time`, `date`, and `time`.See string limitations below. | | `object` | `properties`, `required` | - `properties`: Defines object properties and their schemas.- `required`: Specifies mandatory properties.See object limitations below. | | `array` | `items`, `minItems` | `minItems` accepts only `0` or `1`.See array limitations below. | | `timestamp` | `format` | `format` (required): Sets the output format. Accepted values: `seconds`, `hh:mm:ss`, `hh:mm:ss.fff`.See the **Timestamp type** section below. | **String limitations** When you use the `string` type: * The platform validates strings using only `pattern` and `format`. Including `minLength` or `maxLength` causes a 422 error: "String length constraints (minLength) are not supported." Remove these keywords from your schema. **Object limitations** When you use the `object` type: * The platform does not support the `additionalProperties` keyword. Including it causes a 422 error. Remove it from your schema. * The platform returns properties in declaration order. * Make the first property required. If the first property is optional, the platform moves the first required property to the beginning. **Array limitations** When you use the `array` type: * The platform does not support `uniqueItems` or `maxItems`. Including either keyword causes a 422 error. Remove them from your schema. **Constant and enumerated values** The `const` and `enum` keywords support the following types: * `boolean` * `null` * `number` * `string` **Schema composition** The platform supports only `anyOf` for [schema composition](https://json-schema.org/understanding-json-schema/reference/combining). **Annotations** The platform accepts but ignores JSON schema annotations like `title`, `$comments`, and `description`. **Subschema references** You can reference subschemas using `$ref` with these requirements: * Define subschemas within `$defs`. * Use valid URIs that point to the internal subschema. For details, see the [JSON Schema documentation on \$defs](https://json-schema.org/understanding-json-schema/structuring#defs). **Timestamp type** Declare a property as `{"type": "timestamp", "format": "<format>"}` to control the format of the returned value. The `format` field accepts the following values: | `format` | Example output | Notes | | -------------- | ---------------- | ----------------------------------------------------------------------------- | | `seconds` | `10.5` | Returns a JSON number in seconds. | | `hh:mm:ss` | `"00:01:23"` | Rounded to the nearest second. Negative values are converted to `"00:00:00"`. | | `hh:mm:ss.fff` | `"00:01:23.500"` | Millisecond precision. | The type of the response depends on the value of the `format` field: `seconds` returns a JSON number, while `hh:mm:ss` and `hh:mm:ss.fff` return a JSON string. *Supported positions* You can declare `timestamp` fields at the top level of your schema or inside objects nested one level within an array: * Top level: `properties.<field_name>` * Inside an array: `properties.<array_field>.items.properties.<field_name>` Declaring `timestamp` outside these positions — deeper nesting, inside `oneOf` / `anyOf` / `allOf`, or inside `$ref` — is not supported and is rejected with HTTP 400. *Validation errors* When `format` is missing or invalid, the platform returns `400 parameter_invalid`: ``` response_format.json_schema.properties.<name>.format: format is required for timestamp type; allowed values: seconds, hh:mm:ss, hh:mm:ss.fff ``` **Reserved property names (`start_time` / `end_time`)** The `start_time` and `end_time` properties in your response schema receive special type handling at any nesting depth (including inside array `items`). These are unrelated to the top-level `start_time` / `end_time` request parameters. The platform returns the value in a format determined by the declared type: *Allowed declarations:* | Declared type | Platform behavior | | ------------------------- | ------------------------------------------------------------------- | | `number` | Passes the value through without conversion. | | `integer` | Rounds the value to the nearest integer. | | `string` (no `format`) | Converts the value to the `hh:mm:ss.fff` format. | | `timestamp` with `format` | See the **Timestamp type** section above for the available formats. | *Rejected declarations (returns `400` error):* * `string` with any `format` keyword (`time`, `date-time`, `email`, `uri`, etc.) * `boolean` * `object` * `array` * `null` All other property names in your schema remain unconstrained by these rules. For other field names, use the `timestamp` type described above. **Response validation** Check the `finish_reason` field to verify your JSON response is complete: * When `finish_reason` is `stop`, the generation completed normally, and the JSON is valid and complete. * When `finish_reason` is `length`, the generation reached the maximum response length or the context window. The output may be truncated and fail to parse.

### NonStreamAnalyzeResponse

When the value of the `stream` parameter is set to `false`, the response is as follows:

- `id` (string, optional) — Unique identifier of the response.
- `data` (string, optional) — The generated text based on the prompt you provided.
- `finish_reason` (enum, optional) — The reason the generation stopped. - `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.
  - Allowed values: `stop`, `length`
- `usage` (TokenUsage, optional) — The number of tokens used in the generation.
- `error` (AnalyzeTaskError, optional) — A warning. Present when `finish_reason` is `length`, which means the response reached the maximum response length or the [context window](/v1.3/docs/concepts/models/pegasus#context-window). The partial output is returned in `data`.

### SMEMediaSource

A reference image that provides visual context for segment identification. Provide exactly one of `url`, `asset_id`, or `base64_string`.

- `name` (string, required) — A descriptive name for this media source.
- `media_type` (enum, required) — The media type. Only `image` is available.
  - Allowed values: `image`
- `url` (string, optional) — A publicly accessible HTTPS URL of the image.
- `asset_id` (string, optional) — The unique identifier of an uploaded asset.
- `base64_string` (string, optional) — Base64-encoded image data. The maximum size is 30MB.

### SyncResponseFormatJsonSchema

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. **Supported types** * `array` * `boolean` * `integer` * `null` * `number` * `object` * `string` * `timestamp` **Supported constraints** | Type | Supported keywords | Notes | | ----------- | ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `integer` | `maximum`, `exclusiveMaximum`, `minimum`, `exclusiveMinimum`. | - `maximum`: Sets the highest allowed value (inclusive).- `exclusiveMaximum`: Sets the highest allowed value (exclusive).- `minimum`: Sets the lowest allowed value (inclusive).- `exclusiveMinimum`: Sets the lowest allowed value (exclusive).These constraints are supported only for the `integer` type. | | `string` | `pattern`, `format` | - `pattern`: A regular expression that the string must match.- `format`: Validates predefined formats. It accepts the following values: `uuid`, `date-time`, `date`, and `time`.See string limitations below. | | `object` | `properties`, `required` | - `properties`: Defines object properties and their schemas.- `required`: Specifies mandatory properties.See object limitations below. | | `array` | `items`, `minItems` | `minItems` accepts only `0` or `1`.See array limitations below. | | `timestamp` | `format` | `format` (required): Sets the output format. Accepted values: `seconds`, `hh:mm:ss`, `hh:mm:ss.fff`.See the **Timestamp type** section below. | **String limitations** When you use the `string` type: * The platform validates strings using only `pattern` and `format`. Including `minLength` or `maxLength` causes a 422 error: "String length constraints (minLength) are not supported." Remove these keywords from your schema. **Object limitations** When you use the `object` type: * The platform does not support the `additionalProperties` keyword. Including it causes a 422 error. Remove it from your schema. * The platform returns properties in declaration order. * Make the first property required. If the first property is optional, the platform moves the first required property to the beginning. **Array limitations** When you use the `array` type: * The platform does not support `uniqueItems` or `maxItems`. Including either keyword causes a 422 error. Remove them from your schema. **Constant and enumerated values** The `const` and `enum` keywords support the following types: * `boolean` * `null` * `number` * `string` **Schema composition** The platform supports only `anyOf` for [schema composition](https://json-schema.org/understanding-json-schema/reference/combining). **Annotations** The platform accepts but ignores JSON schema annotations like `title`, `$comments`, and `description`. **Subschema references** You can reference subschemas using `$ref` with these requirements: * Define subschemas within `$defs`. * Use valid URIs that point to the internal subschema. For details, see the [JSON Schema documentation on \$defs](https://json-schema.org/understanding-json-schema/structuring#defs). **Timestamp type** Declare a property as `{"type": "timestamp", "format": "<format>"}` to control the format of the returned value. The `format` field accepts the following values: | `format` | Example output | Notes | | -------------- | ---------------- | ----------------------------------------------------------------------------- | | `seconds` | `10.5` | Returns a JSON number in seconds. | | `hh:mm:ss` | `"00:01:23"` | Rounded to the nearest second. Negative values are converted to `"00:00:00"`. | | `hh:mm:ss.fff` | `"00:01:23.500"` | Millisecond precision. | The type of the response depends on the value of the `format` field: `seconds` returns a JSON number, while `hh:mm:ss` and `hh:mm:ss.fff` return a JSON string. *Supported positions* You can declare `timestamp` fields at the top level of your schema or inside objects nested one level within an array: * Top level: `properties.<field_name>` * Inside an array: `properties.<array_field>.items.properties.<field_name>` Declaring `timestamp` outside these positions — deeper nesting, inside `oneOf` / `anyOf` / `allOf`, or inside `$ref` — is not supported and is rejected with HTTP 400. *Validation errors* When `format` is missing or invalid, the platform returns `400 parameter_invalid`: ``` response_format.json_schema.properties.<name>.format: format is required for timestamp type; allowed values: seconds, hh:mm:ss, hh:mm:ss.fff ``` **Reserved property names (`start_time` / `end_time`)** The `start_time` and `end_time` properties in your response schema receive special type handling at any nesting depth (including inside array `items`). These are unrelated to the top-level `start_time` / `end_time` request parameters. The platform returns the value in a format determined by the declared type: *Allowed declarations:* | Declared type | Platform behavior | | ------------------------- | ------------------------------------------------------------------- | | `number` | Passes the value through without conversion. | | `integer` | Rounds the value to the nearest integer. | | `string` (no `format`) | Converts the value to the `hh:mm:ss.fff` format. | | `timestamp` with `format` | See the **Timestamp type** section above for the available formats. | *Rejected declarations (returns `400` error):* * `string` with any `format` keyword (`time`, `date-time`, `email`, `uri`, etc.) * `boolean` * `object` * `array` * `null` All other property names in your schema remain unconstrained by these rules. For other field names, use the `timestamp` type described above. **Response validation** Check the `finish_reason` field to verify your JSON response is complete: * When `finish_reason` is `stop`, the generation completed normally, and the JSON is valid and complete. * When `finish_reason` is `length`, the generation reached the maximum response length or the context window. The output may be truncated and fail to parse.

### TokenUsage

The number of tokens used in the generation.

- `output_tokens` (integer, required) — The number of tokens in the generated text.
- `input_tokens` (integer, optional) — The number of tokens the input consumed. Together with `output_tokens`, this value must fit within the [context window](/v1.3/docs/concepts/models/pegasus#context-window).

### AnalyzeTaskError

A message attached to an analysis response. The platform uses this object in the following cases: - **Task failure** — when `status` is `failed`. The `message` field describes the failure. - **Task cancellation** — when `status` is `canceled` and a cancellation reason is available. - **Truncation warning (general analysis)** — set on the response `error` when `finish_reason` is `length`, because either `output_tokens` reached the requested `max_tokens` value or the input and response reached the [context window](/v1.3/docs/concepts/models/pegasus#context-window). To obtain the full output, increase the `max_tokens` value or reduce the input size. The partial output is in `result.data` for asynchronous analysis and in `data` for synchronous analysis. - With general analysis, check `finish_reason` instead of parsing the message text. With video segmentation, check `status`.

- `message` (string, required) — A human-readable message. One of: - **Other failures** (async, `status: failed`): the message describes the failure reason. Example: `"Video duration exceeds maximum allowed duration"`. - **Failure: maximum response length reached** (`time_based_metadata`, `status: failed`): `"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)."`. - **Failure: context window reached** (`time_based_metadata`, `status: failed`): `"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."`. - **Cancellation** (async, `status: canceled`): explains why the task was canceled. Example: `"The task was canceled by the user."`. - **Truncation: maximum response length reached** (`general`, `finish_reason: length`, `output_tokens >= max_tokens`): `"output truncated: the generation reached the configured max_tokens. The partial output is returned; raise max_tokens if you need a longer response."`. - **Truncation: context window reached** (`general`, `finish_reason: length`, model stopped before reaching `max_tokens`): `"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 exact text is not part of the contract. Do not parse it.
- `code` (string, optional) — A machine-readable code that identifies the task's condition. Values include: - `user_canceled`: A task was canceled through the task cancellation endpoint. - `batch_canceled`: A queued task was canceled because its batch was canceled. - `batch_expired`: A queued task was canceled because its batch expired. - `batch_processing_timeout`: A processing batch task failed after reaching the batch processing deadline. These task condition codes are distinct from API error response codes, even when a string appears in both. The platform can return other values. Clients must tolerate unrecognized values and must not parse `message` as a discriminator. The platform omits this field for failures and truncation warnings that have no code.

## Examples

### Non-streamed response

**Response**

```json
{
  "event_type": "stream_start",
  "id": "f1385675-207b-4b22-8b3e-f8fa32a8ddc9",
  "data": "The video does not show any dishes or food items, so a comparison cannot be made.",
  "finish_reason": "stop",
  "usage": {
    "output_tokens": 23,
    "input_tokens": 1850
  }
}
```

**SDK Code**

```python Non-streamed response
import requests

url = "https://api.twelvelabs.io/v1.3/analyze"

headers = {"x-api-key": "<apiKey>"}

response = requests.post(url, headers=headers)

print(response.json())
```

```javascript Non-streamed response
const url = 'https://api.twelvelabs.io/v1.3/analyze';
const options = {method: 'POST', headers: {'x-api-key': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Non-streamed response
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.twelvelabs.io/v1.3/analyze"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("x-api-key", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Non-streamed response
require 'uri'
require 'net/http'

url = URI("https://api.twelvelabs.io/v1.3/analyze")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java Non-streamed response
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.twelvelabs.io/v1.3/analyze")
  .header("x-api-key", "<apiKey>")
  .asString();
```

```php Non-streamed response
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.twelvelabs.io/v1.3/analyze', [
  'headers' => [
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Non-streamed response
using RestSharp;

var client = new RestClient("https://api.twelvelabs.io/v1.3/analyze");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift Non-streamed response
import Foundation

let headers = ["x-api-key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.twelvelabs.io/v1.3/analyze")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Truncated response: maximum response length reached

**Response**

```json
{
  "event_type": "stream_start",
  "id": "a3c98ee2-1ad1-4f44-9e2f-2e2cbe9d9c1b",
  "data": "The video shows a chef preparing a multi-course meal, starting with mise en place for the appetizer course. The chef carefully arranges fresh herbs, dices vegetables with",
  "finish_reason": "length",
  "usage": {
    "output_tokens": 2048,
    "input_tokens": 9420
  },
  "error": {
    "message": "output truncated: the generation reached the configured max_tokens. The partial output is returned; raise max_tokens if you need a longer response."
  }
}
```

**SDK Code**

```python Truncated response: maximum response length reached
import requests

url = "https://api.twelvelabs.io/v1.3/analyze"

headers = {"x-api-key": "<apiKey>"}

response = requests.post(url, headers=headers)

print(response.json())
```

```javascript Truncated response: maximum response length reached
const url = 'https://api.twelvelabs.io/v1.3/analyze';
const options = {method: 'POST', headers: {'x-api-key': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Truncated response: maximum response length reached
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.twelvelabs.io/v1.3/analyze"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("x-api-key", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Truncated response: maximum response length reached
require 'uri'
require 'net/http'

url = URI("https://api.twelvelabs.io/v1.3/analyze")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java Truncated response: maximum response length reached
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.twelvelabs.io/v1.3/analyze")
  .header("x-api-key", "<apiKey>")
  .asString();
```

```php Truncated response: maximum response length reached
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.twelvelabs.io/v1.3/analyze', [
  'headers' => [
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Truncated response: maximum response length reached
using RestSharp;

var client = new RestClient("https://api.twelvelabs.io/v1.3/analyze");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift Truncated response: maximum response length reached
import Foundation

let headers = ["x-api-key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.twelvelabs.io/v1.3/analyze")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Truncated response: context window reached

**Response**

```json
{
  "event_type": "stream_start",
  "id": "b4d0a9f1-9e4b-46d7-a3e0-19f5d2b87f3a",
  "data": "The video shows a chef preparing a multi-course meal, starting with mise en place for the appetizer course. The chef carefully arranges fresh herbs, dices vegetables with",
  "finish_reason": "length",
  "usage": {
    "output_tokens": 98304,
    "input_tokens": 162816
  },
  "error": {
    "message": "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."
  }
}
```

**SDK Code**

```python Truncated response: context window reached
import requests

url = "https://api.twelvelabs.io/v1.3/analyze"

headers = {"x-api-key": "<apiKey>"}

response = requests.post(url, headers=headers)

print(response.json())
```

```javascript Truncated response: context window reached
const url = 'https://api.twelvelabs.io/v1.3/analyze';
const options = {method: 'POST', headers: {'x-api-key': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Truncated response: context window reached
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.twelvelabs.io/v1.3/analyze"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("x-api-key", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Truncated response: context window reached
require 'uri'
require 'net/http'

url = URI("https://api.twelvelabs.io/v1.3/analyze")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java Truncated response: context window reached
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.twelvelabs.io/v1.3/analyze")
  .header("x-api-key", "<apiKey>")
  .asString();
```

```php Truncated response: context window reached
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.twelvelabs.io/v1.3/analyze', [
  'headers' => [
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Truncated response: context window reached
using RestSharp;

var client = new RestClient("https://api.twelvelabs.io/v1.3/analyze");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift Truncated response: context window reached
import Foundation

let headers = ["x-api-key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.twelvelabs.io/v1.3/analyze")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Stream start

**Response**

```json
{
  "event_type": "stream_start",
  "metadata": {
    "generation_id": "2f6d0bdd-aed8-47b1-8124-3c9d8006cdc9"
  }
}
```

**SDK Code**

```python Stream start
import requests

url = "https://api.twelvelabs.io/v1.3/analyze"

headers = {"x-api-key": "<apiKey>"}

response = requests.post(url, headers=headers)

print(response.json())
```

```javascript Stream start
const url = 'https://api.twelvelabs.io/v1.3/analyze';
const options = {method: 'POST', headers: {'x-api-key': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Stream start
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.twelvelabs.io/v1.3/analyze"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("x-api-key", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Stream start
require 'uri'
require 'net/http'

url = URI("https://api.twelvelabs.io/v1.3/analyze")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java Stream start
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.twelvelabs.io/v1.3/analyze")
  .header("x-api-key", "<apiKey>")
  .asString();
```

```php Stream start
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.twelvelabs.io/v1.3/analyze', [
  'headers' => [
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Stream start
using RestSharp;

var client = new RestClient("https://api.twelvelabs.io/v1.3/analyze");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift Stream start
import Foundation

let headers = ["x-api-key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.twelvelabs.io/v1.3/analyze")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Text generation

**Response**

```json
{
  "event_type": "text_generation",
  "text": "light-hearted moments of cats"
}
```

**SDK Code**

```python Text generation
import requests

url = "https://api.twelvelabs.io/v1.3/analyze"

headers = {"x-api-key": "<apiKey>"}

response = requests.post(url, headers=headers)

print(response.json())
```

```javascript Text generation
const url = 'https://api.twelvelabs.io/v1.3/analyze';
const options = {method: 'POST', headers: {'x-api-key': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Text generation
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.twelvelabs.io/v1.3/analyze"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("x-api-key", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Text generation
require 'uri'
require 'net/http'

url = URI("https://api.twelvelabs.io/v1.3/analyze")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java Text generation
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.twelvelabs.io/v1.3/analyze")
  .header("x-api-key", "<apiKey>")
  .asString();
```

```php Text generation
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.twelvelabs.io/v1.3/analyze', [
  'headers' => [
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Text generation
using RestSharp;

var client = new RestClient("https://api.twelvelabs.io/v1.3/analyze");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift Text generation
import Foundation

let headers = ["x-api-key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.twelvelabs.io/v1.3/analyze")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Stream end

**Response**

```json
{
  "event_type": "stream_end",
  "finish_reason": "stop",
  "metadata": {
    "generation_id": "6947ee74-5f0e-4dd7-9a4a-31a14ca7a2ee",
    "usage": {
      "output_tokens": 230,
      "input_tokens": 1850
    }
  }
}
```

**SDK Code**

```python Stream end
import requests

url = "https://api.twelvelabs.io/v1.3/analyze"

headers = {"x-api-key": "<apiKey>"}

response = requests.post(url, headers=headers)

print(response.json())
```

```javascript Stream end
const url = 'https://api.twelvelabs.io/v1.3/analyze';
const options = {method: 'POST', headers: {'x-api-key': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Stream end
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.twelvelabs.io/v1.3/analyze"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("x-api-key", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Stream end
require 'uri'
require 'net/http'

url = URI("https://api.twelvelabs.io/v1.3/analyze")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java Stream end
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.twelvelabs.io/v1.3/analyze")
  .header("x-api-key", "<apiKey>")
  .asString();
```

```php Stream end
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.twelvelabs.io/v1.3/analyze', [
  'headers' => [
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Stream end
using RestSharp;

var client = new RestClient("https://api.twelvelabs.io/v1.3/analyze");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift Stream end
import Foundation

let headers = ["x-api-key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.twelvelabs.io/v1.3/analyze")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Stream end with truncation

**Response**

```json
{
  "event_type": "stream_end",
  "finish_reason": "length",
  "metadata": {
    "generation_id": "6947ee74-5f0e-4dd7-9a4a-31a14ca7a2ef",
    "usage": {
      "output_tokens": 2048,
      "input_tokens": 9420
    }
  },
  "error": {
    "message": "output truncated: the generation reached the configured max_tokens. The partial output is returned; raise max_tokens if you need a longer response."
  }
}
```

**SDK Code**

```python Stream end with truncation
import requests

url = "https://api.twelvelabs.io/v1.3/analyze"

headers = {"x-api-key": "<apiKey>"}

response = requests.post(url, headers=headers)

print(response.json())
```

```javascript Stream end with truncation
const url = 'https://api.twelvelabs.io/v1.3/analyze';
const options = {method: 'POST', headers: {'x-api-key': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Stream end with truncation
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.twelvelabs.io/v1.3/analyze"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("x-api-key", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Stream end with truncation
require 'uri'
require 'net/http'

url = URI("https://api.twelvelabs.io/v1.3/analyze")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java Stream end with truncation
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.twelvelabs.io/v1.3/analyze")
  .header("x-api-key", "<apiKey>")
  .asString();
```

```php Stream end with truncation
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.twelvelabs.io/v1.3/analyze', [
  'headers' => [
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Stream end with truncation
using RestSharp;

var client = new RestClient("https://api.twelvelabs.io/v1.3/analyze");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift Stream end with truncation
import Foundation

let headers = ["x-api-key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.twelvelabs.io/v1.3/analyze")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Video URL with prompt

**Request**

```json
{
  "model_name": "pegasus1.5",
  "video": {
    "type": "url",
    "url": "https://example.com/video.mp4"
  },
  "prompt": "Summarize the key events in this clip.",
  "stream": false,
  "max_tokens": 1024
}
```

**Response**

```json
{
  "event_type": "stream_start",
  "id": "f1385675-207b-4b22-8b3e-f8fa32a8ddc9",
  "data": "The video does not show any dishes or food items, so a comparison cannot be made.",
  "finish_reason": "stop",
  "usage": {
    "output_tokens": 23,
    "input_tokens": 1850
  }
}
```

**SDK Code**

```python Video URL with prompt
import requests

url = "https://api.twelvelabs.io/v1.3/analyze"

payload = {
    "model_name": "pegasus1.5",
    "video": {
        "type": "url",
        "url": "https://example.com/video.mp4"
    },
    "prompt": "Summarize the key events in this clip.",
    "stream": False,
    "max_tokens": 1024
}
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Video URL with prompt
const url = 'https://api.twelvelabs.io/v1.3/analyze';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"model_name":"pegasus1.5","video":{"type":"url","url":"https://example.com/video.mp4"},"prompt":"Summarize the key events in this clip.","stream":false,"max_tokens":1024}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Video URL with prompt
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.twelvelabs.io/v1.3/analyze"

	payload := strings.NewReader("{\n  \"model_name\": \"pegasus1.5\",\n  \"video\": {\n    \"type\": \"url\",\n    \"url\": \"https://example.com/video.mp4\"\n  },\n  \"prompt\": \"Summarize the key events in this clip.\",\n  \"stream\": false,\n  \"max_tokens\": 1024\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Video URL with prompt
require 'uri'
require 'net/http'

url = URI("https://api.twelvelabs.io/v1.3/analyze")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"model_name\": \"pegasus1.5\",\n  \"video\": {\n    \"type\": \"url\",\n    \"url\": \"https://example.com/video.mp4\"\n  },\n  \"prompt\": \"Summarize the key events in this clip.\",\n  \"stream\": false,\n  \"max_tokens\": 1024\n}"

response = http.request(request)
puts response.read_body
```

```java Video URL with prompt
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.twelvelabs.io/v1.3/analyze")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"model_name\": \"pegasus1.5\",\n  \"video\": {\n    \"type\": \"url\",\n    \"url\": \"https://example.com/video.mp4\"\n  },\n  \"prompt\": \"Summarize the key events in this clip.\",\n  \"stream\": false,\n  \"max_tokens\": 1024\n}")
  .asString();
```

```php Video URL with prompt
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.twelvelabs.io/v1.3/analyze', [
  'body' => '{
  "model_name": "pegasus1.5",
  "video": {
    "type": "url",
    "url": "https://example.com/video.mp4"
  },
  "prompt": "Summarize the key events in this clip.",
  "stream": false,
  "max_tokens": 1024
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Video URL with prompt
using RestSharp;

var client = new RestClient("https://api.twelvelabs.io/v1.3/analyze");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"model_name\": \"pegasus1.5\",\n  \"video\": {\n    \"type\": \"url\",\n    \"url\": \"https://example.com/video.mp4\"\n  },\n  \"prompt\": \"Summarize the key events in this clip.\",\n  \"stream\": false,\n  \"max_tokens\": 1024\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Video URL with prompt
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "model_name": "pegasus1.5",
  "video": [
    "type": "url",
    "url": "https://example.com/video.mp4"
  ],
  "prompt": "Summarize the key events in this clip.",
  "stream": false,
  "max_tokens": 1024
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.twelvelabs.io/v1.3/analyze")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Clip the video before analysis

**Request**

```json
{
  "model_name": "pegasus1.5",
  "video": {
    "type": "url",
    "url": "https://example.com/video.mp4"
  },
  "prompt": "Summarize the most important segment in this clip.",
  "stream": false,
  "max_tokens": 1024,
  "start_time": 5,
  "end_time": 30
}
```

**Response**

```json
{
  "event_type": "stream_start",
  "id": "f1385675-207b-4b22-8b3e-f8fa32a8ddc9",
  "data": "The video does not show any dishes or food items, so a comparison cannot be made.",
  "finish_reason": "stop",
  "usage": {
    "output_tokens": 23,
    "input_tokens": 1850
  }
}
```

**SDK Code**

```python Clip the video before analysis
import requests

url = "https://api.twelvelabs.io/v1.3/analyze"

payload = {
    "model_name": "pegasus1.5",
    "video": {
        "type": "url",
        "url": "https://example.com/video.mp4"
    },
    "prompt": "Summarize the most important segment in this clip.",
    "stream": False,
    "max_tokens": 1024,
    "start_time": 5,
    "end_time": 30
}
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Clip the video before analysis
const url = 'https://api.twelvelabs.io/v1.3/analyze';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"model_name":"pegasus1.5","video":{"type":"url","url":"https://example.com/video.mp4"},"prompt":"Summarize the most important segment in this clip.","stream":false,"max_tokens":1024,"start_time":5,"end_time":30}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Clip the video before analysis
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.twelvelabs.io/v1.3/analyze"

	payload := strings.NewReader("{\n  \"model_name\": \"pegasus1.5\",\n  \"video\": {\n    \"type\": \"url\",\n    \"url\": \"https://example.com/video.mp4\"\n  },\n  \"prompt\": \"Summarize the most important segment in this clip.\",\n  \"stream\": false,\n  \"max_tokens\": 1024,\n  \"start_time\": 5,\n  \"end_time\": 30\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Clip the video before analysis
require 'uri'
require 'net/http'

url = URI("https://api.twelvelabs.io/v1.3/analyze")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"model_name\": \"pegasus1.5\",\n  \"video\": {\n    \"type\": \"url\",\n    \"url\": \"https://example.com/video.mp4\"\n  },\n  \"prompt\": \"Summarize the most important segment in this clip.\",\n  \"stream\": false,\n  \"max_tokens\": 1024,\n  \"start_time\": 5,\n  \"end_time\": 30\n}"

response = http.request(request)
puts response.read_body
```

```java Clip the video before analysis
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.twelvelabs.io/v1.3/analyze")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"model_name\": \"pegasus1.5\",\n  \"video\": {\n    \"type\": \"url\",\n    \"url\": \"https://example.com/video.mp4\"\n  },\n  \"prompt\": \"Summarize the most important segment in this clip.\",\n  \"stream\": false,\n  \"max_tokens\": 1024,\n  \"start_time\": 5,\n  \"end_time\": 30\n}")
  .asString();
```

```php Clip the video before analysis
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.twelvelabs.io/v1.3/analyze', [
  'body' => '{
  "model_name": "pegasus1.5",
  "video": {
    "type": "url",
    "url": "https://example.com/video.mp4"
  },
  "prompt": "Summarize the most important segment in this clip.",
  "stream": false,
  "max_tokens": 1024,
  "start_time": 5,
  "end_time": 30
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Clip the video before analysis
using RestSharp;

var client = new RestClient("https://api.twelvelabs.io/v1.3/analyze");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"model_name\": \"pegasus1.5\",\n  \"video\": {\n    \"type\": \"url\",\n    \"url\": \"https://example.com/video.mp4\"\n  },\n  \"prompt\": \"Summarize the most important segment in this clip.\",\n  \"stream\": false,\n  \"max_tokens\": 1024,\n  \"start_time\": 5,\n  \"end_time\": 30\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Clip the video before analysis
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "model_name": "pegasus1.5",
  "video": [
    "type": "url",
    "url": "https://example.com/video.mp4"
  ],
  "prompt": "Summarize the most important segment in this clip.",
  "stream": false,
  "max_tokens": 1024,
  "start_time": 5,
  "end_time": 30
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.twelvelabs.io/v1.3/analyze")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Structured prompt with reference images

**Request**

```json
{
  "model_name": "pegasus1.5",
  "video": {
    "type": "url",
    "url": "https://example.com/video.mp4"
  },
  "prompt_v2": {
    "input_text": "Compare <@curry> with anything food-related visible in this clip.",
    "media_sources": [
      {
        "name": "curry",
        "media_type": "image",
        "url": "https://example.com/curry.jpg"
      }
    ]
  },
  "stream": false,
  "max_tokens": 4096
}
```

**Response**

```json
{
  "event_type": "stream_start",
  "id": "f1385675-207b-4b22-8b3e-f8fa32a8ddc9",
  "data": "The video does not show any dishes or food items, so a comparison cannot be made.",
  "finish_reason": "stop",
  "usage": {
    "output_tokens": 23,
    "input_tokens": 1850
  }
}
```

**SDK Code**

```python Structured prompt with reference images
import requests

url = "https://api.twelvelabs.io/v1.3/analyze"

payload = {
    "model_name": "pegasus1.5",
    "video": {
        "type": "url",
        "url": "https://example.com/video.mp4"
    },
    "prompt_v2": {
        "input_text": "Compare <@curry> with anything food-related visible in this clip.",
        "media_sources": [
            {
                "name": "curry",
                "media_type": "image",
                "url": "https://example.com/curry.jpg"
            }
        ]
    },
    "stream": False,
    "max_tokens": 4096
}
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Structured prompt with reference images
const url = 'https://api.twelvelabs.io/v1.3/analyze';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"model_name":"pegasus1.5","video":{"type":"url","url":"https://example.com/video.mp4"},"prompt_v2":{"input_text":"Compare <@curry> with anything food-related visible in this clip.","media_sources":[{"name":"curry","media_type":"image","url":"https://example.com/curry.jpg"}]},"stream":false,"max_tokens":4096}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Structured prompt with reference images
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.twelvelabs.io/v1.3/analyze"

	payload := strings.NewReader("{\n  \"model_name\": \"pegasus1.5\",\n  \"video\": {\n    \"type\": \"url\",\n    \"url\": \"https://example.com/video.mp4\"\n  },\n  \"prompt_v2\": {\n    \"input_text\": \"Compare <@curry> with anything food-related visible in this clip.\",\n    \"media_sources\": [\n      {\n        \"name\": \"curry\",\n        \"media_type\": \"image\",\n        \"url\": \"https://example.com/curry.jpg\"\n      }\n    ]\n  },\n  \"stream\": false,\n  \"max_tokens\": 4096\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Structured prompt with reference images
require 'uri'
require 'net/http'

url = URI("https://api.twelvelabs.io/v1.3/analyze")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"model_name\": \"pegasus1.5\",\n  \"video\": {\n    \"type\": \"url\",\n    \"url\": \"https://example.com/video.mp4\"\n  },\n  \"prompt_v2\": {\n    \"input_text\": \"Compare <@curry> with anything food-related visible in this clip.\",\n    \"media_sources\": [\n      {\n        \"name\": \"curry\",\n        \"media_type\": \"image\",\n        \"url\": \"https://example.com/curry.jpg\"\n      }\n    ]\n  },\n  \"stream\": false,\n  \"max_tokens\": 4096\n}"

response = http.request(request)
puts response.read_body
```

```java Structured prompt with reference images
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.twelvelabs.io/v1.3/analyze")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"model_name\": \"pegasus1.5\",\n  \"video\": {\n    \"type\": \"url\",\n    \"url\": \"https://example.com/video.mp4\"\n  },\n  \"prompt_v2\": {\n    \"input_text\": \"Compare <@curry> with anything food-related visible in this clip.\",\n    \"media_sources\": [\n      {\n        \"name\": \"curry\",\n        \"media_type\": \"image\",\n        \"url\": \"https://example.com/curry.jpg\"\n      }\n    ]\n  },\n  \"stream\": false,\n  \"max_tokens\": 4096\n}")
  .asString();
```

```php Structured prompt with reference images
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.twelvelabs.io/v1.3/analyze', [
  'body' => '{
  "model_name": "pegasus1.5",
  "video": {
    "type": "url",
    "url": "https://example.com/video.mp4"
  },
  "prompt_v2": {
    "input_text": "Compare <@curry> with anything food-related visible in this clip.",
    "media_sources": [
      {
        "name": "curry",
        "media_type": "image",
        "url": "https://example.com/curry.jpg"
      }
    ]
  },
  "stream": false,
  "max_tokens": 4096
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Structured prompt with reference images
using RestSharp;

var client = new RestClient("https://api.twelvelabs.io/v1.3/analyze");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"model_name\": \"pegasus1.5\",\n  \"video\": {\n    \"type\": \"url\",\n    \"url\": \"https://example.com/video.mp4\"\n  },\n  \"prompt_v2\": {\n    \"input_text\": \"Compare <@curry> with anything food-related visible in this clip.\",\n    \"media_sources\": [\n      {\n        \"name\": \"curry\",\n        \"media_type\": \"image\",\n        \"url\": \"https://example.com/curry.jpg\"\n      }\n    ]\n  },\n  \"stream\": false,\n  \"max_tokens\": 4096\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Structured prompt with reference images
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "model_name": "pegasus1.5",
  "video": [
    "type": "url",
    "url": "https://example.com/video.mp4"
  ],
  "prompt_v2": [
    "input_text": "Compare <@curry> with anything food-related visible in this clip.",
    "media_sources": [
      [
        "name": "curry",
        "media_type": "image",
        "url": "https://example.com/curry.jpg"
      ]
    ]
  ],
  "stream": false,
  "max_tokens": 4096
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.twelvelabs.io/v1.3/analyze")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### JSON schema with start_time/end_time integers

**Request**

```json
{
  "model_name": "pegasus1.5",
  "video": {
    "type": "url",
    "url": "https://example.com/video.mp4"
  },
  "prompt": "Summarize and give start_time and end_time of the most important segment.",
  "stream": false,
  "response_format": {
    "type": "json_schema",
    "json_schema": {
      "type": "object",
      "properties": {
        "summary": {
          "type": "string"
        },
        "start_time": {
          "type": "integer"
        },
        "end_time": {
          "type": "integer"
        }
      }
    }
  }
}
```

**Response**

```json
{
  "event_type": "stream_start",
  "id": "f1385675-207b-4b22-8b3e-f8fa32a8ddc9",
  "data": "The video does not show any dishes or food items, so a comparison cannot be made.",
  "finish_reason": "stop",
  "usage": {
    "output_tokens": 23,
    "input_tokens": 1850
  }
}
```

**SDK Code**

```python JSON schema with start_time/end_time integers
import requests

url = "https://api.twelvelabs.io/v1.3/analyze"

payload = {
    "model_name": "pegasus1.5",
    "video": {
        "type": "url",
        "url": "https://example.com/video.mp4"
    },
    "prompt": "Summarize and give start_time and end_time of the most important segment.",
    "stream": False,
    "response_format": {
        "type": "json_schema",
        "json_schema": {
            "type": "object",
            "properties": {
                "summary": { "type": "string" },
                "start_time": { "type": "integer" },
                "end_time": { "type": "integer" }
            }
        }
    }
}
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript JSON schema with start_time/end_time integers
const url = 'https://api.twelvelabs.io/v1.3/analyze';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"model_name":"pegasus1.5","video":{"type":"url","url":"https://example.com/video.mp4"},"prompt":"Summarize and give start_time and end_time of the most important segment.","stream":false,"response_format":{"type":"json_schema","json_schema":{"type":"object","properties":{"summary":{"type":"string"},"start_time":{"type":"integer"},"end_time":{"type":"integer"}}}}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go JSON schema with start_time/end_time integers
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.twelvelabs.io/v1.3/analyze"

	payload := strings.NewReader("{\n  \"model_name\": \"pegasus1.5\",\n  \"video\": {\n    \"type\": \"url\",\n    \"url\": \"https://example.com/video.mp4\"\n  },\n  \"prompt\": \"Summarize and give start_time and end_time of the most important segment.\",\n  \"stream\": false,\n  \"response_format\": {\n    \"type\": \"json_schema\",\n    \"json_schema\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"summary\": {\n          \"type\": \"string\"\n        },\n        \"start_time\": {\n          \"type\": \"integer\"\n        },\n        \"end_time\": {\n          \"type\": \"integer\"\n        }\n      }\n    }\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby JSON schema with start_time/end_time integers
require 'uri'
require 'net/http'

url = URI("https://api.twelvelabs.io/v1.3/analyze")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"model_name\": \"pegasus1.5\",\n  \"video\": {\n    \"type\": \"url\",\n    \"url\": \"https://example.com/video.mp4\"\n  },\n  \"prompt\": \"Summarize and give start_time and end_time of the most important segment.\",\n  \"stream\": false,\n  \"response_format\": {\n    \"type\": \"json_schema\",\n    \"json_schema\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"summary\": {\n          \"type\": \"string\"\n        },\n        \"start_time\": {\n          \"type\": \"integer\"\n        },\n        \"end_time\": {\n          \"type\": \"integer\"\n        }\n      }\n    }\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java JSON schema with start_time/end_time integers
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.twelvelabs.io/v1.3/analyze")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"model_name\": \"pegasus1.5\",\n  \"video\": {\n    \"type\": \"url\",\n    \"url\": \"https://example.com/video.mp4\"\n  },\n  \"prompt\": \"Summarize and give start_time and end_time of the most important segment.\",\n  \"stream\": false,\n  \"response_format\": {\n    \"type\": \"json_schema\",\n    \"json_schema\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"summary\": {\n          \"type\": \"string\"\n        },\n        \"start_time\": {\n          \"type\": \"integer\"\n        },\n        \"end_time\": {\n          \"type\": \"integer\"\n        }\n      }\n    }\n  }\n}")
  .asString();
```

```php JSON schema with start_time/end_time integers
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.twelvelabs.io/v1.3/analyze', [
  'body' => '{
  "model_name": "pegasus1.5",
  "video": {
    "type": "url",
    "url": "https://example.com/video.mp4"
  },
  "prompt": "Summarize and give start_time and end_time of the most important segment.",
  "stream": false,
  "response_format": {
    "type": "json_schema",
    "json_schema": {
      "type": "object",
      "properties": {
        "summary": {
          "type": "string"
        },
        "start_time": {
          "type": "integer"
        },
        "end_time": {
          "type": "integer"
        }
      }
    }
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp JSON schema with start_time/end_time integers
using RestSharp;

var client = new RestClient("https://api.twelvelabs.io/v1.3/analyze");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"model_name\": \"pegasus1.5\",\n  \"video\": {\n    \"type\": \"url\",\n    \"url\": \"https://example.com/video.mp4\"\n  },\n  \"prompt\": \"Summarize and give start_time and end_time of the most important segment.\",\n  \"stream\": false,\n  \"response_format\": {\n    \"type\": \"json_schema\",\n    \"json_schema\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"summary\": {\n          \"type\": \"string\"\n        },\n        \"start_time\": {\n          \"type\": \"integer\"\n        },\n        \"end_time\": {\n          \"type\": \"integer\"\n        }\n      }\n    }\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift JSON schema with start_time/end_time integers
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "model_name": "pegasus1.5",
  "video": [
    "type": "url",
    "url": "https://example.com/video.mp4"
  ],
  "prompt": "Summarize and give start_time and end_time of the most important segment.",
  "stream": false,
  "response_format": [
    "type": "json_schema",
    "json_schema": [
      "type": "object",
      "properties": [
        "summary": ["type": "string"],
        "start_time": ["type": "integer"],
        "end_time": ["type": "integer"]
      ]
    ]
  ]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.twelvelabs.io/v1.3/analyze")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### JSON schema with `timestamp` fields

**Request**

```json
{
  "model_name": "pegasus1.5",
  "video": {
    "type": "url",
    "url": "https://example.com/video.mp4"
  },
  "prompt": "Identify intro, main content, and outro clips.",
  "stream": false,
  "response_format": {
    "type": "json_schema",
    "json_schema": {
      "type": "object",
      "properties": {
        "clip_start": {
          "type": "timestamp",
          "format": "seconds"
        },
        "events": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "intro_end": {
                "type": "timestamp",
                "format": "hh:mm:ss"
              },
              "outro_start": {
                "type": "timestamp",
                "format": "hh:mm:ss.fff"
              },
              "label": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}
```

**Response**

```json
{
  "event_type": "stream_start",
  "id": "f1385675-207b-4b22-8b3e-f8fa32a8ddc9",
  "data": "The video does not show any dishes or food items, so a comparison cannot be made.",
  "finish_reason": "stop",
  "usage": {
    "output_tokens": 23,
    "input_tokens": 1850
  }
}
```

**SDK Code**

```python JSON schema with `timestamp` fields
import requests

url = "https://api.twelvelabs.io/v1.3/analyze"

payload = {
    "model_name": "pegasus1.5",
    "video": {
        "type": "url",
        "url": "https://example.com/video.mp4"
    },
    "prompt": "Identify intro, main content, and outro clips.",
    "stream": False,
    "response_format": {
        "type": "json_schema",
        "json_schema": {
            "type": "object",
            "properties": {
                "clip_start": {
                    "type": "timestamp",
                    "format": "seconds"
                },
                "events": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "intro_end": {
                                "type": "timestamp",
                                "format": "hh:mm:ss"
                            },
                            "outro_start": {
                                "type": "timestamp",
                                "format": "hh:mm:ss.fff"
                            },
                            "label": { "type": "string" }
                        }
                    }
                }
            }
        }
    }
}
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript JSON schema with `timestamp` fields
const url = 'https://api.twelvelabs.io/v1.3/analyze';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"model_name":"pegasus1.5","video":{"type":"url","url":"https://example.com/video.mp4"},"prompt":"Identify intro, main content, and outro clips.","stream":false,"response_format":{"type":"json_schema","json_schema":{"type":"object","properties":{"clip_start":{"type":"timestamp","format":"seconds"},"events":{"type":"array","items":{"type":"object","properties":{"intro_end":{"type":"timestamp","format":"hh:mm:ss"},"outro_start":{"type":"timestamp","format":"hh:mm:ss.fff"},"label":{"type":"string"}}}}}}}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go JSON schema with `timestamp` fields
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.twelvelabs.io/v1.3/analyze"

	payload := strings.NewReader("{\n  \"model_name\": \"pegasus1.5\",\n  \"video\": {\n    \"type\": \"url\",\n    \"url\": \"https://example.com/video.mp4\"\n  },\n  \"prompt\": \"Identify intro, main content, and outro clips.\",\n  \"stream\": false,\n  \"response_format\": {\n    \"type\": \"json_schema\",\n    \"json_schema\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"clip_start\": {\n          \"type\": \"timestamp\",\n          \"format\": \"seconds\"\n        },\n        \"events\": {\n          \"type\": \"array\",\n          \"items\": {\n            \"type\": \"object\",\n            \"properties\": {\n              \"intro_end\": {\n                \"type\": \"timestamp\",\n                \"format\": \"hh:mm:ss\"\n              },\n              \"outro_start\": {\n                \"type\": \"timestamp\",\n                \"format\": \"hh:mm:ss.fff\"\n              },\n              \"label\": {\n                \"type\": \"string\"\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby JSON schema with `timestamp` fields
require 'uri'
require 'net/http'

url = URI("https://api.twelvelabs.io/v1.3/analyze")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"model_name\": \"pegasus1.5\",\n  \"video\": {\n    \"type\": \"url\",\n    \"url\": \"https://example.com/video.mp4\"\n  },\n  \"prompt\": \"Identify intro, main content, and outro clips.\",\n  \"stream\": false,\n  \"response_format\": {\n    \"type\": \"json_schema\",\n    \"json_schema\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"clip_start\": {\n          \"type\": \"timestamp\",\n          \"format\": \"seconds\"\n        },\n        \"events\": {\n          \"type\": \"array\",\n          \"items\": {\n            \"type\": \"object\",\n            \"properties\": {\n              \"intro_end\": {\n                \"type\": \"timestamp\",\n                \"format\": \"hh:mm:ss\"\n              },\n              \"outro_start\": {\n                \"type\": \"timestamp\",\n                \"format\": \"hh:mm:ss.fff\"\n              },\n              \"label\": {\n                \"type\": \"string\"\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java JSON schema with `timestamp` fields
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.twelvelabs.io/v1.3/analyze")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"model_name\": \"pegasus1.5\",\n  \"video\": {\n    \"type\": \"url\",\n    \"url\": \"https://example.com/video.mp4\"\n  },\n  \"prompt\": \"Identify intro, main content, and outro clips.\",\n  \"stream\": false,\n  \"response_format\": {\n    \"type\": \"json_schema\",\n    \"json_schema\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"clip_start\": {\n          \"type\": \"timestamp\",\n          \"format\": \"seconds\"\n        },\n        \"events\": {\n          \"type\": \"array\",\n          \"items\": {\n            \"type\": \"object\",\n            \"properties\": {\n              \"intro_end\": {\n                \"type\": \"timestamp\",\n                \"format\": \"hh:mm:ss\"\n              },\n              \"outro_start\": {\n                \"type\": \"timestamp\",\n                \"format\": \"hh:mm:ss.fff\"\n              },\n              \"label\": {\n                \"type\": \"string\"\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n}")
  .asString();
```

```php JSON schema with `timestamp` fields
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.twelvelabs.io/v1.3/analyze', [
  'body' => '{
  "model_name": "pegasus1.5",
  "video": {
    "type": "url",
    "url": "https://example.com/video.mp4"
  },
  "prompt": "Identify intro, main content, and outro clips.",
  "stream": false,
  "response_format": {
    "type": "json_schema",
    "json_schema": {
      "type": "object",
      "properties": {
        "clip_start": {
          "type": "timestamp",
          "format": "seconds"
        },
        "events": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "intro_end": {
                "type": "timestamp",
                "format": "hh:mm:ss"
              },
              "outro_start": {
                "type": "timestamp",
                "format": "hh:mm:ss.fff"
              },
              "label": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp JSON schema with `timestamp` fields
using RestSharp;

var client = new RestClient("https://api.twelvelabs.io/v1.3/analyze");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"model_name\": \"pegasus1.5\",\n  \"video\": {\n    \"type\": \"url\",\n    \"url\": \"https://example.com/video.mp4\"\n  },\n  \"prompt\": \"Identify intro, main content, and outro clips.\",\n  \"stream\": false,\n  \"response_format\": {\n    \"type\": \"json_schema\",\n    \"json_schema\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"clip_start\": {\n          \"type\": \"timestamp\",\n          \"format\": \"seconds\"\n        },\n        \"events\": {\n          \"type\": \"array\",\n          \"items\": {\n            \"type\": \"object\",\n            \"properties\": {\n              \"intro_end\": {\n                \"type\": \"timestamp\",\n                \"format\": \"hh:mm:ss\"\n              },\n              \"outro_start\": {\n                \"type\": \"timestamp\",\n                \"format\": \"hh:mm:ss.fff\"\n              },\n              \"label\": {\n                \"type\": \"string\"\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift JSON schema with `timestamp` fields
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "model_name": "pegasus1.5",
  "video": [
    "type": "url",
    "url": "https://example.com/video.mp4"
  ],
  "prompt": "Identify intro, main content, and outro clips.",
  "stream": false,
  "response_format": [
    "type": "json_schema",
    "json_schema": [
      "type": "object",
      "properties": [
        "clip_start": [
          "type": "timestamp",
          "format": "seconds"
        ],
        "events": [
          "type": "array",
          "items": [
            "type": "object",
            "properties": [
              "intro_end": [
                "type": "timestamp",
                "format": "hh:mm:ss"
              ],
              "outro_start": [
                "type": "timestamp",
                "format": "hh:mm:ss.fff"
              ],
              "label": ["type": "string"]
            ]
          ]
        ]
      ]
    ]
  ]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.twelvelabs.io/v1.3/analyze")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```