
Explore our guides and examples to integrate TwelveLabs
Easily build features like semantic search, anomaly detection, content recommenders and capabilities tailored to you. Our API unlocks your video’s full potential.
Try our API.
Get your API keys from the API Keys dashboard (see the authentication guide) and ensure the TwelveLabs SDK is installed on your computer:
pip install twelvelabs
yarn add twelvelabs-js # or npm install twelvelabs-js
You can copy and paste the code below to analyze videos and generate text based on their content. Replace the placeholders surrounded by <> with your values.
from twelvelabs import TwelveLabs
from twelvelabs.indexes import IndexesCreateRequestModelsItem
from twelvelabs.tasks import TasksRetrieveResponse
client = TwelveLabs(api_key="<YOUR_API_KEY>")
index = client.indexes.create(
index_name="<YOUR_INDEX_NAME>",
models=[
IndexesCreateRequestModelsItem(
model_name="pegasus1.2", model_options=["visual", "audio"]
)
]
)
print(f"Created index: id={index.id}")
task = client.tasks.create(
index_id=index.id, video_url="<YOUR_VIDEO_URL>")
print(f"Created task: id={task.id}")
def on_task_update(task: TasksRetrieveResponse):
print(f" Status={task.status}")
task = client.tasks.wait_for_done(task_id=task.id, callback=on_task_update)
if task.status != "ready":
raise RuntimeError(f"Indexing failed with status {task.status}")
print(
f"Upload complete. The unique identifier of your video is {task.video_id}.")
text_stream = client.analyze_stream(video_id=task.video_id, prompt="<YOUR_PROMPT>")
for text in text_stream:
if text.event_type == "text_generation":
print(text.text)
import { TwelveLabs, TwelvelabsApi } from "twelvelabs-js";
const client = new TwelveLabs({ apiKey: "<YOUR_API_KEY>" });
const index = await client.indexes.create({
indexName: "<YOUR_INDEX_NAME>",
models: [
{
modelName: "pegasus1.2",
modelOptions: ["visual", "audio"],
},
],
});
console.log(`Created index: id=${index.id}`);
const createTaskResponse = await client.tasks.create({
indexId: index.id!,
videoUrl: "<YOUR_VIDEO_URL>",
});
console.log(`Created task: id=${createTaskResponse.id}`);
const task = await client.tasks.waitForDone(createTaskResponse.id!, {
callback: (task: TwelvelabsApi.TasksRetrieveResponse) => {
console.log(` Status=${task.status}`);
},
});
if (task.status !== "ready") {
throw new Error(`Indexing failed with status ${task.status}`);
}
console.log(
`Upload complete. The unique identifier of your video is ${task.videoId}`,
);
const textStream = await client.analyzeStream({
videoId: task.videoId!,
prompt: "<YOUR_PROMPT>",
});
for await (const text of textStream) {
if ("text" in text) {
console.log(text.text!);
}
}
For more information, visit our Quickstart documentation or test in the Playground sandbox.
Get your API keys from the API Keys dashboard (see the authentication guide) and ensure the TwelveLabs SDK is installed on your computer:
pip install twelvelabs
yarn add twelvelabs-js # or npm install twelvelabs-js
You can copy and paste the code below to analyze videos and generate text based on their content. Replace the placeholders surrounded by <> with your values.
from typing import List
from twelvelabs import TwelveLabs
from twelvelabs.types import VideoSegment
from twelvelabs.embed import TasksStatusResponse
client = TwelveLabs(api_key="<YOUR_API_KEY>")
task = client.embed.tasks.create(
model_name="Marengo-retrieval-2.7", video_url="<YOUR_VIDEO_URL>")
print(f"Created video embedding task: id={task.id}")
def on_task_update(task: TasksStatusResponse):
print(f" Status={task.status}")
status = client.embed.tasks.wait_for_done(task.id, callback=on_task_update)
print(f"Embedding done: {status.status}")
task = client.embed.tasks.retrieve(
task_id=task.id, embedding_option=["visual-text", "audio"])
def print_segments(segments: List[VideoSegment], max_elements: int = 5):
for segment in segments:
print(f" embedding_scope={segment.embedding_scope} embedding_option={segment.embedding_option} start_offset_sec={segment.start_offset_sec} end_offset_sec={segment.end_offset_sec}")
first_few = segment.float_[:max_elements]
print(
f" embeddings: [{', '.join(str(x) for x in first_few)}...] (total: {len(segment.float_)} values)"
)
if task.video_embedding is not None and task.video_embedding.segments is not None:
print_segments(task.video_embedding.segments)
import { TwelveLabs, TwelvelabsApi } from "twelvelabs-js";
const client = new TwelveLabs({ apiKey: "<YOUR_API_KEY>" });
let task = await client.embed.tasks.create({
modelName: "Marengo-retrieval-2.7",
videoUrl: "<YOUR_VIDEO_URL>",
});
console.log(`Created video embedding task: id=${task.id}`);
const status = await client.embed.tasks.waitForDone(task.id!, {
callback: (task: TwelvelabsApi.embed.TasksStatusResponse) => {
console.log(` Status=${task.status}`);
},
});
console.log(`Embedding done: ${status.status}`);
const videoWithEmbeddings = await client.embed.tasks.retrieve(task.id!, {
embeddingOption: ["visual-text", "audio"],
});
const printSegments = (
segments: TwelvelabsApi.VideoSegment[],
maxElements = 5,
) => {
segments.forEach((segment) => {
const firstFew = segment.float?.slice(0, maxElements);
console.log(
`embeddingScope=${segment.embeddingScope} embeddingOption=${segment.embeddingOption} startOffsetSec=${segment.startOffsetSec} endOffsetSec=${segment.endOffsetSec}`,
);
console.log(
` embeddings: [${firstFew?.join(", ")}...] (total: ${
segment.float?.length
} values)`,
);
});
};
if (videoWithEmbeddings.videoEmbedding?.segments) {
printSegments(videoWithEmbeddings.videoEmbedding.segments);
}
from typing import List
from twelvelabs import TwelveLabs
from twelvelabs.types import BaseSegment
client = TwelveLabs(api_key="<YOUR_API_KEY>")
res = client.embed.create(
model_name="Marengo-retrieval-2.7",
text="<YOUR_TEXT>"
)
def print_segments(segments: List[BaseSegment], max_elements: int = 5):
for segment in segments:
first_few = segment.float_[:max_elements]
print(
f" embeddings: [{', '.join(str(x) for x in first_few)}...] (total: {len(segment.float_)} values)"
)
print("Created text embedding")
if res.text_embedding is not None and res.text_embedding.segments is not None:
print_segments(res.text_embedding.segments)
import { TwelveLabs, TwelvelabsApi } from "twelvelabs-js";
const client = new TwelveLabs({ apiKey: "<YOUR_API_KEY>" });
let res = await client.embed.create({
modelName: "Marengo-retrieval-2.7",
text: "<YOUR_TEXT>"
});
const printSegments = (segments: TwelvelabsApi.BaseSegment[], maxElements = 5) => {
segments.forEach((segment) => {
const first_few = segment.float?.slice(0, maxElements);
console.log(
` embeddings: [${first_few?.join(", ")}...] (total: ${
segment.float?.length
} values)`
);
});
};
console.log("Created text embedding");
if ("textEmbedding" in res && res.textEmbedding?.segments) {
printSegments(res.textEmbedding.segments);
}
from typing import List
from twelvelabs import TwelveLabs
from twelvelabs.types import BaseSegment
client = TwelveLabs(api_key="<YOUR_API_KEY>")
res = client.embed.create(
model_name="Marengo-retrieval-2.7",
image_url="<YOUR_IMAGE_URL>"
)
def print_segments(segments: List[BaseSegment], max_elements: int = 5):
for segment in segments:
first_few = segment.float_[:max_elements]
print(
f" embeddings: [{', '.join(str(x) for x in first_few)}...] (total: {len(segment.float_)} values)"
)
print(f"Created image embedding")
if res.image_embedding is not None and res.image_embedding.segments is not None:
print_segments(res.image_embedding.segments)
import { TwelveLabs, TwelvelabsApi } from "twelvelabs-js";
const client = new TwelveLabs({ apiKey: "<YOUR_API_KEY>" });
let res = await client.embed.create({
modelName: "Marengo-retrieval-2.7",
imageUrl: "<YOUR_IMAGE_URL>"
});
const printSegments = (segments: TwelvelabsApi.BaseSegment[], maxElements = 5) => {
segments.forEach((segment) => {
const first_few = segment.float?.slice(0, maxElements);
console.log(
` embeddings: [${first_few?.join(", ")}...] (total: ${
segment.float?.length
} values)`
);
});
};
console.log("Created image embedding");
if ("imageEmbedding" in res && res.imageEmbedding?.segments) {
printSegments(res.imageEmbedding.segments);
}
from typing import List
from twelvelabs import TwelveLabs
from twelvelabs.types import BaseSegment
client = TwelveLabs(api_key="<YOUR_API_KEY>")
res = client.embed.create(
model_name="Marengo-retrieval-2.7",
audio_url="<YOUR_AUDIO_URL>"
)
def print_segments(segments: List[BaseSegment], max_elements: int = 5):
for segment in segments:
first_few = segment.float_[:max_elements]
print(
f" embeddings: [{', '.join(str(x) for x in first_few)}...] (total: {len(segment.float_)} values)"
)
print(f"Created audio embedding")
if res.audio_embedding is not None and res.audio_embedding.segments is not None:
print_segments(res.audio_embedding.segments)
import { TwelveLabs, TwelvelabsApi } from "twelvelabs-js";
const client = new TwelveLabs({ apiKey: "<YOUR_API_KEY>" });
let res = await client.embed.create({
modelName: "Marengo-retrieval-2.7",
audioUrl: "<YOUR_AUDIO_URL>"
});
const printSegments = (segments: TwelvelabsApi.BaseSegment[], maxElements = 5) => {
segments.forEach((segment) => {
const first_few = segment.float?.slice(0, maxElements);
console.log(
` embeddings: [${first_few?.join(", ")}...] (total: ${
segment.float?.length
} values)`
);
});
};
console.log("Created audio embedding");
if ("audioEmbedding" in res && res.audioEmbedding?.segments) {
printSegments(res.audioEmbedding.segments);
}
For more information, visit our Quickstart documentation or test in the Playground sandbox.
Get your API keys from the API Keys dashboard (see the authentication guide) and ensure the TwelveLabs SDK is installed on your computer:
pip install twelvelabs
yarn add twelvelabs-js # or npm install twelvelabs-js
You can copy and paste the code below to analyze videos and generate text based on their content. Replace the placeholders surrounded by <> with your values.
from twelvelabs import TwelveLabs
from twelvelabs.indexes import IndexesCreateRequestModelsItem
from twelvelabs.tasks import TasksRetrieveResponse
client = TwelveLabs(api_key="<YOUR_API_KEY>")
index = client.indexes.create(
index_name="<YOUR_INDEX_NAME>",
models=[
IndexesCreateRequestModelsItem(
model_name="marengo2.7",
model_options=["visual", "audio"]
)
]
)
if index.id is None:
raise RuntimeError("Failed to create an index.")
print(f"Created index: id={index.id}")
task = client.tasks.create(
index_id=index.id, video_url="<YOUR_VIDEO_URL>")
print(f"Created task: id={task.id}")
def on_task_update(task: TasksRetrieveResponse):
print(f" Status={task.status}")
task = client.tasks.wait_for_done(task_id=task.id, callback=on_task_update)
if task.status != "ready":
raise RuntimeError(f"Indexing failed with status {task.status}")
print(
f"Upload complete. The unique identifier of your video is {task.video_id}.")
search_pager = client.search.query(
index_id=index.id, query_text="<YOUR_QUERY>", search_options=["visual", "audio"],)
print("Search results:")
for clip in search_pager:
print(
f" video_id {clip.video_id} score={clip.score} start={clip.start} end={clip.end} confidence={clip.confidence}"
)
import { TwelveLabs, TwelvelabsApi } from "twelvelabs-js";
const client = new TwelveLabs({ apiKey: "<YOUR_API_KEY>" });
const index = await client.indexes.create({
indexName: "<YOUR_INDEX_NAME>",
models: [
{
modelName: "marengo2.7",
modelOptions: ["visual", "audio"],
},
],
});
console.log(`Created index: id=${index.id}`);
const createTaskResponse = await client.tasks.create({
indexId: index.id!,
videoUrl:"<YOUR_VIDEO_URL>",
});
console.log(`Created task: id=${createTaskResponse.id}`);
const task = await client.tasks.waitForDone(createTaskResponse.id!, {
callback: (task: TwelvelabsApi.TasksRetrieveResponse) => {
console.log(` Status=${task.status}`);
},
});
if (task.status !== "ready") {
throw new Error(`Indexing failed with status ${task.status}`);
}
console.log(
`Upload complete. The unique identifier of your video is ${task.videoId}`,
);
let searchPager = await client.search.query({
indexId: index.id!,
queryText: "<YOUR_QUERY>",
searchOptions: ["visual", "audio"],
});
console.log("Search results:");
for await (const clip of searchPager) {
console.log(
` videoId=${clip.videoId} score=${clip.score} start=${clip.start} end=${clip.end} confidence=${clip.confidence}`,
);
}
For more information, visit our Quickstart documentation or test in the Playground sandbox.
Jump right in with a
Sample App…
Discover what TwelveLabs can do by experimenting with our fully functional sample applications.
See all sample appsWho talked about us
Use semantic search capabilities of the platform to identify the most suitable influencers to reach out to.
Try this exampleAnalyze social media posts for your videos
Simplify the cross-platform video promotion workflow by analyzing unique posts for each social media platform.
Try this exampleShade finder
This application uses the image-to-video search feature to find color shades in videos.
Try this exampleIntegrations
Expand the functionality and efficiency of TwelveLabs’ Video Understanding Platform with our partner integrations.

Semantic video search plugin
The plugin allows you to accurately identify movements, actions, objects, people, sounds, on-screen text, and speech

The TwelveLabs handler
This guide outlines how you can use the handler and how the handler interfaces with the Twelve Labs Video Understanding Platform.

Semantic video search
This integration combines Twelve Labs’ Embed API with MongoDB Atlas Vector Search to create an efficient semantic video search solution.
Browse by product
Explore documentation specific to each of our product offering.
Product overviewOur stable of models.
Learn more about TwelveLabs’ world-leading video foundation models.
Learn more
Marengo
Our breakthrough video foundation model analyzes frames and their temporal relationships, along with speech and sound — a huge leap forward for search and any-to-any retrieval tasks.

Pegasus
Our powerful video-first language model integrates visual, audio, and speech information — and employs this deep video understanding to reach new heights in text generation.



