Google

Generate an embedding

Turn a piece of text into a vector embedding for retrieval and similarity.

POST /google/v1beta/models/{modelsId}:embedContent● 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}`

  • 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.

    ▸ 展开子字段(2)
    • partsarray可选

      Ordered `Parts` that constitute a single message. Parts may have different MIME types.

    • rolestring可选

      Optional. The producer of the content. Must be either 'user' or 'model'. Useful to set for multi-turn conversations, otherwise can be left blank or unset.

  • 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

Only text parts are accepted; images and other multimodal parts are rejected. taskType, title and retrieval settings such as autoTruncate / documentOcr / audioTrackExtraction have no equivalent on the platform: a request that carries them gets 400 (INVALID_ARGUMENT) instead of being silently ignored, because different taskType values produce vectors that behave differently and dropping one would quietly change retrieval quality. outputDimensionality maps to the dimension of the returned vector.

Errors follow the Gemini API format — see error codes

Response

HTTP 200

Successful response

application/json

NameTypeDescription
embeddingobjectOutput only. The embedding generated from the input content.
embedding.shapearray<integer>This field stores the soft tokens tensor frame shape (e.g. [1, 1, 256, 2048]).
embedding.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.