Indexes, videos, and tasks

The GET methods of the /indexes, /indexes/videos, and /tasks endpoints support filtering.

You can interact with the platform using one of the available SDKs or an HTTP client like requests or axios. This guide demonstrates how to use the SDKs, the recommended approach for most scenarios. If you need to make direct HTTP requests, refer to the corresponding pages in API Reference section for details.

To filter the results of an API query, you must specify one or more conditions after the endpoint in the URL of the call. To separate the endpoint and the conditions, you must use a ? symbol. If you add multiple conditions, you must separate them using the & symbol.

A condition consists of an expression that specifies:

  • The field you want to filter on
  • An operator
  • The value to compare to

To indicate the relationship between a field and its value, you can use the exact match or comparison operators.

Exact match operator

Use the exact match operator (=) to match only the results that equal the value you specify. The syntax is as follows: <field>=<value>.

Comparison operators

Use the comparison operators ([lte]= and [gte]=) to match based on the arithmetic comparison. The syntax is as follows <field>[lte]=<value> and <field>[gte]=<value>.

Filter composition

You can add multiple filters to a single query. For example, if you want to filter all the video indexing tasks created on a specific date and whose status is pending, you must specify both the created_at and status fields, as shown in this example: created_at=2022-05-17&status=pending.

The examples in this section are specific to using the /tasks endpoint. However, the principles demonstrated are similar when using the /indexes and /indexes/videos endpoints.

📘

Note

Depending on the endpoint, you can filter on various fields. For details, see the API Reference section.

Prerequisites

Examples

Filter on a specific date

The following example code uses the created_at parameter to return all the tasks created on a specific date:

from twelvelabs import TwelveLabs

client = TwelveLabs(api_key="<YOUR_API_KEY>")

indexes = client.task.list_pagination(
  created_at="2022-05-17"
  )

# Utility function to print a specific page
def print_page(page):
  for task in page:
    print(f"id={task.id} status={task.status} created_at={task.created_at}")

print_page(indexes.data)

while True:
    try:
        print_page(next(indexes))
    except StopIteration:
        break
import { TwelveLabs, Task } from 'twelvelabs-js';

const client = new TwelveLabs({ apiKey: '<YOUR_API_KEY>'});

const tasks = await client.task.listPagination({ createdAt: '2022-05-17' });
tasks.data.forEach((task: Task) => {
  console.log(`id=${task.id} status=${task.status}`);
});
while (true) {
  const nextPageData = await tasks.next();
  if (!nextPageData) {
    break;
  }
  nextPageData.forEach((task: Task) => {
    console.log(`id=${task.id} status=${task.status} created_at=${task.createdAt}`);
  });
}

The following example output was truncated for brevity:

  id=6283ab5ef18e21febd160bc3 status=ready created_at=2022-05-17T14:04:14.001Z
  id=6283a0a8f18e21febd160bbf status=ready created_at=2022-05-17T13:18:32.388Z
  id=6283a00df18e21febd160bbc status=ready created_at=2022-05-17T13:15:57.053Z

Filter based on a file name

To filter based on a file name, use the filename parameter as shown in the example below:

from twelvelabs import TwelveLabs

client = TwelveLabs(api_key="<YOUR_API_KEY>")

tasks = client.task.list_pagination(
  filename="<YOUR_FILENAME>" # Example: filename="01.mp4"
  )

# Utility function to print a specific page
def print_page(page):
  for task in page:
    print(f"id={task.id} status={task.status} created_at={task.created_at} metadata={task.metadata}")

print_page(tasks.data)

while True:
    try:
        print_page(next(tasks))
    except StopIteration:
        break
import { TwelveLabs, Task } from 'twelvelabs-js';

const client = new TwelveLabs({ apiKey: '<YOUR_API_KEY>'});

const tasks = await client.task.listPagination({ filename: '<YOUR_FILE_NAME>' }); // Example: filename="01.mp4"
tasks.data.forEach((task: Task) => {
  console.log(`id=${task.id} status=${task.status} metadata=${task.metadata}`);
});
while (true) {
  const nextPageData = await tasks.next();
  if (!nextPageData) {
    break;
  }
  nextPageData.forEach((task: Task) => {
    console.log(`id=${task.id} status=${task.status} created_at=${task.createdAt} metadata=${task.metadata}`);
  });
}

The following output was truncated for brevity:

id=65e5ae52bb29f13bdd6f37c8 status=ready created_at=2024-03-04T11:19:46.901Z metadata={'filename': '01.mp4', 'duration': 579.12, 'width': 640, 'height': 360}
id=65d46ef879384c4778ab30fa status=ready created_at=2024-02-20T09:20:56.321Z metadata={'filename': '01.mp4', 'duration': 579.12, 'width': 640, 'height': 360}

Filter based on duration

To filter based on the duration of a video, use the duration parameter and either the exact match or the comparison operators.

Use the exact match operator

The example below uses the exact match operator to display all the videos of a specific duration (810 seconds):

from twelvelabs import TwelveLabs

client = TwelveLabs(api_key="<YOUR_API_KEY>")

indexes = client.task.list_pagination(
  duration=810
  )

# Utility function to print a specific page
def print_page(page):
  for task in page:
    print(f"id={task.id} status={task.status} created_at={task.created_at} metadata={task.metadata}")

print_page(indexes.data)

while True:
    try:
        print_page(next(indexes))
    except StopIteration:
        break
import { TwelveLabs, Task } from 'twelvelabs-js';

const client = new TwelveLabs({ apiKey: '<YOUR_API_KEY>'});

const tasks = await client.task.listPagination({ duration: 810 });
tasks.data.forEach((task: Task) => {
  console.log(`id=${task.id} status=${task.status}`);
});
while (true) {
  const nextPageData = await tasks.next();
  if (!nextPageData) {
    break;
  }
  nextPageData.forEach((task: Task) => {
    console.log(`id=${task.id} status=${task.status} created_at=${task.createdAt} metadata=${task.metadata}`);
  });
}

The following example output was truncated for brevity:

id=65e5ae52bb29f13bdd6f37c8 status=ready created_at=2024-03-04T11:19:46.901Z metadata={'filename': '02.mp4', 'duration': 810, 'width': 640, 'height': 360}
id=65d46ef879384c4778ab30fa status=ready created_at=2024-02-20T09:20:56.321Z metadata={'filename': '02.mp4', 'duration': 810, 'width': 640, 'height': 360}