Embeddings
OpenAI Embeddings API - Generate text-embedding-3-large, ada-002 vectors through UniterRouter. Build semantic search, RAG applications with unified embedding API.
Embeddings
Create vector embeddings from text input. Embeddings are numerical representations of text that can be used for semantic search, clustering, and similarity comparisons.
Endpoint
POST https://api.uniterouter.ai/v1/embeddingsRequest Body
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | ID of the embedding model to use |
input | string | array | Yes | Text to embed. Can be a string or array of strings |
encoding_format | string | No | Format of embeddings: float (default) or base64 |
dimensions | integer | No | Number of dimensions for the output (model-dependent) |
Supported Models
| Model | Provider | Dimensions | Max Tokens |
|---|---|---|---|
text-embedding-3-small | OpenAI | 1536 | 8191 |
text-embedding-3-large | OpenAI | 3072 | 8191 |
text-embedding-ada-002 | OpenAI | 1536 | 8191 |
voyage-3 | Voyage | 1024 | 32000 |
voyage-3-lite | Voyage | 512 | 32000 |
Example Request
curl https://api.uniterouter.ai/v1/embeddings \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $UNITEROUTER_API_KEY" \
-d '{
"model": "text-embedding-3-small",
"input": "The quick brown fox jumps over the lazy dog"
}'from openai import OpenAI
client = OpenAI(
base_url="https://api.uniterouter.ai/v1",
api_key="your_api_key",
)
response = client.embeddings.create(
model="text-embedding-3-small",
input="The quick brown fox jumps over the lazy dog"
)
embedding = response.data[0].embedding
print(f"Embedding dimensions: {len(embedding)}")import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.uniterouter.ai/v1",
apiKey: process.env.UNITEROUTER_API_KEY,
});
const response = await client.embeddings.create({
model: "text-embedding-3-small",
input: "The quick brown fox jumps over the lazy dog",
});
const embedding = response.data[0].embedding;
console.log(`Embedding dimensions: ${embedding.length}`);Response
{
"object": "list",
"data": [
{
"object": "embedding",
"index": 0,
"embedding": [0.0023064255, -0.009327292, ...]
}
],
"model": "text-embedding-3-small",
"usage": {
"prompt_tokens": 9,
"total_tokens": 9
}
}Batch Embeddings
Embed multiple texts in a single request for better efficiency:
response = client.embeddings.create(
model="text-embedding-3-small",
input=[
"First document to embed",
"Second document to embed",
"Third document to embed"
]
)
for item in response.data:
print(f"Index {item.index}: {len(item.embedding)} dimensions")Use Cases
Semantic Search
import numpy as np
def cosine_similarity(a, b):
return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))
# Embed query and documents
query_embedding = get_embedding("What is machine learning?")
doc_embeddings = [get_embedding(doc) for doc in documents]
# Find most similar
similarities = [cosine_similarity(query_embedding, doc) for doc in doc_embeddings]
most_similar_idx = np.argmax(similarities)RAG (Retrieval-Augmented Generation)
Combine embeddings with chat completions for context-aware responses:
# 1. Embed user query
query_embedding = client.embeddings.create(
model="text-embedding-3-small",
input=user_query
).data[0].embedding
# 2. Search vector database for relevant context
relevant_docs = vector_db.search(query_embedding, top_k=5)
# 3. Generate response with context
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": f"Context: {relevant_docs}"},
{"role": "user", "content": user_query}
]
)Tip: Use text-embedding-3-small for most use cases. It offers the best balance of cost and performance.
How is this guide?
Responses
OpenAI Responses API - New conversation format for GPT-4, GPT-4o with built-in tool handling. Simplified API for multi-turn conversations and agent workflows.
Images POST
DALL-E API - Generate images from text prompts through UniterRouter. Access DALL-E 3, Stable Diffusion, Midjourney-style image generation with unified API.