Generate text from video

The Resources.Generate class provides methods to generate various types of text content from videos.

Topics, titles, and hashtags

Description: This method generates topics, titles, and hashtags for a specific video. It uses predefined formats and doesn't require a custom prompt, and it's best for generating immediate and straightforward text representations without specific customization.

Function signature and example:

async gist(
  videoId: string,
  types: GenerateGistType[],
  options: RequestOptions = {},
): Promise<Models.GenerateGistResult> 
const result = await client.generate.gist(
  "<YOUR_VIDEO_ID>",
  ["title", "topic", "hashtag"]
);

console.log("Result ID:", result.id);

if (result.title !== undefined) {
  console.log("Title:", result.title);
}

if (result.topics !== undefined) {
  console.log("Topics:");
  result.topics.forEach(topic => {
    console.log(`  - ${topic}`);
  });
}

if (result.hashtags !== undefined) {
  console.log("Hashtags:");
  result.hashtags.forEach(hashtag => {
    console.log(`  - ${hashtag}`);
  });
}

Parameters:

NameTypeRequiredDescription
videoIdstringYesThe unique identifier of the video for which you want to generate text.
typesGenerateGistType[]YesThe types of text you want to generate. Available values: topics, titles, hashtags.
optionsRequestOptionsNoAdditional options for the request. Defaults to {}.

Return value: Returns a Promise that resolves to a Models.GenerateGistResult instance.

API Reference: For a description of each field in the request and response, see the Generate topics, titles, and hashtags page.

Related guide: Titles, topics, and hashtags.

Summaries, chapters, and highlights

Description: This method generates summaries, chapters, or highlights for your videos. Optionally, you can provide a prompt to customize the output.

Function signature and example:

async summarize(
  videoId: string,
  type: GenerateSummarizeType,
  prompt?: string,
  temperature?: number,
  options: RequestOptions = {},
): Promise<Models.GenerateSummarizeResult>
const result = await client.generate.summarize(
  "<YOUR_VIDEO_ID>",
  "summary",
  "<YOUR_PROMPT>",
  0.7
  
)

console.log(`Result ID: ${result.id}`);

if (result.summary !== undefined) {
  console.log(`Summary: ${result.summary}`);
}

if (result.chapters !== undefined && result.chapters.length > 0) {
  console.log("Chapters:");
  result.chapters.forEach(chapter => {
    console.log(`  Chapter ${chapter.chapterNumber}:`);
    console.log(`    Start: ${chapter.start}`);
    console.log(`    End: ${chapter.end}`);
    console.log(`    Title: ${chapter.chapterTitle}`);
    console.log(`    Summary: ${chapter.chapterSummary}`);
  });
}

if (result.highlights !== undefined && result.highlights.length > 0) {
  console.log("Highlights:");
  result.highlights.forEach(highlight => {
    console.log(`  Start: ${highlight.start}`);
    console.log(`  End: ${highlight.end}`);
    console.log(`  Highlight: ${highlight.highlight}`);
  });
  }

Parameters:

NameTypeRequiredDescription
videoIdstringYesThe unique identifier of the video for which you want to generate text.
typestringYesThe type of text you want to generate. Available values: summaries, chapters, highlights.
promptstringNoThe prompt to customize the output.
temperaturenumberNoThe temperature to use in the generation.
optionsRequestOptionsNoAdditional options for the request. Defaults to {}.

Return value: Returns a Promise that resolves to a Models.GenerateSummarizeResult instance.

API Reference: For a description of each field in the request and response, see the Generate summaries, chapters, and highlights page.

Related guide: Summaries, chapters, and highlights.

Open-ended text

Description: This method generates open-ended texts based on your videos.

Function signature and example:

async text(
  videoId: string,
  prompt: string,
  temperature?: number,
  options: RequestOptions = {},
): Promise<Models.GenerateOpenEndedTextResult>
const result = await client.generate.text(
  "<YOUR_VIDEO_ID>",
  "Be concise"
  0.7,
);
console.log(`Result ID: ${result.id}`);
console.log(`Generated text: ${result.data}`);

Parameters:

NameTypeRequiredDescription
videoIdstringYesThe unique identifier of the video for which you want to generate text.
promptstringYesThe prompt to customize the output.
temperaturenumberNoThe temperature to use in the generation.
optionsRequestOptionsNoAdditional options for the request. Defaults to {}.

Return value: Returns a Promise that resolves to a Models.GenerateOpenEndedTextResult instance.

API Reference: For a description of each field in the request and response, see the Open-ended text page.

Related guide: Open-ended text .

Open-ended text with streaming responses

Description: This method generates open-ended texts and supports streaming responses.

Function signature and example:

async textStream(
  { videoId, prompt, temperature }: GenerateTextStreamParams,
  options: RequestOptions = {},
): Promise<Models.GenerateTextStreamResult>
  const textStream = await client.generate.textStream({
    videoId: "<YOUR_VIDEO_ID>",
    prompt: '<YOUR_PROMPT>',
    temperature: 0.7
  });

  for await (const text of textStream) {
    console.log(text);
  }

  console.log(`Aggregated text: ${textStream.aggregatedText}`);
})();

Parameters:

NameTypeRequiredDescription
paramsGenerateTextStreamParamsYesParameters for generating open-ended text.
optionsRequestOptionsNoAdditional options for the request. Defaults to {}.

The GenerateTextStreamParams interface defines the parameters for streaming text generated based on video content:

NameTypeRequiredDescription
videoIdstringYesThe unique identifier of the video for which you want to generate text.
promptstringYesThe prompt to customize the output.
temperaturenumberNoThe temperature to use in the generation.

API Reference: For a description of each field in the request and response, see the Open-ended text page.

Related guide: Streaming responses .