Embeddings
Generate vector embeddings for search, clustering, classification, and RAG.
Endpoint
POST /v1/embeddingsThe OpenAI-compatible Embeddings API turns text into vectors. Use any OpenAI SDK client pointed at the Yunxin base URL.
Request
{
"model": "model-id",
"input": "The quick brown fox jumps over the lazy dog.",
"encoding_format": "float"
}Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Embedding model ID (query GET /v1/models?type=embedding). |
input | string / array | Yes | A single string or an array of strings to embed. |
encoding_format | string | No | float (default) or base64. |
dimensions | integer | No | Output dimensionality, if the model supports it. |
Response
{
"object": "list",
"data": [
{
"object": "embedding",
"index": 0,
"embedding": [0.0023, -0.0091, 0.0152]
}
],
"model": "model-id",
"usage": {
"prompt_tokens": 10,
"total_tokens": 10
}
}Examples
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["YUNXIN_API_KEY"],
base_url="https://api.yuhuanstudio.com/v1",
)
response = client.embeddings.create(
model="model-id",
input="The quick brown fox jumps over the lazy dog.",
)
print(len(response.data[0].embedding))import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.YUNXIN_API_KEY,
baseURL: "https://api.yuhuanstudio.com/v1",
});
const response = await client.embeddings.create({
model: "model-id",
input: "The quick brown fox jumps over the lazy dog.",
});
console.log(response.data[0].embedding.length);curl https://api.yuhuanstudio.com/v1/embeddings \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $YUNXIN_API_KEY" \
-d '{
"model": "model-id",
"input": "The quick brown fox jumps over the lazy dog."
}'Batch embeddings
Pass an array to input to embed many texts in one request. Results align by index:
response = client.embeddings.create(
model="model-id",
input=[
"First document text",
"Second document text",
"Third document text",
],
)
for item in response.data:
print(f"Index {item.index}: {len(item.embedding)} dimensions")Reducing dimensions
When a model supports it, request a smaller vector with dimensions to save storage and speed up
similarity search:
response = client.embeddings.create(
model="model-id",
input="Vector databases store embeddings.",
dimensions=512,
)Available models
Embedding models and their dimensions vary by provider. Discover what's live at runtime:
curl "https://api.yuhuanstudio.com/v1/models?type=embedding" \
-H "Authorization: Bearer $YUNXIN_API_KEY"Check each model's record via GET /v1/models/{model_id} for its native dimensions
and whether the dimensions parameter is supported.
Use cases
- Semantic search — rank documents by similarity to a query.
- Clustering — group related texts.
- Classification — categorize by comparing against labeled examples.
- RAG — retrieve relevant context for generation pipelines.
How is this guide?