Text & embeddings
Embeddings
Convert text into vector embeddings for search, clustering and RAG.
POST
/v1/embeddings
Compatible with the OpenAI Embeddings API. Returns a vector for each input text; use the vectors for semantic search, retrieval-augmented generation (RAG), clustering or classification.
Authentication
Authorization: Bearer sk-xxxx
Request body
| Parameter | Type | Required | Description |
|---|---|---|---|
model |
string | Yes | Embedding model ID, e.g. text-embedding-3-small. |
input |
string | array | Yes | Text to embed, or an array of texts for a batch. Each item must fit within the model's context length. |
encoding_format |
string | No | float (default) or base64. |
dimensions |
integer | No | Number of output dimensions. Supported by text-embedding-3-* and some other models. |
user |
string | No | Stable end-user identifier. |
Request example
cURL
curl https://rutoken.ai/v1/embeddings \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_KEY" \
-d '{
"model": "text-embedding-3-small",
"input": ["The food was delicious.", "The service was slow."]
}'
Python
from openai import OpenAI
client = OpenAI(base_url="https://rutoken.ai/v1", api_key="sk-xxxx")
resp = client.embeddings.create(
model="text-embedding-3-small",
input=["The food was delicious.", "The service was slow."],
)
for item in resp.data:
print(item.index, len(item.embedding))
Node.js
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://rutoken.ai/v1", apiKey: "sk-xxxx" });
const resp = await client.embeddings.create({
model: "text-embedding-3-small",
input: ["The food was delicious.", "The service was slow."],
});
for (const item of resp.data) console.log(item.index, item.embedding.length);
Response
json
{
"object": "list",
"data": [
{
"object": "embedding",
"index": 0,
"embedding": [0.0023064255, -0.009327292, 0.015797347]
},
{
"object": "embedding",
"index": 1,
"embedding": [-0.012174723, 0.004532318, -0.020815546]
}
],
"model": "text-embedding-3-small",
"usage": {
"prompt_tokens": 12,
"total_tokens": 12
}
}
The vectors are shortened here; text-embedding-3-small returns 1536 dimensions by default.
| Field | Type | Description |
|---|---|---|
data[].index |
integer | Position of the corresponding input. |
data[].embedding |
array | string | The vector, or a base64 string when encoding_format is base64. |
usage.prompt_tokens |
integer | Input tokens used for billing. |
Notes
- Compare vectors with cosine similarity. OpenAI embeddings are normalized to length 1, so a dot product gives the same ranking.
- Gemini embedding models can also be called through this endpoint with the same request format.
- To re-order search results by relevance, use Rerank.