Gemini Embeddings
POST /v1/gemini/embeddings
Native passthrough to Google Gemini’s embedding API. Request shape mirrors models/{model}:embedContent / :batchEmbedContents; response is normalized to a single list-of-embeddings format with a usage block on top.
/v1/embeddingsUse /v1/embeddings for the unified OpenAI-compatible shape. Use this endpoint when you need Gemini-specific fields — task_type, output_dimensionality truncation, optional document title — that the OpenAI shape doesn’t expose.
Headers
| Header | Required | Description |
|---|---|---|
Authorization |
Yes | Bearer <api-key-or-jwt> |
Content-Type |
Yes | application/json |
X-Quantized-Provider |
No | Pin a provider by slug (only gemini serves this endpoint), or one specific connection as <provider>/<connection>. The pin narrows the providers your license allows and never widens them. A malformed value or a disallowed provider returns 400. |
X-Quantized-Metadata |
No | A flat JSON object of scalar values, recorded with the request for your own attribution. Invalid JSON or nested values return 400. See Authentication. |
Request body
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
model |
string | Yes | — | Model id (e.g. gemini-embedding-001) |
contents |
array | Yes | — | One or more content objects. Each item produces one embedding |
contents[].parts |
array | Yes | — | At least one {text: string} part per content. Multiple parts in one content are embedded together into a single vector; use separate contents items for separate vectors |
task_type |
string | No | null | One of RETRIEVAL_QUERY, RETRIEVAL_DOCUMENT, SEMANTIC_SIMILARITY, CLASSIFICATION, CLUSTERING, QUESTION_ANSWERING, FACT_VERIFICATION, CODE_RETRIEVAL_QUERY |
output_dimensionality |
integer | No | null (model default, 3072 for gemini-embedding-001) |
Vector dimension. Must be >= 1. Common values: 768, 3072 |
title |
string | No | null | Document title — only meaningful when task_type is RETRIEVAL_DOCUMENT |
The serializer uses extra="forbid". Fields outside the list above are rejected with 400 invalid_request. Notable rejects: OpenAI’s input, dimensions, encoding_format, user; Cohere’s texts, input_type, embedding_types.
Single vs batch routing
The router picks the upstream endpoint based on the cardinality of contents:
- 1 content →
:embedContent($0.15 per 1M tokens) - N > 1 contents →
:batchEmbedContents($0.075 per 1M tokens, 50% cheaper)
Gemini’s :embedContent endpoint silently concatenates multi-part content into a single string and returns ONE vector for everything — no error, 200 OK, wrong shape. The router defends against this by always dispatching multi-content requests to :batchEmbedContents. The endpoint field in the response confirms which upstream URL was used; treat any unexpected value (e.g. embedContent for a multi-content request) as a router bug.
Examples
curl -X POST https://api.quantized.us/v1/gemini/embeddings \
-H "Authorization: Bearer sk-quantized-YOUR-KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-embedding-001",
"contents": [
{"parts": [{"text": "The quick brown fox jumps over the lazy dog."}]}
],
"task_type": "RETRIEVAL_DOCUMENT"
}'
curl -X POST https://api.quantized.us/v1/gemini/embeddings \
-H "Authorization: Bearer sk-quantized-YOUR-KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-embedding-001",
"contents": [
{"parts": [{"text": "first"}]},
{"parts": [{"text": "second"}]},
{"parts": [{"text": "third"}]}
],
"task_type": "RETRIEVAL_DOCUMENT"
}'
import httpx
resp = httpx.post(
"https://api.quantized.us/v1/gemini/embeddings",
headers={"Authorization": "Bearer sk-quantized-YOUR-KEY"},
json={
"model": "gemini-embedding-001",
"contents": [
{"parts": [{"text": "What is a fox?"}]}
],
"task_type": "RETRIEVAL_QUERY",
"output_dimensionality": 768,
},
)
data = resp.json()
print(data["endpoint"]) # "embedContent"
print(len(data["embeddings"][0]["values"])) # 768
Response
{
"model": "gemini-embedding-001",
"embeddings": [
{"values": [0.0123, -0.0456, 0.0789, ...]}
],
"endpoint": "embedContent",
"usage": {
"credits_used": 16
}
}
| Field | Type | Description |
|---|---|---|
model |
string | Echoed from the request |
embeddings |
array | One entry per input content, in order. Single-input requests return a 1-element list |
embeddings[].values |
array of floats | The vector |
endpoint |
string | Either "embedContent" or "batchEmbedContents" — the upstream URL the router called |
usage.credits_used |
integer | Micro-credits consumed (billed at the rate corresponding to endpoint) |
Gemini’s :embedContent returns {embedding: {values: [...]}} (singular), while :batchEmbedContents returns {embeddings: [{values: [...]}, ...]} (plural). The router normalizes both to the plural list shape so client code doesn’t branch on cardinality, and surfaces the upstream choice via the endpoint field.
Gemini’s embedding endpoints do not return token counts. Quantized estimates input tokens at ~4 characters per token (floored at 1). This is conservative and rarely under-bills for natural-language input.
Models
| Model id | Native dimension | Truncatable to | Public list rate (single / batch) |
|---|---|---|---|
gemini-embedding-001 |
3072 | 768 | $0.15 / $0.075 per 1M tokens |
Filter for Gemini embedding models via GET /v1/models:
models = response.json()["data"] # GET /v1/models returns {"object": "list", "data": [...]}
gemini_embed_models = [
m for m in models
if "gemini_embeddings" in m.get("supported_features", [])
]
Providers
| Provider | Slug | Default? |
|---|---|---|
| Google Gemini | gemini |
Yes (and only) |
This endpoint is Gemini-only. X-Quantized-Provider is optional; any value other than gemini (or gemini/<connection>) returns 400.
Errors
| Status | Code | Condition |
|---|---|---|
400 |
invalid_request |
Request body failed validation: missing or empty contents, an unsupported field, an invalid task_type value, or output_dimensionality < 1. param names the field |
400 |
invalid_request |
Malformed X-Quantized-Provider header (param: "X-Quantized-Provider") |
400 |
invalid_metadata_header |
Invalid X-Quantized-Metadata header |
400 |
invalid_request |
Gemini rejected the request (e.g. an invalid task type combination); the provider’s message is returned |
400 |
context_length_exceeded |
A content is longer than the model accepts |
400 |
no_provider_available |
No provider available for the endpoint (e.g. a pin your license doesn’t allow) |
401 |
missing_api_key, invalid_api_key, api_key_expired, license_inactive |
Missing, invalid, or expired API key, or an inactive license |
402 |
budget_exhausted |
Your license is out of budget. metadata names the limit that blocked the request |
403 |
policy_denied |
Your license’s policy does not allow this service or parameter value (param names the parameter) |
403 |
content_policy_violation |
Request blocked by a guardrail |
404 |
model_not_found |
Unknown model id — forwarded to Gemini, which answers models/<id> is not found for API version v1beta |
429 |
rate_limit_exceeded |
The provider rate-limited the request. retry-after is set when the provider sent one |
500 |
internal_error |
Unexpected error, or a budget configuration error |
502 |
provider_error |
The provider returned a 5xx or an invalid response, or the connection dropped |
503 |
provider_misconfigured |
Our credentials for the provider are missing or were rejected |
503 |
policy_unavailable |
Your license’s policy can’t be evaluated |
504 |
upstream_timeout |
The provider timed out |
Every error uses the standard error body. Branch on the status and code; see the Error reference for each.
The following are not accepted by v1 and may be added in a future release:
- Multimodal Gemini embeddings (image, audio, video parts)
- Vertex AI endpoint variant (this endpoint talks to
generativelanguage.googleapis.com, not the Vertex API) - Concurrent fan-out to
:countTokensfor precise token counts