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

# embedContent

> POST /v1beta/models/{model}:embedContent —— Gemini 嵌入向量

获取 Gemini 嵌入向量。也可批量调用 `:batchEmbedContents`。

## 请求

```bash theme={null}
curl "https://openp.ai/v1beta/models/text-embedding-004:embedContent" \
  -H "x-goog-api-key: $OPENPAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "content": {"parts": [{"text": "hello world"}]}
  }'
```

### 字段

| 字段                     | 类型      |  必填 | 说明                                                                                                 |
| ---------------------- | ------- | :-: | -------------------------------------------------------------------------------------------------- |
| `content.parts`        | array   |  ✅  | 文本片段数组                                                                                             |
| `taskType`             | string  |     | `RETRIEVAL_QUERY` / `RETRIEVAL_DOCUMENT` / `SEMANTIC_SIMILARITY` / `CLASSIFICATION` / `CLUSTERING` |
| `title`                | string  |     | 当 `taskType=RETRIEVAL_DOCUMENT` 时可附                                                                |
| `outputDimensionality` | integer |     | 截断维度(仅 `gemini-embedding-001`)                                                                     |

## 响应

```json theme={null}
{
  "embedding": {
    "values": [0.012, -0.034, ..., 0.001]
  }
}
```

## 批量嵌入

```bash theme={null}
curl "https://openp.ai/v1beta/models/text-embedding-004:batchEmbedContents" \
  -H "x-goog-api-key: $OPENPAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "requests": [
      {"model": "models/text-embedding-004", "content": {"parts": [{"text": "a"}]}},
      {"model": "models/text-embedding-004", "content": {"parts": [{"text": "b"}]}}
    ]
  }'
```

返回:

```json theme={null}
{
  "embeddings": [
    {"values": [...]},
    {"values": [...]}
  ]
}
```
