Generate an embedding
Turn a piece of text into a vector embedding for retrieval and similarity.
/google/v1beta/models/{modelsId}:embedContent● SupportedRequest 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 supportedRequired. 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 supportedOptional. 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可选○ UnsupportedOptional. Whether to extract audio from video content.
Passing this returns 400; this embedding option is currently unsupported.
autoTruncateboolean可选○ UnsupportedOptional. 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可选○ UnsupportedOptional. Whether to enable OCR for document content.
Passing this returns 400; this embedding option is currently unsupported.
outputDimensionalityinteger可选◐ Partially supportedOptional. 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可选○ UnsupportedOptional. The task type of the embedding.
Passing this returns 400; this embedding option is currently unsupported.
titlestring可选○ UnsupportedOptional. 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 supportedOptional. 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可选○ UnsupportedOptional. 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.
titlestring可选○ UnsupportedOptional. 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
| Name | Type | Description |
|---|---|---|
| embedding | object | Output only. The embedding generated from the input content. |
| embedding.shape | array<integer> | This field stores the soft tokens tensor frame shape (e.g. [1, 1, 256, 2048]). |
| embedding.values | array<number> | The embedding values. This is for 3P users only and will not be populated for 1P calls. |
| usageMetadata | object | Output only. The usage metadata for the request. |
| usageMetadata.promptTokenCount | integer | Output only. Number of tokens in the prompt. |
| usageMetadata.promptTokenDetails | array<object> | Output only. List of modalities that were processed in the request input. |