> ## Documentation Index
> Fetch the complete documentation index at: https://portkey-docs-feat-rerank-documentation.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Embeddings

> Get embeddings from Bedrock

Bedrock supports embedding text and images through Amazon Titan and Cohere models.
Portkey provides a standardized interface for embedding multiple modalities.

# Bedrock Titan

## Embedding Text

<CodeGroup>
  ```python Python theme={"system"}
  from portkey_ai import Portkey

  client = Portkey(
      api_key="YOUR_PORTKEY_API_KEY", # defaults to os.environ.get("PORTKEY_API_KEY")
      provider="@PROVIDER",
  )

  embeddings = client.embeddings.create(
      model="amazon.titan-embed-text-v2:0",
      input="Hello this is a test",
      # normalize=False # if you would like to disable normalization
      # dimensions=1024, # embedding dimensions
      # encoding_format="float", # embedding format
  )
  ```

  ```javascript NodeJS theme={"system"}
  import { Portkey } from 'portkey-ai';

  const portkey = new Portkey({
      apiKey: "YOUR_API_KEY",
      provider:"@YOUR_PROVIDER"
  });

  const embedding = await portkey.embeddings.create({
      model: "amazon.titan-embed-text-v2:0",
      input: "Hello this is a test",
      // normalize: false, // if you would like to disable normalization
      // dimensions: 1024, // embedding dimensions
      // encoding_format: "float", // embedding format
  });

  console.log(embedding);
  ```

  ```sh cURL theme={"system"}
  curl --location 'https://api.portkey.ai/v1/embeddings' \
  --header 'Content-Type: application/json' \
  --header 'x-portkey-api-key: PORTKEY_API_KEY' \
  --header 'x-portkey-provider: PORTKEY_PROVIDER' \
  --data-raw '{
      "model": "amazon.titan-embed-text-v2:0",
      "input": "Hello this is a test",
      "normalize": false, // if you would like to disable normalization
      "dimensions": 1024, // embedding dimensions
      "encoding_format": "float" // embedding format
  }'
  ```

  ```python OpenAI Python theme={"system"}
  from openai import OpenAI
  from portkey_ai import PORTKEY_GATEWAY_URL, createHeaders

  portkey_client = OpenAI(
      api_key='NOT_REQUIRED',
      base_url=PORTKEY_GATEWAY_URL,
      default_headers=createHeaders(
          provider="openai",
          api_key="PORTKEY_API_KEY"
      )
  )

  embeddings = portkey_client.embeddings.create(
      model="amazon.titan-embed-text-v2:0",
      input="Hello this is a test",
      # normalize=False # if you would like to disable normalization
      # dimensions=1024, # embedding dimensions
      # encoding_format="float", # embedding format
  )
  ```

  ```js OpenAI NodeJS theme={"system"}
  import OpenAI from 'openai'; // We're using the v4 SDK
  import { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai'

  const portkeyClient = new OpenAI({
    apiKey: 'NOT_REQUIRED', // defaults to process.env["OPENAI_API_KEY"],
    baseURL: PORTKEY_GATEWAY_URL,
    defaultHeaders: createHeaders({
      provider: "vertex-ai",
      apiKey: "PORTKEY_API_KEY", // defaults to process.env["PORTKEY_API_KEY"]
      provider:"@PORTKEY_PROVIDER"
    })
  });

  const embedding = await portkeyClient.embeddings.create({
      model: "amazon.titan-embed-text-v2:0",
      input: "Hello this is a test",
      // normalize=False, // if you would like to disable normalization
      // dimensions=1024, // embedding dimensions
      // encoding_format="float", // embedding format
  });

  console.log(embedding);
  ```
</CodeGroup>

## Embeddings Images

<CodeGroup>
  ```python Python theme={"system"}
  from portkey_ai import Portkey

  client = Portkey(
      api_key="YOUR_PORTKEY_API_KEY", # defaults to os.environ.get("PORTKEY_API_KEY")
      provider="@PROVIDER",
  )

  embeddings = client.embeddings.create(
      model="amazon.titan-embed-image-v1",
      dimensions=256,
      input=[
      {
          "text": "this is the caption of the image",
          "image": {
              "base64": "UklGRkacAABXRUJQVlA4IDqcAACQggKdASqpAn8B....."
          }
      }
  ]
  )
  ```

  ```javascript NodeJS theme={"system"}
  import { Portkey } from 'portkey-ai';

  const portkey = new Portkey({
      apiKey: "YOUR_API_KEY",
      provider:"@YOUR_PROVIDER"
  });

  const embedding = await portkey.embeddings.create({
      model: "amazon.titan-embed-image-v1",
      dimensions: 256,
      input: [
      {
          "text": "this is the caption of the image",
          "image": {
              "base64": "UklGRkacAABXRUJQVlA4IDqcAACQggKdASqpAn8B....."
          }
      }
  ]
  });

  console.log(embedding);
  ```

  ```sh cURL theme={"system"}
  curl --location 'https://api.portkey.ai/v1/embeddings' \
  --header 'Content-Type: application/json' \
  --header 'x-portkey-api-key: PORTKEY_API_KEY' \
  --header 'x-portkey-provider: PORTKEY_PROVIDER' \
  --data-raw '{
  "model": "amazon.titan-embed-image-v1",
  "dimensions": 256,
  "input": [
      {
          "text": "this is the caption of the image",
          "image": {
              "base64": "UklGRkacAABXRUJQVlA4IDqcAACQggKdASqpAn8B....."
          }
      }
  ]
  }'
  ```

  ```python OpenAI Python theme={"system"}
  from openai import OpenAI
  from portkey_ai import PORTKEY_GATEWAY_URL, createHeaders

  portkey_client = OpenAI(
      api_key='NOT_REQUIRED',
      base_url=PORTKEY_GATEWAY_URL,
      default_headers=createHeaders(
          provider="openai",
          api_key="PORTKEY_API_KEY"
      )
  )

  embeddings = portkey_client.embeddings.create(
      model="amazon.titan-embed-image-v1",
      dimensions=256,
      input=[
      {
          "text": "this is the caption of the image",
          "image": {
              "base64": "UklGRkacAABXRUJQVlA4IDqcAACQggKdASqpAn8B....."
          }
      }
      ]
  )
  ```

  ```js OpenAI NodeJS theme={"system"}
  import OpenAI from 'openai'; // We're using the v4 SDK
  import { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai'

  const portkeyClient = new OpenAI({
    apiKey: 'NOT_REQUIRED', // defaults to process.env["OPENAI_API_KEY"],
    baseURL: PORTKEY_GATEWAY_URL,
    defaultHeaders: createHeaders({
      apiKey: "PORTKEY_API_KEY", // defaults to process.env["PORTKEY_API_KEY"]
      provider:"@PORTKEY_PROVIDER"
    })
  });

  const embedding = await portkeyClient.embeddings.create({
      model: "amazon.titan-embed-image-v1",
      dimensions: 256,
      input: [
      {
          text: "this is the caption of the image",
          image: {
              base64: "UklGRkacAABXRUJQVlA4IDqcAACQggKdASqpAn8B....."
          }
      }
      ]
  });

  console.log(embedding);
  ```
</CodeGroup>

# Cohere

## Embedding Text

<CodeGroup>
  ```python Python theme={"system"}
  from portkey_ai import Portkey

  client = Portkey(
      api_key="YOUR_PORTKEY_API_KEY", # defaults to os.environ.get("PORTKEY_API_KEY")
      provider="@PROVIDER",
  )

  embeddings = client.embeddings.create(
      model="cohere.embed-english-v3",
      input=["Hello this is a test", "skibidi"],
      input_type="classification"
  )
  ```

  ```javascript NodeJS theme={"system"}
  import { Portkey } from 'portkey-ai';

  const portkey = new Portkey({
      apiKey: "YOUR_API_KEY",
      provider:"@YOUR_PROVIDER"
  });

  const embedding = await portkey.embeddings.create({
      model: "cohere.embed-english-v3",
      input: ["Hello this is a test", "skibidi"],
      input_type: "classification"
  });

  console.log(embedding);
  ```

  ```sh cURL theme={"system"}
  curl --location 'https://api.portkey.ai/v1/embeddings' \
  --header 'Content-Type: application/json' \
  --header 'x-portkey-api-key: PORTKEY_API_KEY' \
  --header 'x-portkey-provider: PORTKEY_PROVIDER' \
  --data-raw '{
    "model": "cohere.embed-english-v3",
    "input": ["Hello this is a test", "skibidi"],
    "input_type": "classification"
  }'
  ```

  ```python OpenAI Python theme={"system"}
  from openai import OpenAI
  from portkey_ai import PORTKEY_GATEWAY_URL, createHeaders

  portkey_client = OpenAI(
      api_key='NOT_REQUIRED',
      base_url=PORTKEY_GATEWAY_URL,
      default_headers=createHeaders(
          provider="openai",
          api_key="PORTKEY_API_KEY"
      )
  )

  embeddings = portkey_client.embeddings.create(
      model="cohere.embed-english-v3",
      input=["Hello this is a test", "skibidi"],
      input_type="classification"
  )
  ```

  ```js OpenAI NodeJS theme={"system"}
  import OpenAI from 'openai'; // We're using the v4 SDK
  import { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai'

  const portkeyClient = new OpenAI({
    apiKey: 'NOT_REQUIRED', // defaults to process.env["OPENAI_API_KEY"],
    baseURL: PORTKEY_GATEWAY_URL,
    defaultHeaders: createHeaders({
      provider: "vertex-ai",
      apiKey: "PORTKEY_API_KEY", // defaults to process.env["PORTKEY_API_KEY"]
      provider:"@PORTKEY_PROVIDER"
    })
  });

  const embedding = await portkeyClient.embeddings.create({
      model: "cohere.embed-english-v3",
      input: ["Hello this is a test", "skibidi"],
      input_type: "classification"
  });

  console.log(embedding);
  ```
</CodeGroup>

## Embeddings Images

<CodeGroup>
  ```python Python theme={"system"}
  from portkey_ai import Portkey

  client = Portkey(
      api_key="YOUR_PORTKEY_API_KEY", # defaults to os.environ.get("PORTKEY_API_KEY")
      provider="@PROVIDER",
  )

  embeddings = client.embeddings.create(
      model="cohere.embed-english-v3",
      input_type="image",
      dimensions=256,
      input=[
      {
          "image": {
              "base64": "Data:image/webp;base64,UklGRkacAABXRUJQVlA4IDqcAACQggKdASqpAn8B....."
          }
      }
  ]
  )
  ```

  ```javascript NodeJS theme={"system"}
  import { Portkey } from 'portkey-ai';

  const portkey = new Portkey({
      apiKey: "YOUR_API_KEY",
      provider:"@YOUR_PROVIDER"
  });

  const embedding = await portkey.embeddings.create({
  "model": "cohere.embed-english-v3",
  "input_type": "image",
  "dimensions": 256,
  "input": [
      {
          "image": {
              "base64": "Data:image/webp;base64,UklGRkacAABXRUJQVlA4IDqcAACQggKdASqpAn8B....."
          }
      }
  ]
  });

  console.log(embedding);
  ```

  ```sh cURL theme={"system"}
  curl --location 'https://api.portkey.ai/v1/embeddings' \
  --header 'Content-Type: application/json' \
  --header 'x-portkey-api-key: PORTKEY_API_KEY' \
  --header 'x-portkey-provider: PORTKEY_PROVIDER' \
  --data-raw '{
  "model": "cohere.embed-english-v3",
  "input_type": "image",
  "dimensions": 256,
  "input": [
      {
          "image": {
              "base64": "Data:image/webp;base64,UklGRkacAABXRUJQVlA4IDqcAACQggKdASqpAn8B....."
          }
      }
  ]
  }'
  ```

  ```python OpenAI Python theme={"system"}
  from openai import OpenAI
  from portkey_ai import PORTKEY_GATEWAY_URL, createHeaders

  portkey_client = OpenAI(
      api_key='NOT_REQUIRED',
      base_url=PORTKEY_GATEWAY_URL,
      default_headers=createHeaders(
          provider="openai",
          api_key="PORTKEY_API_KEY"
      )
  )

  embeddings = portkey_client.embeddings.create(
      model="cohere.embed-english-v3",
      input_type="image",
      dimensions=256,
      input=[
      {
          image: {
              base64: "Data:image/webp;base64,UklGRkacAABXRUJQVlA4IDqcAACQggKdASqpAn8B....."
          }
      }
  ]
  )
  ```

  ```js OpenAI NodeJS theme={"system"}
  import OpenAI from 'openai'; // We're using the v4 SDK
  import { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai'

  const portkeyClient = new OpenAI({
    apiKey: 'NOT_REQUIRED', // defaults to process.env["OPENAI_API_KEY"],
    baseURL: PORTKEY_GATEWAY_URL,
    defaultHeaders: createHeaders({
      apiKey: "PORTKEY_API_KEY", // defaults to process.env["PORTKEY_API_KEY"]
      provider:"@PORTKEY_PROVIDER"
    })
  });

  const embedding = await portkeyClient.embeddings.create({
      model: "cohere.embed-english-v3",
      input_type: "image",
      dimensions: 256,
      input: [
      {
          image: {
              base64: "Data:image/webp;base64,UklGRkacAABXRUJQVlA4IDqcAACQggKdASqpAn8B....."
          }
      }
    ]
  });

  console.log(embedding);
  ```
</CodeGroup>
