Google

Generate batch embeddings

Generate vector embeddings for several texts in one request.

POST /google/v1beta/models/{modelsId}:batchEmbedContents● Supported

Official Gemini API docs ↗

Request parameters

  • modelstring必填

    path: Required. The model's resource name. This serves as an ID for the Model to use. This name should match a model name returned by the `ListModels` method. Format: `models/{model}`

  • requestsarray必填

    Required. Embed requests for the batch. The model in each of these requests must match the model specified `BatchEmbedContentsRequest.model`.

    Accepts 1–100 items, returns them in input order, and requires matching dimensions.

    ▸ 展开子字段(6)
    • contentobject可选◐ Partially supported

      Required. The content to embed. Only the `parts.text` fields will be counted.

      Text parts only; images return 400, including on multimodal embedding models.

    • embedContentConfigobject可选◐ Partially supported

      Optional. Configuration for the EmbedContent request.

      Only outputDimensionality is available, subject to model limits. Other options such as autoTruncate, documentOcr and audioTrackExtraction return 400.

      ▸ 展开子字段(6)
      • audioTrackExtractionboolean可选○ Unsupported

        Optional. Whether to extract audio from video content.

        Passing this returns 400; this embedding option is currently unsupported.

      • autoTruncateboolean可选○ Unsupported

        Optional. Whether to silently truncate the input content if it's longer than the maximum sequence length.

        Passing this returns 400; this embedding option is currently unsupported.

      • documentOcrboolean可选○ Unsupported

        Optional. Whether to enable OCR for document content.

        Passing this returns 400; this embedding option is currently unsupported.

      • outputDimensionalityinteger可选◐ Partially supported

        Optional. Reduced dimension for the output embedding. If set, excessive values in the output embedding are truncated from the end.

        Tested dimensions work on text-embedding-3-small and qwen3-vl-embedding; doubao-embedding-vision requires at least 1024. bge-m3 and qwen3-embedding-0.6b error.

      • taskTypestring可选○ Unsupported

        Optional. The task type of the embedding.

        Passing this returns 400; this embedding option is currently unsupported.

        取值 CLASSIFICATIONCLUSTERINGCODE_RETRIEVAL_QUERYFACT_VERIFICATIONQUESTION_ANSWERINGRETRIEVAL_DOCUMENTRETRIEVAL_QUERYSEMANTIC_SIMILARITYTASK_TYPE_UNSPECIFIED
      • titlestring可选○ Unsupported

        Optional. The title for the text.

        Passing this returns 400; this embedding option is currently unsupported.

    • modelstring可选

      Required. The model's resource name. This serves as an ID for the Model to use. This name should match a model name returned by the `ListModels` method. Format: `models/{model}`

      Must match the model in the URL path, otherwise returns 400.

    • outputDimensionalityinteger可选◐ Partially supported

      Optional. Deprecated: Please use EmbedContentConfig.output_dimensionality instead. Optional reduced dimension for the output embedding. If set, excessive values in the output embedding are truncated from the end. Supported by newer models since 2024 only. You cannot set this value if using the earlier model (`models/embedding-001`).

      Tested dimensions work on text-embedding-3-small and qwen3-vl-embedding; doubao-embedding-vision requires at least 1024. bge-m3 and qwen3-embedding-0.6b error.

    • taskTypestring可选○ Unsupported

      Optional. Deprecated: Please use EmbedContentConfig.task_type instead. Optional task type for which the embeddings will be used. Not supported on earlier models (`models/embedding-001`).

      Passing this returns 400.

      取值 CLASSIFICATIONCLUSTERINGCODE_RETRIEVAL_QUERYFACT_VERIFICATIONQUESTION_ANSWERINGRETRIEVAL_DOCUMENTRETRIEVAL_QUERYSEMANTIC_SIMILARITYTASK_TYPE_UNSPECIFIED
    • titlestring可选○ Unsupported

      Optional. Deprecated: Please use EmbedContentConfig.title instead. An optional title for the text. Only applicable when TaskType is `RETRIEVAL_DOCUMENT`. Note: Specifying a `title` for `RETRIEVAL_DOCUMENT` provides better quality embeddings for retrieval.

      Passing this returns 400.

Returns

200

Each entry in requests follows the same rules as embedContent (text parts only, same rejections); every entry in a batch must use the same outputDimensionality. The current official JS and Python SDKs actually call this batch endpoint for embedContent.

Errors follow the Gemini API format — see error codes

Response

HTTP 200

Successful response

application/json

NameTypeDescription
embeddingsarray<object>Output only. The embeddings for each request, in the same order as provided in the batch request.
embeddings[].shapearray<integer>This field stores the soft tokens tensor frame shape (e.g. [1, 1, 256, 2048]).
embeddings[].valuesarray<number>The embedding values. This is for 3P users only and will not be populated for 1P calls.
usageMetadataobjectOutput only. The usage metadata for the request.
usageMetadata.promptTokenCountintegerOutput only. Number of tokens in the prompt.
usageMetadata.promptTokenDetailsarray<object>Output only. List of modalities that were processed in the request input.