Amazon Bedrock
This guide shows you how to use TwelveLabs models on Amazon Bedrock to perform the following tasks:
- Analyze videos and generate text based on their content.
- Create embeddings from video, text, audio, or image inputs.
TwelveLabs provides the following models on Amazon Bedrock:
The table below shows the specifications for each type of embedding:
For more information, see the TwelveLabs in Amazon Bedrock product page. For details on pricing, see the Amazon Bedrock pricing page.
Note
We are currently experiencing a temporary latency issue with text and image embedding. The latency for API calls ranges from 30 to 60 seconds. We are working with Amazon Bedrock to reduce this latency to a few seconds. We expect to complete this update by Friday, August 8, 2025.
Prerequisites
Before you start, ensure you have the following:
- An AWS account with access to a region where the TwelveLabs models are supported.
- An AWS IAM principal with sufficient Amazon Bedrock permissions. For details on setting permissions, see the Identity and access management for Amazon Bedrock page.
- S3 permissions to read input files and write output files for Marengo operations.
- The AWS CLI and configured with your credentials.
- Python 3.7 or later with the
boto3
library. - Access to the model you want to use. Navigate to the AWS Console > Bedrock > Model Access page and request access. Note that the availability of the models varies by region.
Media input methods
Both TwelveLabs models support base64 encoded strings and S3 URIs for media input. Note that the base64 method has a 36MB file size limit. This guide uses S3 URIs.
Note
Your S3 bucket and the model must be in the same region. If the regions don’t match, you will receive a ValidationException
error.
S3 output requirements for Marengo
Marengo uses the StartAsyncInvoke
API and requires an S3 location for storing results. Each invocation creates a unique directory with two files:
manifest.json
: Contains metadata including the request ID.output.json
: Contains the actual embeddings.
Examples
The sections below provide examples of using the TwelveLabs models on Amazon Bedrock.
Analyze videos
The example code below shows how you can use Pegasus to analyze videos and generate text based on their content. Ensure you replace the following placeholders with your values:
<YOUR_REGION>
: with your region (example: “eu-west-1”).<YOUR_ACCOUNT_ID>
: with your AWS account ID (example: “123456789012”).<YOUR_BUCKET_NAME>
: with the name of your S3 bucket (example: “my-video-bucket”).<YOUR_VIDEO_FILE>
: with the name of your video file (example: “my_video.mp4”).<YOUR_PROMPT>
: with a string that guides the model on the desired format or content (example: “Summarize this video”).
Create embeddings from video, audio, or image inputs
The example code below shows how you can use Marengo to create embeddings from video, audio, or image inputs. Marengo uses the StartAsyncInvoke
API, which means you must:
- Submit your request, providing an S3 location for your input media file and an S3 location for the output. Note that this example uses the same bucket.
- Wait for the job to complete.
- Retrieve the results from the S3 output location.
Ensure you replace the following placeholders with your values:
<YOUR_REGION>
: with your AWS region (example: “eu-west-1”)<YOUR_ACCOUNT_ID>
: with your AWS account ID (example: “123456789012”)<YOUR_BUCKET_NAME>
: with the name of your S3 bucket (example: “my-bucket”)<YOUR_VIDEO_FILE>
: with the name of your video file (example: “my_file.mp4”)<YOUR_INPUT_TYPE>
: with the type of media you wish to provide. The following values are supported: “video”, “audio”, or “image”.
Create embeddings from text inputs
The example code below shows how you can use Marengo to create embeddings from text inputs. Marengo uses the StartAsyncInvoke
API, which means you must:
- Submit your request, providing an S3 location for the output.
- Wait for the job to complete.
- Retrieve the results from the S3 output location.
Ensure you replace the following placeholders with your values:
<YOUR_REGION>
: with your AWS region (example: “eu-west-1”).<YOUR_ACCOUNT_ID>
: with your AWS account ID (example: “123456789012”).<YOUR_BUCKET_NAME>
: with your S3 bucket name (example: “my-bucket”).<YOUR_TEXT>
: with the text for which you wish to create an embedding (example: “A man walking down the street”).
Request parameters and response fields
For a complete list of request parameters and response fields, see the following pages in the Amazon Bedrock documentation: