Indexes, videos, and tasks

When listing your indexes, videos, or video indexing tasks, the platform supports the following parameters that allow you to control pagination behavior:

  • page: A number that identifies the page you want to retrieve. The default value is 1.
  • page_limit: Specifies the maximum number of items on each page. The default value is 10 and the maximum value is 50.

The examples on this page are specific to listing your indexes. However, the principles demonstrated are similar when listing your video indexing tasks or videos.

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.

Prerequisites

Examples

The SDKs provide two distinct methods for listing items, each suited to different use cases and requirements. Selecting the most efficient method is important for optimizing the performance of your application:

  • Direct pagination: Choose this method for retrieving a specific page, mainly when the total number of items is manageable, or you must fetch a single page of results.
  • Iterative pagination: Choose this method for iterative navigation through lists, mainly when your application must retrieve a large number of items.

Direct pagination

Retrieve the first page of results

The following example code retrieves the first page of results using the default value for the page and page_limit parameters by invoking the list method of the index object with no parameters:

from twelvelabs import TwelveLabs

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

indexes = client.index.list()
for index in indexes:
    print(
        f"id={index.id} name={index.name} engines={index.engines} created_at={index.created_at}"
    )
import { TwelveLabs } from 'twelvelabs-js';

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

const indexes = await client.index.list();
indexes.forEach((index) => {
  console.log(
    `id=${index.id} name=${index.name} engines=${JSON.stringify(index.engines)} created_at=${index.createdAt}`,
  );
});

The following output was truncated for brevity:

id=65e5ac69bb29f13bdd6f37c4 name=2024-03-04T11:11:36.583Z engines=[Engine(name='pegasus1', options=['visual', 'conversation'], addons=None)] created_at=2024-03-04T11:11:37.393Z
id=65e59606bb29f13bdd6f3794 name=2024-03-04T09:36:06.079Z engines=[Engine(name='pegasus1', options=['visual', 'conversation'], addons=None)] created_at=2024-03-04T09:36:06.791Z
id=65e5945abb29f13bdd6f378c name=2024-03-04T09:28:57.739Z engines=[Engine(name='pegasus1', options=['visual', 'conversation'], addons=None)] created_at=2024-03-04T09:28:58.473Z

Retrieve a specific page

The following example code uses the page parameter to retrieve a specific page (2):

from twelvelabs import TwelveLabs

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

indexes = client.index.list(page=2)
for index in indexes:
    print(
        f"id={index.id} name={index.name} engines={index.engines} created_at={index.created_at}"
    )
import { TwelveLabs } from 'twelvelabs-js';

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

const indexes = await client.index.list({ page: 2 });
indexes.forEach((index) => {
  console.log(
    `id=${index.id} name=${index.name} engines=${JSON.stringify(index.engines)} created_at=${index.createdAt}`,
  );
});

The following output was truncated for brevity:

id=65e567dabb29f13bdd6f372f name=2024-03-04T06:19:05.798Z engines=[Engine(name='pegasus1', options=['visual', 'conversation'], addons=None)] created_at=2024-03-04T06:19:06.468Z
id=65e56706bb29f13bdd6f372e name=2024-03-04T06:15:33.863Z engines=[Engine(name='pegasus1', options=['visual', 'conversation'], addons=None)] created_at=2024-03-04T06:15:34.522Z
id=65e566f9bb29f13bdd6f372d name=2024-03-04T06:15:20.859Z engines=[Engine(name='pegasus1', options=['visual', 'conversation'], addons=None)] created_at=2024-03-04T06:15:21.52Z

If the number of items on a page is less than the maximum number of items the platform should return on that page, you've reached the end of the dataset.

Limits

The following example code uses the page_limit parameter to specify a limit of 2 items on each page:

from twelvelabs import TwelveLabs

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

indexes = client.index.list(page_limit=2)
for index in indexes:
    print(
        f"id={index.id} name={index.name} engines={index.engines} created_at={index.created_at}"
    )
import { TwelveLabs } from 'twelvelabs-js';

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

const indexes = await client.index.list({ pageLimit: 2 });
indexes.forEach((index) => {
  console.log(
    `id=${index.id} name=${index.name} engines=${JSON.stringify(index.engines)} created_at=${index.createdAt}`,
  );
});

The output should look similar to the following one:

id=65e71802bb29f13bdd6f38d8 name=2024-03-05T13:02:57.938Z engines=[Engine(name='pegasus1', options=['visual', 'conversation'], addons=None), Engine(name='marengo2.5', options=['visual', 'conversation', 'text_in_video'], addons=None)] created_at=2024-03-05T13:02:58.531Z
id=65e5ac69bb29f13bdd6f37c4 name=2024-03-04T11:11:36.583Z engines=[Engine(name='pegasus1', options=['visual', 'conversation'], addons=None)] created_at=2024-03-04T11:11:37.393Z

Iterative pagination

To retrieve the first page of results, invoke the list_pagination method of the index object. To retrieve subsequent pages of results, use the iterator protocol in Python or the async iterator protocol in JavaScript.

Retrieve the first page of results

The following example code retrieves the first page of results using the default value for the page and page_limit parameters by invoking the list_pagination method of the index object with no parameters:

from twelvelabs import TwelveLabs

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

indexes = client.index.list_pagination()

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

print_page(indexes.data)
import { TwelveLabs, Index } from 'twelvelabs-js';

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

const indexes = await client.index.listPagination();
indexes.data.forEach((index: Index) => {
  console.log(
    `id=${index.id} name=${index.name} engines=${JSON.stringify(index.engines)} created_at=${index.createdAt}`,
  );

The following example output was truncated for brevity:

id=65e71802bb29f13bdd6f38d8 name=2024-03-05T13:02:57.938Z engines=[Engine(name='pegasus1', options=['visual', 'conversation'], addons=None), Engine(name='marengo2.5', options=['visual', 'conversation', 'text_in_video'], addons=None)] created_at=2024-03-05T13:02:58.531Z
id=65e5ac69bb29f13bdd6f37c4 name=2024-03-04T11:11:36.583Z engines=[Engine(name='pegasus1', options=['visual', 'conversation'], addons=None)] created_at=2024-03-04T11:11:37.393Z
id=65e59606bb29f13bdd6f3794 name=2024-03-04T09:36:06.079Z engines=[Engine(name='pegasus1', options=['visual', 'conversation'], addons=None)] created_at=2024-03-04T09:36:06.791Z

Iterate over the results

The following example code iterates over results using the default value for the page and page_limit parameters:

from twelvelabs import TwelveLabs

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

indexes = client.index.list_pagination()

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

print_page(indexes.data)

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

  const client = new TwelveLabs({ apiKey: '<YOUR_API_KEY>'});
  
  const indexes = await client.index.listPagination();
  indexes.data.forEach((index: Index) => {
    console.log(
      `id=${index.id} name=${index.name} engines=${JSON.stringify(index.engines)} created_at=${index.createdAt}`,
    );
  });
  while (true) {
    const nextPageData = await indexes.next();
    if (!nextPageData) {
      break;
    }
    nextPageData.forEach((index: Index) => {
      console.log(
        `id=${index.id} name=${index.name} engines=${JSON.stringify(index.engines)} created_at=${index.createdAt}`,
      );
    });
  }

The following example output was truncated for brevity:

id=65e71802bb29f13bdd6f38d8 name=2024-03-05T13:02:57.938Z engines=[Engine(name='pegasus1', options=['visual', 'conversation'], addons=None), Engine(name='marengo2.5', options=['visual', 'conversation', 'text_in_video'], addons=None)] created_at=2024-03-05T13:02:58.531Z
id=65e5ac69bb29f13bdd6f37c4 name=2024-03-04T11:11:36.583Z engines=[Engine(name='pegasus1', options=['visual', 'conversation'], addons=None)] created_at=2024-03-04T11:11:37.393Z
id=65e59606bb29f13bdd6f3794 name=2024-03-04T09:36:06.079Z engines=[Engine(name='pegasus1', options=['visual', 'conversation'], addons=None)] created_at=2024-03-04T09:36:06.791Z
id=65e5945abb29f13bdd6f378c name=2024-03-04T09:28:57.739Z engines=[Engine(name='pegasus1', options=['visual', 'conversation'], addons=None)] created_at=2024-03-04T09:28:58.473Z

Limits

The following example code iterates over results and specifies a limit of 5 items on each page:

from twelvelabs import TwelveLabs

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

indexes = client.index.list_pagination(page_limit=5)

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

print_page(indexes.data)

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

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

const indexes = await client.index.listPagination({pageLimit:5});
indexes.data.forEach((index: Index) => {
  console.log(
    `id=${index.id} name=${index.name} engines=${JSON.stringify(index.engines)} created_at=${index.createdAt}`,
  );
});
while (true) {
  const nextPageData = await indexes.next();
  if (!nextPageData) {
    break;
  }
  nextPageData.forEach((index: Index) => {
    console.log(
      `id=${index.id} name=${index.name} engines=${JSON.stringify(index.engines)} created_at=${index.createdAt}`,
    );
  });
}

The following example output was truncated for brevity:

id=65e71802bb29f13bdd6f38d8 name=2024-03-05T13:02:57.938Z engines=[Engine(name='pegasus1', options=['visual', 'conversation'], addons=None), Engine(name='marengo2.5', options=['visual', 'conversation', 'text_in_video'], addons=None)] created_at=2024-03-05T13:02:58.531Z
id=65e5ac69bb29f13bdd6f37c4 name=2024-03-04T11:11:36.583Z engines=[Engine(name='pegasus1', options=['visual', 'conversation'], addons=None)] created_at=2024-03-04T11:11:37.393Z
id=65e59606bb29f13bdd6f3794 name=2024-03-04T09:36:06.079Z engines=[Engine(name='pegasus1', options=['visual', 'conversation'], addons=None)] created_at=2024-03-04T09:36:06.791Z
id=65e5945abb29f13bdd6f378c name=2024-03-04T09:28:57.739Z engines=[Engine(name='pegasus1', options=['visual', 'conversation'], addons=None)] created_at=2024-03-04T09:28:58.473Z