POST
/
v1beta
/
models
/
{model}
:embedContent
curl -X POST "https://api.example.com/v1beta/models/text-embedding-004:embedContent?key=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "models/text-embedding-004",
    "content": {
      "parts": [
        {
          "text": "What is the meaning of life?"
        }
      ]
    },
    "taskType": "RETRIEVAL_QUERY"
  }'
{
  "embedding": {
    "values": [
      0.013168523,
      -0.008711934,
      -0.046782676,
      0.000699 5056,
      -0.024563482,
      ...
    ]
  }
}
Official documentation: https://ai.google.dev/gemini-api/docs/embeddings
Generate vector embeddings for text using Google Gemini embedding models. Embeddings are useful for semantic search, clustering, recommendations, and other machine learning tasks.

Request Parameters

key
string
required
API key.
model
string
required
The embedding model to use (e.g., “models/text-embedding-004”).
content
object
required
Content to embed.
  • parts (array): Array of content parts
    • text (string): Text to embed
taskType
string
Task type for the embedding.Options:
  • RETRIEVAL_QUERY: Query in a search/retrieval setting
  • RETRIEVAL_DOCUMENT: Document in a search/retrieval setting
  • SEMANTIC_SIMILARITY: Semantic similarity task
  • CLASSIFICATION: Classification task
  • CLUSTERING: Clustering task
title
string
Optional title for the content (only for RETRIEVAL_DOCUMENT task type).

Response

Returns a vector embedding for the input text.
curl -X POST "https://api.example.com/v1beta/models/text-embedding-004:embedContent?key=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "models/text-embedding-004",
    "content": {
      "parts": [
        {
          "text": "What is the meaning of life?"
        }
      ]
    },
    "taskType": "RETRIEVAL_QUERY"
  }'
{
  "embedding": {
    "values": [
      0.013168523,
      -0.008711934,
      -0.046782676,
      0.000699 5056,
      -0.024563482,
      ...
    ]
  }
}

Batch Embeddings

You can also generate embeddings for multiple texts in a single request using the batchEmbedContents endpoint:
POST /v1beta/models/{model}:batchEmbedContents
This allows you to embed multiple pieces of content efficiently in one API call.