Embed content¶
embedContent turns text into vectors for search, clustering and retrieval. Through the gateway the call is checked
against your policies, charged to the right team and recorded in Request logs, with the SDK code you already have.
What it is¶
POST /v1beta/models/{model}:embedContent (and :batchEmbedContents for several texts), sent to a Gemini embedding
model. Embeddings are not translated: the name must point to a Gemini model. Each provider's embedding models give
vectors of their own kind, so the gateway never swaps one for another.
| Model behind the name | What happens |
|---|---|
| A Gemini embedding model | Sent as it is |
| Another provider's model | A 400 that says so; nothing is sent |
For OpenAI embedding models, use OpenAI's format instead: Embeddings.
The two settings¶
The same as for Generate content: base address https://<your-gateway>, API version v1beta,
and your Vidai key as the API key.
A minimal call¶
from google import genai
from google.genai import types
client = genai.Client(
api_key="vk_…",
http_options=types.HttpOptions(base_url="https://<your-gateway>", api_version="v1beta"),
)
result = client.models.embed_content(
model="gemini-embedding-001",
contents="Travel policy: economy class for flights under six hours.",
)
print(len(result.embeddings[0].values))
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({ apiKey: "vk_…", apiVersion: "v1beta", httpOptions: { baseUrl: "https://<your-gateway>" } });
const result = await ai.models.embedContent({
model: "gemini-embedding-001",
contents: "Travel policy: economy class for flights under six hours.",
});
console.log(result.embeddings?.[0].values?.length);
curl "https://<your-gateway>/v1beta/models/gemini-embedding-001:embedContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" -H "content-type: application/json" \
-d '{"content":{"parts":[{"text":"Travel policy: economy class for flights under six hours."}]}}'
gemini-embedding-001 is an example: use the embedding model names your organisation approved under Models.
Reading what the gateway did¶
x-vidai-request-id and x-vidai-model come with every answer. In Python, read them from
result.sdk_http_response.headers; in TypeScript, from result.sdkHttpResponse?.headers.
Errors¶
In Google's shape, as on Generate content. An embedding call to another provider's model
is a 400 with INVALID_ARGUMENT; match on x-vidai-error-code.
Model names¶
A Gemini embedding model your key may call, as listed under Models in the Control room.
What goes through the gateway¶
| Call | Gemini (Google AI Studio) | Other providers |
|---|---|---|
embedContent, batchEmbedContents |
Yes | No: a 400 |
For embeddings in code written for Vertex AI, use a client in Gemini API mode, as above: the gateway takes
:embedContent, not Vertex AI's :predict (the Vertex AI paths it takes are listed on Vertex AI).
Check it works in a minute¶
Run the curl above: a JSON answer with embedding.values means the address, key and model are right.
Good to know¶
- Store which model made a vector with the vector: vectors from different models can't be compared.