API Reference

Embeddings

Generate vector embeddings for semantic search, RAG, clustering, and similarity detection. Access models from OpenAI, Cohere, Voyage, BGE-M3, and more through a single endpoint.

Endpoint

http
POST https://api.onerouter.app/v1/embeddings

Request Parameters

ParameterTypeRequiredDescription
modelstringYesEmbedding model ID (e.g., text-embedding-3-large, text-embedding-3-small, voyage-3)
inputstring / arrayYesText to embed. Pass a string for one embedding or an array of strings for batch (up to 2048 items per request).
dimensionsintegerNoReduce output dimensions to save storage and improve search speed. Supported by text-embedding-3 models. Must be ≤ model's max dimension.
encoding_formatstringNo"float" (default) or "base64" for compact transfer.
userstringNoEnd-user identifier for abuse monitoring.

Single Embedding

python
from openai import OpenAI

client = OpenAI(
    api_key="sk-your-key",
    base_url="https://api.onerouter.app/v1",
)

response = client.embeddings.create(
    model="text-embedding-3-large",
    input="Your text string for embedding",
    dimensions=1024,  # Optional: reduce dimensions
)

embedding = response.data[0].embedding
print(f"Vector dimension: {len(embedding)}")

Batch Embedding

Send up to 2048 inputs in a single request for maximum throughput. The response preserves input order — response.data[0] corresponds to input[0].

python
# Batch embedding — process up to 2048 inputs per request
texts = ["First document", "Second document", "Third document"]

response = client.embeddings.create(
    model="text-embedding-3-large",
    input=texts,
    dimensions=1024,
)

for i, data in enumerate(response.data):
    print(f"Text {i}: vector[:5] = {data.embedding[:5]}...")

Dimension Reduction

Models like text-embedding-3-large (max 3072 dimensions) and text-embedding-3-small (max 1536) support reducing output dimensions via the dimensions parameter.

Why reduce dimensions?

  • Smaller storage: A vector with 256 dimensions uses 12× less space than 3072 dims
  • Faster search: Fewer dimensions = faster cosine similarity computation
  • Good enough quality: For most use cases, 256–512 dimensions retain ~95%+ of the semantic quality
DimensionsStorage (per 1M vectors)QualityBest For
256~1 GBGoodLarge-scale search, cost-sensitive apps
512~2 GBGreatGeneral-purpose RAG and semantic search
1024~4 GBExcellentHigh-accuracy search, clustering
3072~12 GBMaximumMaximum accuracy, small corpora
python
import numpy as np

def cosine_similarity(a, b):
    return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))

# Embed your document corpus (do this once, store results)
doc_embeddings = client.embeddings.create(model="text-embedding-3-large", input=documents)

# Embed a search query
query_embedding = client.embeddings.create(model="text-embedding-3-large", input="How do I reset my password?")

# Find most similar documents
scores = [cosine_similarity(query_embedding.data[0].embedding, d.embedding) for d in doc_embeddings.data]
top_idx = np.argmax(scores)
print(f"Best match: {documents[top_idx]} (score: {scores[top_idx]:.3f})")
Pro tip: For production RAG, pair embeddings with Rerank for a two-stage pipeline: coarse retrieval with embeddings (fast + cheap), then precision reranking on the top 20–50 results.

Available Models

ModelProviderMax DimsBest For
text-embedding-3-largeOpenAI3072Maximum accuracy, flexible dimension reduction
text-embedding-3-smallOpenAI1536Cost-efficient, good quality
Cohere Embed v3Cohere1024Multilingual, strong search performance
Voyage AIVoyage1024 / 2048Code and legal document embeddings
BGE-M3BAAI1024Open-source, multilingual, self-host friendly

See the Models page for the complete catalog with current per-token pricing.