> ## Documentation Index
> Fetch the complete documentation index at: https://docs.leapx-hub.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Gemini Text Embedding (embedContent)

## Introduction

Use the Gemini native API to convert text to vector embeddings. The model is specified in the **URL path** (e.g. `gemini-embedding-001`). Use this when you need Google embedding models or alignment with the Gemini API.

<Info>
  This complements the [Embeddings](/en/api-reference/endpoint/embeddings) (OpenAI-style) endpoint: this doc describes the Gemini native path; the same capability is also available via `POST /v1/embeddings`.
</Info>

## Authentication

<ParamField header="Authorization" type="string" required>
  Bearer token, e.g. `Bearer sk-xxxxxxxxxx`
</ParamField>

## Path Parameters

<ParamField path="model" type="string" required>
  Embedding model name, e.g. `gemini-embedding-001`. Do **not** send `model` in the request body.
</ParamField>

## Request Parameters

<ParamField body="content" type="object" required>
  Content to embed. Must include a `parts` array; each item is `{ "text": "your text" }`.
</ParamField>

<ParamField body="outputDimensionality" type="integer">
  Output vector dimension (supported only by some models, e.g. `gemini-embedding-001`, `text-embedding-004`).
</ParamField>

<ParamField body="taskType" type="string">
  Task type, e.g. `RETRIEVAL_DOCUMENT`, `RETRIEVAL_QUERY` (optional).
</ParamField>

## cURL Example

```bash theme={null}
curl -X POST "https://api.leapx-hub.com/v1/models/gemini-embedding-001:embedContent" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-XyLy**************************mIqSt" \
  -d '{
    "content": {
      "parts": [
        { "text": "Text to embed" }
      ]
    }
  }'
```

With dimension:

```bash theme={null}
curl -X POST "https://api.leapx-hub.com/v1/models/gemini-embedding-001:embedContent" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-XyLy**************************mIqSt" \
  -d '{
    "content": {
      "parts": [
        { "text": "Text to embed" }
      ]
    },
    "outputDimensionality": 768
  }'
```

## Python Example

```python theme={null}
import requests

url = "https://api.leapx-hub.com/v1/models/gemini-embedding-001:embedContent"
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer sk-XyLy**************************mIqSt"
}
payload = {
    "content": {
        "parts": [
            { "text": "Text to embed" }
        ]
    }
}

response = requests.post(url, json=payload, headers=headers)
data = response.json()
embedding = data["embedding"]["values"]
print(f"Dimension: {len(embedding)}")
```

<ResponseExample>
  ```json theme={null}
  {
    "embedding": {
      "values": [0.0023064255, -0.009327292, 0.015797347, ...]
    },
    "metadata": {
      "usage": {
        "prompt_tokens": 6,
        "total_tokens": 6
      }
    }
  }
  ```
</ResponseExample>

## Batch (batchEmbedContents)

For batch embedding use: `POST /v1/models/{model}:batchEmbedContents` with a `requests` array; each item has the same shape as a single request (including `content.parts`). Do **not** include `model` in each item.

```bash theme={null}
curl -X POST "https://api.leapx-hub.com/v1/models/gemini-embedding-001:batchEmbedContents" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-XyLy**************************mIqSt" \
  -d '{
    "requests": [
      { "content": { "parts": [{ "text": "First text" }] } },
      { "content": { "parts": [{ "text": "Second text" }] } }
    ]
  }'
```

## Supported Models

| Model                | Description                                                      |
| -------------------- | ---------------------------------------------------------------- |
| gemini-embedding-001 | General-purpose embedding model; supports `outputDimensionality` |
| text-embedding-004   | High-accuracy embedding model                                    |

## Notes

<Note>
  * The model is specified in the URL path; do not include `model` in the request body
  * `content.parts` is required with at least one non-empty `text`
  * Usage is returned in `metadata.usage` (`prompt_tokens`, `total_tokens`)
</Note>
