Classify

Deprecation notice

The Classify API has been deprecated on Feb 28, 2025.

Recommended alternative: Update to the 1.3 version of the API and use the Pegasus video understanding model to classify videos.

Resources: Migration guide > Use Pegasus to classify videos.

The Resources.Classify class provides methods to classify a set of videos or entire indexes.

Methods

Classify a set of videos

Description: This method classifies a set of videos based on the provided parameters and returns the first page of results.

Function signature and example:

1async videos(
2 { conversationOption = 'semantic', ...restBody }: ClassifyVideosOptions,
3 options: RequestOptions = {},
4): Promise<Models.ClassifyPageResult>

Parameters:

NameTypeRequiredDescription
paramsClassifyVideosOptionsYesParameters for classifying the videos.
optionsRequestOptionsNoAdditional options for the request. Defaults to {}.

The ClassifyVideosOptions interface defines the parameters for classifying a set of videos:

NameTypeRequiredDescription
videoIdsstring[]YesAn array containing the unique identifiers of the videos that you want to classify.

The following properties are inherited from the ClassifyOptions interface:

NameTypeRequiredDescription
options('visual' | 'conversation' | 'text_in_video')[]YesAn array that specifies the sources of information the platform uses when it categorizes a video.
classesArray<{ name: string; prompts: string[]; options?: ('visual' | 'conversation' | 'text_in_video')[]; conversationOption?: 'semantic' | 'exact_match' }>YesAn array of objects containing the names and the definitions of entities or actions that the platform must identify.
conversationOption'semantic' | 'exact_match'NoSpecifies the type of match the platform will perform.
pageLimitnumberNoThe maximum number of results per page.
includeClipsbooleanNoSet this parameter to true to retrieve detailed information about each matching video clip.
thresholdRecord<string, any>NoThresholds for different classification options.
showDetailedScorebooleanNoWhether to show detailed scores in the result.

Return value: Returns a Promise that resolves to an Models.ClassifyPageResult object containing the classification results.

API Reference: For a description of each field in the request and response, see the Classify a set of videos page.

Related guides:

Classify all the videos within an index

Description: This method classifies all the videos within a specific index based on the provided parameters and returns the first page of results.

Function signature and example:

1async index(
2 { conversationOption = 'semantic', ...restBody }: ClassifyIndexOptions,
3 options: RequestOptions = {},
4): Promise<Models.ClassifyPageResult>
5}

Parameters:

NameTypeRequiredDescription
paramsClassifyIndexOptionsYesParameters for classifying the videos.
optionsRequestOptionsNoAdditional options for the request. Defaults to {}.

The ClassifyIndexOptions interface defines the parameters for classifying a set of videos:

NameTypeRequiredDescription
indexIdstringYesThe unique identifier of the index containing the videos that you want to classify.

The following properties are inherited from the ClassifyOptions interface:

NameTypeRequiredDescription
options('visual' | 'conversation' | 'text_in_video')[]YesAn array that specifies the sources of information the platform uses when it categorizes a video.
classesArray<{ name: string; prompts: string[]; options?: ('visual' | 'conversation' | 'text_in_video')[]; conversationOption?: 'semantic' | 'exact_match' }>YesAn array of objects containing the names and the definitions of entities or actions that the platform must identify.
conversationOption'semantic' | 'exact_match'NoSpecifies the type of match the platform will perform.
pageLimitnumberNoThe maximum number of results per page.
includeClipsbooleanNoSet this parameter to true to retrieve detailed information about each matching video clip.
thresholdRecord<string, any>NoThresholds for different classification options.
showDetailedScorebooleanNoWhether to show detailed scores in the result.

Return value: Returns a Promise that resolves to an Models.ClassifyPageResult object containing the classification results.

API Reference: For a description of each field in the request and response, see the Classify all the videos within an index page.

Related guides:

Retrieve a specific page of results

Description: This method retrieves a specific page of results. This method provides direct pagination. Choose it mainly when the total number of items is manageable, or you must fetch a single page of results.

Function signature and example:

1async byPageToken(pageToken: string, options: RequestOptions = {}): Promise<Models.ClassifyPageResult>

Parameters:

NameTypeRequiredDescription
pageTokenstringYesA token that identifies the page to retrieve.
optionsRequestOptionsNoAdditional options for the request. Defaults to {}.

Return value: Returns a Promise that resolves to an Models.ClassifyPageResult object containing the classification results.

API Reference: For a description of each field in the request and response, see the Retrieve a specific page of results page.

Related guides:

Iterative pagination

If your application must retrieve a large number of items, use iterative pagination. To retrieve the first page of results, invoke the videos or index method of the classify object. To retrieve subsequent pages of results, use the async iterator protocol.

Node.js
1const CLASSES = [
2 {
3 name: 'DanceTok',
4 prompts: ['Dance tutorial', 'Dance group', 'Dance competition'],
5 },
6 {
7 name: 'CookTok',
8 prompts: ['Cooking tutorial', 'Cooking ustensils review'],
9 },
10];
11
12function printClassifyPageResult(result, pageNumber) {
13 console.log(`Page ${pageNumber}`);
14 console.log("Classification results:");
15 const data = result.data || result;
16 data.forEach(videoData => printClassifyVideoData(videoData));
17}
18
19function printClassifyVideoData(videoData) {
20 console.log(`Video ID: ${videoData.videoId}`);
21 videoData.classes.forEach(classData => printClassifyClass(classData));
22 console.log(); // Add a blank line between videos
23}
24
25function printClassifyClass(classData) {
26 console.log(` Class name: ${classData.name}`);
27 console.log(` Score: ${classData.score}`);
28 console.log(` Duration ratio: ${classData.durationRatio}`);
29 if (classData.clips && classData.clips.length > 0) {
30 console.log(" Clips:");
31 classData.clips.forEach(clip => printClassifyClip(clip));
32 }
33 if (classData.detailedScores) {
34 printClassifyDetailedScore(classData.detailedScores);
35 }
36}
37
38function printClassifyClip(clip) {
39 console.log(` Start: ${clip.start}`);
40 console.log(` End: ${clip.end}`);
41 console.log(` Score: ${clip.score}`);
42 console.log(` Option: ${clip.option}`);
43 console.log(` Prompt: ${clip.prompt}`);
44 console.log(` Thumbnail URL: ${clip.thumbnailUrl || 'N/A'}`);
45}
46
47function printClassifyDetailedScore(detailedScore) {
48 console.log(" Detailed scores:");
49 console.log(` Max score: ${detailedScore.maxScore}`);
50 console.log(` Avg score: ${detailedScore.avgScore}`);
51 console.log(` Normalized score: ${detailedScore.normalizedScore}`);
52}
53
54let classifyResults = await client.classify.index({
55 indexId: "<YOUR_INDEX_ID>",
56 options: ["visual"],
57 classes: CLASSES,
58 pageLimit: 2,
59 showDetailedScore: true,
60});
61
62let pageNumber = 1;
63printClassifyPageResult(classifyResults, pageNumber);
64
65while (true) {
66 const nextPage = await classifyResults.next();
67 if (nextPage === null) break;
68 pageNumber++;
69 printClassifyPageResult(nextPage, pageNumber);
70}
71
72console.log("No more results.");
73}
Built with