Skip to content
Open app

Embeddings

Use gemini-embedding-2 with the EMBEDDING API-key permission. Requests use the native Google contract and return vectors, not generated text or images. gemini-embedding-2-preview remains a separate model ID, never an alias for the stable version; preview access depends on your provider.

  • POST /api/gemini/v1beta/models/gemini-embedding-2:embedContent accepts one content and returns embedding.
  • POST /api/gemini/v1beta/models/gemini-embedding-2:batchEmbedContents accepts requests[] and returns embeddings[] in the same order.

Vertex AI requires project allowlisting for batchEmbedContents. If Google denies access, its error is returned and the hold is released; the platform does not silently split the batch into individual calls. The Google SDK uses batchEmbedContents in Gemini API mode even for one input, so the SDK example below also requires batch access. Use the first REST example for a single embedContent request on a project without batch allowlisting.

The /v1beta prefix also works. These methods do not use streaming, generateContent, or the native /api/v1/generations endpoint.

Terminal window
curl 'https://api.moonez.ai/api/gemini/v1beta/models/gemini-embedding-2:embedContent' \
-H "x-goog-api-key: $MOONEZ_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"content":{"parts":[{"text":"Find related documents"}]},"outputDimensionality":768}'
Terminal window
curl 'https://api.moonez.ai/api/gemini/v1beta/models/gemini-embedding-2:batchEmbedContents' \
-H "x-goog-api-key: $MOONEZ_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"requests":[{"model":"models/gemini-embedding-2","content":{"parts":[{"text":"First document"}]}},{"model":"models/gemini-embedding-2","content":{"parts":[{"text":"Second document"}]}}]}'

For a single Vertex-backed request, specify the model in the URL and omit the model field from the JSON body. A Gemini-style models/... value in that body is rejected by Vertex with HTTP 400; Moonez forwards it unchanged.

import os
from google import genai
from google.genai import types
client = genai.Client(
api_key=os.environ["MOONEZ_API_KEY"],
http_options=types.HttpOptions(base_url="https://api.moonez.ai/api/gemini"),
)
result = client.models.embed_content(
model="gemini-embedding-2",
contents="First document",
config=types.EmbedContentConfig(output_dimensionality=768),
)
print(result.embeddings[0].values)

Text, images, PDF, audio, and video use Google’s Content.parts format, including inlineData and supported fileData references. Provider restrictions still apply. The platform does not upload files to Google on your behalf or rewrite unsupported request parameters. Consult the Google embedding guide and REST contract.

Both synchronous methods use the same standard paid input rates, verified against Google pricing on October 22, 2026:

Input modalityUSD / 1 million input tokens
Text$0.20
Images / PDF$0.45
Audio$6.50
Video$12.00

Output vectors are not charged. batchEmbedContents is synchronous and does not receive the separate asynchronous Batch API discount. The asynchronous asyncBatchEmbedContent lifecycle is not exposed by this integration.

Before accepting a request, we reserve an upper bound using 8,192 tokens per input and its highest applicable modality rate. For a batch, holds are summed before rounding. This is a temporary hold, not a fixed request fee.

Final cost uses Google’s usageMetadata.promptTokenCount and promptTokenDetails[] (Gemini API) or promptTokensDetails[] (Vertex AI), with the rates saved when the request was accepted. Mixed modalities are added without intermediate rounding. The final ledger charge is rounded once to six decimal places; unused reserve is released. Failed requests or missing/invalid usage release the hold rather than charging an estimate. A total-only receipt is accepted only for known text-only input.

The customer dashboard shows the actual charge and remaining reserve. Provider Google-spend statistics use the same modality rate card, but remain an estimate of standard Google list cost, not an imported Google invoice. Discounts, credits, taxes, and free-tier eligibility are not inferred.