> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.twelvelabs.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.twelvelabs.io/_mcp/server.

# Image embeddings

> Create embeddings for an image file asynchronously.

This guide shows how you can create image embeddings using the Marengo 3.5 video understanding model. For complete specifications and input requirements, see the [Marengo 3.5](/v1.3/docs/concepts/models/marengo/marengo-3-5) page.

The Marengo video understanding model generates embeddings for all modalities in the same latent space. This shared space enables any-to-any searches across different types of content.

For details on how your usage is measured and billed, see the [Pricing](https://www.twelvelabs.io/pricing) page.

# Key concepts

This section explains the key concepts and terminology used in this guide:

* **Asset**: Your uploaded content. Once created, you can reference the same asset across multiple operations without uploading the file again.
* **Embedding**: Vector representation of your content.
* **Embedding task**: An asynchronous operation for processing your content and creating embeddings. Contains a status and the resulting embeddings when complete.

# Workflow

This guide shows how to create one embedding for an image file, so your queries can match its content. The example uploads the image as an asset. You can also pass a URL or base64-encoded data inline instead of creating an asset; both are shown as commented-out lines in the code examples.

The platform processes your files asynchronously, one file per request. This example embeds one image; repeat the request for each file in your collection.

For an image, the type of embedding, the output format, and the scope fields each accept a single value. You can request a per-dimension uncertainty vector.

To combine an image with text or with other media in a single embedding, see the [Embed a query](/v1.3/docs/guides/create-embeddings/query) guide.

Use these embeddings for similarity search, content classification, clustering, recommendations, or Retrieval-Augmented Generation (RAG).

> **Retention policy**
>
> Embeddings created with the asynchronous method are stored for seven days. After this, you must recreate them to obtain the results again.

# Prerequisites

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

  If you don't have an account, [sign up](https://playground.twelvelabs.io/) for a free account.

  Go to the [API Keys](https://playground.twelvelabs.io/dashboard/api-keys) page.

  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.

  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:

  **`Python`**

  ```shell Python
  pip install --upgrade twelvelabs
  ```

  **`Node.js`**

  ```shell Node.js
  yarn add twelvelabs-js@latest # or npm install twelvelabs-js@latest
  ```

* Your images must meet the following requirements:
  * **Upload limits**: Images up to 32 MB.

  * **Model capabilities**: See the complete [input requirements](/v1.3/docs/concepts/models/marengo/marengo-3-5#input-requirements) for Marengo 3.5.

# Complete example

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

**`Python`**

```Python Python maxLines=12
import time
from twelvelabs import TwelveLabs, AsyncImageInputRequest, MediaSource

# 1. Initialize the client
client = TwelveLabs(api_key="<YOUR_API_KEY>")

# 2. Upload an image
asset = client.assets.create(
    method="url",
    url="<YOUR_IMAGE_URL>" # Use direct links to raw media files. Video hosting platforms and cloud storage sharing links are not supported
    # Or use method="direct" and file=open("<PATH_TO_IMAGE_FILE>", "rb") to upload a local file up to 32 MB
)
print(f"Created asset: id={asset.id}")

# 3. Check the status of the asset
print("Waiting for asset to be ready...")
while True:
    asset = client.assets.retrieve(asset.id)
    if asset.status == "ready":
        print("Asset is ready")
        break
    if asset.status == "failed":
        raise RuntimeError(f"Asset processing failed: id={asset.id}")
    time.sleep(5)

# 4. Create an embedding task
task = client.embed.v_2.tasks.create(
    input_type="image",
    model_name="marengo3.5",
    image=AsyncImageInputRequest(
        media_source=MediaSource(
            asset_id=asset.id,
            # url="<YOUR_IMAGE_URL>", # Use direct links to raw media files. Video hosting platforms and cloud storage sharing links are not supported
            # base_64_string="<BASE_64_ENCODED_DATA>",
        ),
    ),
    # embedding_uncertainty=True,
    # embedding_dimension=512,
)
print(f"Task ID: {task.id}")

# 5. Monitor the status
while True:
    task = client.embed.v_2.tasks.retrieve(task_id=task.id)
    if task.status == "ready":
        print("Task completed")
        break
    elif task.status == "failed":
        print("Task failed")
        break
    else:
        print("Task still processing...")
        time.sleep(5)

# 6. Process the results
print(f"Number of embeddings: {len(task.data)}")
if task.metadata is not None and task.metadata.embedding_dimension is not None:
    print(f"Embedding dimensions (metadata.embedding_dimension): {task.metadata.embedding_dimension}")
for embedding_data in task.data:
    print(f"Embedding dimensions: {len(embedding_data.embedding)}")
    print(f"First 10 values: {embedding_data.embedding[:10]}")
    if embedding_data.embedding_uncertainty is not None:
        print(f"First 10 uncertainty values: {embedding_data.embedding_uncertainty[:10]}")
```

**`Node.js`**

```JavaScript Node.js maxLines=12
import { TwelveLabs } from "twelvelabs-js";
// Uncomment the next line if uploading a local file
// import fs from "fs";

// 1. Initialize the client
const client = new TwelveLabs({ apiKey: "<YOUR_API_KEY>" });

// 2. Upload an image
const asset = await client.assets.create({
  method: "url",
  url: "<YOUR_IMAGE_URL>", // Use direct links to raw media files. Video hosting platforms and cloud storage sharing links are not supported
  // Or use method: "direct" and file: fs.createReadStream("<PATH_TO_IMAGE_FILE>") to upload a local file up to 32 MB
});
console.log(`Created asset: id=${asset.id}`);

// 3. Check the status of the asset
console.log("Waiting for asset to be ready...");
let readyAsset = await client.assets.retrieve(asset.id);
while (readyAsset.status !== "ready" && readyAsset.status !== "failed") {
  await new Promise((resolve) => setTimeout(resolve, 5000));
  readyAsset = await client.assets.retrieve(asset.id);
}
if (readyAsset.status === "failed") {
  throw new Error(`Asset processing failed: id=${asset.id}`);
}
console.log("Asset is ready");

// 4. Create an embedding task
let task = await client.embed.v2.tasks.create({
    inputType: "image",
    modelName: "marengo3.5",
    image: {
        mediaSource: {
            assetId: asset.id,
            // url: "<YOUR_IMAGE_URL>", // Use direct links to raw media files. Video hosting platforms and cloud storage sharing links are not supported
            // base64String: "<BASE_64_ENCODED_DATA>",
        },
    },
    // embeddingUncertainty: true,
    // embeddingDimension: 512,
});
console.log(`Task ID: ${task.id}`);

// 5. Monitor the status
while (true) {
    task = await client.embed.v2.tasks.retrieve(task.id);
    if (task.status === "ready") {
        console.log("Task completed");
        break;
    } else if (task.status === "failed") {
        console.log("Task failed");
        break;
    } else {
        console.log("Task still processing...");
        await new Promise(resolve => setTimeout(resolve, 5000));
    }
}

// 6. Process the results
console.log(`Number of embeddings: ${task.data.length}`);
if (task.metadata?.embeddingDimension != null) {
    console.log(`Embedding dimensions (metadata.embeddingDimension): ${task.metadata.embeddingDimension}`);
}
for (const embeddingData of task.data) {
    console.log(`Embedding dimensions: ${embeddingData.embedding.length}`);
    console.log(`First 10 values: ${embeddingData.embedding.slice(0, 10)}`);
    if (embeddingData.embeddingUncertainty != null) {
        console.log(`First 10 uncertainty values: ${embeddingData.embeddingUncertainty.slice(0, 10)}`);
    }
}
```

# Code explanation

#### Python

#### Import the SDK and initialize the client

Create a client instance to interact with the TwelveLabs Video Understanding Platform.\

**Function call**: You call the [constructor](/v1.3/sdk-reference/python/the-twelve-labs-class#the-initializer) of the `TwelveLabs` class.\

**Parameters**:

* `api_key`: The API key to authenticate your requests to the platform.\


**Return value**: An object of type `TwelveLabs` configured for making API calls.

#### Upload an image

Upload an image file to create an asset.\

**Function call**: You call the [`assets.create`](/v1.3/sdk-reference/python/upload-content/direct-uploads#create-an-asset) function.\

**Parameters**:

* `method`: The upload method for your asset. Use `url` for a publicly accessible or `direct` to upload a local file. This example uses `url`.
* `url` or `file`: The publicly accessible URL of your image file or an opened file object in binary read mode. This example uses `url`.

**Return value**: An object of type `Asset`. This object contains, among other information, a field named `id` representing the unique identifier of your asset.

#### Check the status of the asset

Asset processing is asynchronous. Poll the status of the asset until it is `ready` before you use it.\

**Function call**: You call the [`assets.retrieve`](/v1.3/sdk-reference/python/manage-assets#retrieve-an-asset) function.\

**Parameters**:

* `asset_id`: The unique identifier of your asset.\


**Return value**: An object of type `Asset` containing, among other information, a field named `status` representing the current status of the asset. Check this field until its value is `ready`.

#### Create an embedding task

Create an embedding task to start processing your image.\

**Function call**: You call the [`embed.v_2.tasks.create`](/v1.3/sdk-reference/python/create-embeddings-v-2/create-async-embeddings#create-an-async-embedding-task) function.\

**Parameters**:

* `input_type`: The type of content. Set this parameter to `image`.
* `model_name`: The embedding model to use. This example uses `marengo3.5`.
* *(Optional)* `embedding_uncertainty`: Set this parameter to `true` to receive a `data[].embedding_uncertainty` field in the response. This field is a per-dimension uncertainty vector with the same length as the `embedding` array. A higher value shows lower confidence in that dimension.
* *(Optional)* `embedding_dimension`: The number of dimensions of the embedding: `128`, `256`, or `512`. The default is `512`. Applies to the whole task. To embed the same content at a different length, create a second task.
* `image`: An object containing the following properties:
  * `media_source`: An object specifying the source of the image file. Specify one of the following:
    * `asset_id`: The unique identifier of an asset from a previous upload.
    * `url`: The publicly accessible URL of the image file.
    * `base_64_string`: The base64-encoded image data.

      This example uses the identifier of the asset created in the previous step.

**Return value**: An object of type `TasksCreateResponse` containing, among other information, a field named `id`, which represents the unique identifier of your embedding task. You can use this identifier to track the status of your embedding task. The object also includes a `metadata.embedding_dimension` field, which contains the number of dimensions of the embeddings this task returns.

#### Monitor the status

The platform requires some time to process images. Poll the status of the embedding task until it is `ready`. This example uses a loop to check the status every 5 seconds.\

**Function call**: You repeatedly call the [`embed.v_2.tasks.retrieve`](/v1.3/sdk-reference/python/create-embeddings-v-2/create-async-embeddings#retrieve-task-status-and-results) function until the task completes.\


**Parameters**:

* `task_id`: The unique identifier of your embedding task.\


**Return value**: An object of type `EmbeddingTaskResponse` containing, among other information, the following fields:

* `status`: The current status of the task. The possible values are:
  * `processing`: The platform is creating the embeddings.
  * `ready`: Processing is complete. Embeddings are available in the `data` field.
  * `failed`: The task failed.
* `data`: When the status is `ready`, this field contains a list with one embedding object. The embedding object includes:
  * `embedding`: The embedding vector (a list of floats).
  * `embedding_uncertainty`: A per-dimension uncertainty vector with the same length as the `embedding` array. A higher value shows lower confidence in that dimension. Present when the request sets `embedding_uncertainty` to `true`.
  * `embedding_option`: The type of embedding. For an image, this field is `visual`.
  * `embedding_scope`: The scope of the embedding. For an image, this field is `asset`.
* `metadata.embedding_dimension`: The number of dimensions of the embeddings this task returns. Only Marengo 3.5.

#### Process the results

This example prints the number of embeddings, the dimensions and first 10 vector values of the embedding, and the conditional fields from the previous step when present.

#### Node.js

#### Import the SDK and initialize the client

Create a client instance to interact with the TwelveLabs Video Understanding Platform.\

**Function call**: You call the [constructor](/v1.3/sdk-reference/node-js/the-twelve-labs-class#the-constructor) of the `TwelveLabs` class.\

**Parameters**: You pass all parameters as properties of a single object.

* `apiKey`: The API key to authenticate your requests to the platform.\


**Return value**: An object of type `TwelveLabs` configured for making API calls.

#### Upload an image file

Upload an image file to create an asset.\

**Function call**: You call the [`assets.create`](/v1.3/sdk-reference/node-js/upload-content/direct-uploads#create-an-asset) function.\

**Parameters**: You pass all parameters as properties of a single object.

* `method`: The upload method for your asset. Use `url` for a publicly accessible or `direct` to upload a local file. This example uses `url`.
* `url` or `file`: The publicly accessible URL of your image file or an opened file object in binary read mode. This example uses `url`.

**Return value**: An `HttpResponsePromise` that resolves to an object of type `Asset`. This object contains, among other information, a field named `id` representing the unique identifier of your asset.

#### Check the status of the asset

Asset processing is asynchronous. Poll the status of the asset until it is `ready` before you use it.\

**Function call**: You call the [`assets.retrieve`](/v1.3/sdk-reference/node-js/manage-assets#retrieve-an-asset) function.\

**Parameters**: You pass the parameter as a positional argument.

* `assetId`: The unique identifier of your asset.\


**Return value**: An `HttpResponsePromise` that resolves to an object of type `Asset` containing, among other information, a field named `status` representing the current status of the asset. Check this field until its value is `ready`.

#### Create an embedding task

Create an embedding task to start processing your image.\

**Function call**: You call the [`embed.v2.tasks.create`](/v1.3/sdk-reference/node-js/create-embeddings-v-2/create-async-embeddings) function.\

**Parameters**:

* `inputType`: The type of content. Set this parameter to `image`.
* `modelName`: The embedding model to use. This example uses `marengo3.5`.
* *(Optional)* `embeddingUncertainty`: Set this parameter to `true` to receive a `data[].embeddingUncertainty` field in the response. This field is a per-dimension uncertainty vector with the same length as the `embedding` array. A higher value shows lower confidence in that dimension.
* *(Optional)* `embeddingDimension`: The number of dimensions of the embedding: `128`, `256`, or `512`. The default is `512`. Applies to the whole task. To embed the same content at a different length, create a second task.
* `image`: An object containing the following properties:
  * `mediaSource`: An object specifying the source of the image file. Specify one of the following:
    * `assetId`: The unique identifier of an asset from a previous upload.
    * `url`: The publicly accessible URL of the image file.
    * `base64String`: The base64-encoded image data.

      This example uses the identifier of the asset created in the previous step.

**Return value**: An object of type `TasksCreateResponse` containing, among other information, a field named `id`, which represents the unique identifier of your embedding task. You can use this identifier to track the status of your embedding task. The object also includes a `metadata.embedding_dimension` field, which contains the number of dimensions of the embeddings this task returns.

#### Monitor the status

The platform requires some time to process images. Poll the status of the embedding task until it is `ready`. This example uses a loop to check the status every 5 seconds.\

**Function call**: You repeatedly call the [`embed.v2.tasks.retrieve`](/v1.3/sdk-reference/node-js/create-embeddings-v-2/create-async-embeddings#retrieve-task-status-and-results) function until the task completes.\


**Parameters**:

* `taskId`: The unique identifier of your embedding task.\


**Return value**: An object of type `EmbeddingTaskResponse` containing, among other information, the following fields:

* `status`: The current status of the task. The possible values are:
  * `processing`: The platform is creating the embeddings.
  * `ready`: Processing is complete. Embeddings are available in the `data` field.
  * `failed`: The task failed.
* `data`: When the status is `ready`, this field contains a list with one embedding object. The embedding object includes:
  * `embedding`: The embedding vector (a list of floats).
  * `embeddingUncertainty`: A per-dimension uncertainty vector with the same length as the `embedding` array. A higher value shows lower confidence in that dimension. Present when the request sets `embeddingUncertainty` to `true`.
  * `embeddingOption`: The type of embedding. For an image, this field is `visual`.
  * `embeddingScope`: The scope of the embedding. For an image, this field is `asset`.
* `metadata.embeddingDimension`: The number of dimensions of the embeddings this task returns. Only Marengo 3.5.

#### Process the results

This example prints the number of embeddings, the dimensions and first 10 vector values of the embedding, and the conditional fields from the previous step when present.