Upload content

This guide shows you how to upload video and image content to the platform as an asset. The platform supports the following upload methods:

  • Direct uploads: Upload local files (up to 200 MB) or provide a public URL (up to 4 GB). Use direct links to raw media files. The platform does not support video hosting platforms or cloud storage sharing links.
  • Multipart uploads: Upload local video files up to 5 GB. Use multipart uploads for automatic retries, progress tracking, and improved reliability.
Note

The platform accepts uploads up to 10 GB, but knowledge stores have a 5 GB limit. Files that exceed this limit fail when you add them to a knowledge store.

Key concepts

  • Asset: Your uploaded content. Once created, you can reference the same asset across multiple operations without uploading the file again.

Prerequisites

  • To use the platform, you need an API key:

    1

    If you don’t have an account, sign up for a free account.

    2

    Go to the API Keys page.

    3

    If you need to create a new key, select the Create API Key button. Enter a name and set the expiration period. The default is 12 months.

    4

    Select the Copy icon next to your key to copy it to your clipboard.

  • Depending on the programming language you are using, install the TwelveLabs SDK by entering one of the following commands:

    $pip install twelvelabs

Direct uploads

Direct uploads create an asset from a local file or a publicly accessible URL in a single request.

Example

Copy and paste the code below, replacing the placeholders surrounded by <> with your values.

1from twelvelabs import TwelveLabs
2import time
3
4client = TwelveLabs(api_key="<YOUR_API_KEY>")
5
6# Step 1: Upload the file
7asset = client.assets.create(method="direct", file=open("<YOUR_FILE_PATH>", "rb"))
8print(f"Asset created: {asset.id}, Status: {asset.status}, File type: {asset.file_type}")
9
10# Step 2: Check the status of the asset
11while True:
12 status = client.assets.retrieve(asset_id=asset.id).status
13 if status == "ready":
14 break
15 elif status == "failed":
16 raise Exception("Asset processing failed")
17 print(f"Status: {status}, waiting...")
18 time.sleep(5)
19print("Asset ready")

Code explanation

1

Upload the file

Upload a video or an image from a local file or a publicly accessible URL to create an asset. This example prints the asset identifier, status, and file type to the standard output.

Function call: You call the assets.create method.
Parameters:

  • method: The upload method. Set to direct for a local file.
  • file: The local file to upload, opened in binary read mode. Maximum size: 200 MB for video and audio, 32 MB for images.

Return value: An object of type Asset containing, among other information, a field named id representing the unique identifier of the newly created asset, a field named status representing its current state, and a field named file_type containing the MIME type the platform detected, such as video/mp4 or image/jpeg.

2

Check the status of the asset

Poll the asset until it reaches the ready status. This example checks every 5 seconds. An asset must reach ready before you can add it to a knowledge store.
Function call: You call the assets.retrieve method.
Parameters:

  • asset_id: The unique identifier of the asset, from the previous step.

Return value: An object of type Asset. Check the status field for the current state. The possible values are processing, ready, and failed.

Multipart uploads

Use multipart uploads for local files larger than 200 MB, up to 5 GB.

Example

Copy and paste the code below, replacing the placeholders surrounded by <> with your values.

1from twelvelabs import TwelveLabs
2import time
3
4client = TwelveLabs(api_key="<YOUR_API_KEY>")
5
6# Step 1: Upload the file
7def progress_callback(progress):
8 print(f"Progress: {progress.percentage:.1f}% "
9 f"({progress.completed_chunks}/{progress.total_chunks} chunks)")
10
11result = client.multipart_upload.upload_file(
12 "<YOUR_FILE_PATH>",
13 progress_callback=progress_callback,
14)
15print(f"Asset created: {result.asset_id}")
16
17# Step 2: Check the status of the asset
18while True:
19 status = client.assets.retrieve(asset_id=result.asset_id).status
20 if status == "ready":
21 break
22 elif status == "failed":
23 raise Exception("Asset processing failed")
24 print(f"Status: {status}, waiting...")
25 time.sleep(5)
26print("Asset ready")

Code explanation

1

Upload the file

Upload a local file to create an asset. The SDK sets up the upload session, splits the file into chunks, uploads them in parallel with automatic retries, and reports completion. This example prints the progress and the asset identifier to the standard output.
Function call: You call the multipart_upload.upload_file method.
Parameters:

  • file_path: The path to the local file to upload. Maximum size: 5 GB.
  • (Optional) progress_callback: A function the SDK calls with progress updates during the upload.

Return value: An object of type UploadResult with a field named asset_id representing the unique identifier of the asset. For lower-level control over the individual steps, see the Multipart uploads API reference.

2

Check the status of the asset

Poll the asset until it reaches the ready status. This example checks every 5 seconds. An asset must reach ready before you can add it to a knowledge store.
Function call: You call the assets.retrieve method.
Parameters:

  • asset_id: The unique identifier of the asset, from the previous step.

Return value: An object of type Asset. Check the status field for the current state. The possible values are processing, ready, and failed.

Next steps

Jupyter notebooks

The notebooks below provide complete, executable code. Hosted on Google Colab, they allow you to run the code directly and adapt it to your own content.

NotebookDescriptionTry it
Uploading contentUpload a single video or image, wait for processing, and generate an HLS playlist or thumbnails.Open In Colab
Uploading multiple filesUpload a folder of videos and images, add them to a knowledge store, and handle rate limits and partial failures.Open In Colab