Skip to content
中文

Generate an embedding

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

Official Gemini API docs ↗

Request parameters

  • modelstringrequired

    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}

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

    Expand sub-fields (2)
    • partsarrayoptional

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

    • rolestringoptional

      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.

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

    Expand sub-fields (6)
    • audioTrackExtractionbooleanoptional○ Unsupported

      Optional. Whether to extract audio from video content.

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

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

    • documentOcrbooleanoptional○ Unsupported

      Optional. Whether to enable OCR for document content.

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

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

    • taskTypestringoptional○ Unsupported

      Optional. The task type of the embedding.

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

      values CLASSIFICATIONCLUSTERINGCODE_RETRIEVAL_QUERYFACT_VERIFICATIONQUESTION_ANSWERINGRETRIEVAL_DOCUMENTRETRIEVAL_QUERYSEMANTIC_SIMILARITYTASK_TYPE_UNSPECIFIED
    • titlestringoptional○ Unsupported

      Optional. The title for the text.

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

  • modelstringoptional

    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.

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

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

    values CLASSIFICATIONCLUSTERINGCODE_RETRIEVAL_QUERYFACT_VERIFICATIONQUESTION_ANSWERINGRETRIEVAL_DOCUMENTRETRIEVAL_QUERYSEMANTIC_SIMILARITYTASK_TYPE_UNSPECIFIED
  • titlestringoptional○ 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

Request

curl
curl https://api.deepraxis.com/google/v1beta/models/text-embedding-3-small:embedContent \
  -H "x-goog-api-key: $PRAXIS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"content":{"parts":[{"text":"你好"}]}}'
Python
from google import genai
from google.genai import types

client = genai.Client(
    api_key="$PRAXIS_API_KEY",
    http_options=types.HttpOptions(base_url="https://api.deepraxis.com/google"),
)

resp = client.models.embed_content(
    model="text-embedding-3-small",
    contents="你好",
)
print(resp.embeddings[0].values)
TypeScript
import { GoogleGenAI } from "@google/genai";

const ai = new GoogleGenAI({
  apiKey: "$PRAXIS_API_KEY",
  httpOptions: { baseUrl: "https://api.deepraxis.com/google" },
});

const resp = await ai.models.embedContent({
  model: "text-embedding-3-small",
  contents: "你好",
});
console.log(resp.embeddings?.[0]?.values);

Response 200

{
  "embedding": {
    "values": [
      0.007704960182309151,
      -0.06173783168196678,
      0.07302535325288773,
      0.06841219216585159,
      "… (1024 项)"
    ]
  },
  "usageMetadata": {
    "promptTokenCount": 2
  }
}

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.