Request
Response
Parameters
The content to be embedded. Contains an ordered list of parts.
The maximum number of dimensions to include in the output embedding. Truncates the output vector. Recommended values:
768, 1536, 3072.Only supported on
gemini-embedding-001 (legacy). Specifies the task type.Options:SEMANTIC_SIMILARITY: Text similarity — recommendation, duplicate detectionCLASSIFICATION: Sentiment analysis, spam detectionCLUSTERING: Document organization, market research, anomaly detectionRETRIEVAL_DOCUMENT: Documents to be indexed/retrievedRETRIEVAL_QUERY: Search queries (pair withRETRIEVAL_DOCUMENTfor the docs)CODE_RETRIEVAL_QUERY: Natural-language code search queriesQUESTION_ANSWERING: Questions in a QA systemFACT_VERIFICATION: Statements to verify against retrieved evidence
Usage examples
Alternative Route Prefix
You can also use the/v1beta/ route prefix instead of /gemini/v1beta/:
[!NOTE]
You can also authenticate using the ?key=$ZnapAI_API_KEY query parameter instead of the header if required by your integration. Both prefix routes support both auth styles.
Multimodal embeddings (gemini-embedding-2 only)
All modalities map into the same embedding space. Example passing base64 image data:
Supported modalities and limits
Batch embeddings (batchEmbedContents)
Returns separate embeddings for multiple inputs in a single API call:
Specify task type to improve performance
Task types with Embeddings 2 (gemini-embedding-2)
gemini-embedding-2 does not accept a task_type field. Instead, prefix the task instruction directly into the text you embed.
Retrieval use cases (asymmetric format)
Single-input use cases (symmetric format) — use the same prefix for query and document.
Example structure query:
Task types with Embeddings 001 (gemini-embedding-001)
For gemini-embedding-001, pass the taskType in the request body:
Controlling embedding size
output_dimensionality truncates the output vector. Both models default to 3072 dimensions. Recommended values: 768, 1536, 3072.
[!NOTE]gemini-embedding-2auto-normalizes truncated dimensions (e.g. 768, 1536) so cosine similarity works correctly out of the box.gemini-embedding-001requires you to manually L2-normalize non-3072-dim vectors client-side.
