Embeddings

Convert text into numerical vectors with the OpenAI-compatible Embeddings endpoint.

POST https://getrouter.ai/v1/embeddings

Basic request

curl https://getrouter.ai/v1/embeddings \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "MODEL_ID",
    "input": "A unified API for multiple AI models"
  }'

The response contains vectors in the data array and usage information in usage when available.

Python

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://getrouter.ai/v1",
)

response = client.embeddings.create(
    model="MODEL_ID",
    input=[
        "A unified API for multiple AI models",
        "Vector search retrieves semantically similar text",
    ],
)

for item in response.data:
    print(item.index, len(item.embedding))

Node.js / TypeScript

import OpenAI from 'openai'

const client = new OpenAI({
  apiKey: 'YOUR_API_KEY',
  baseURL: 'https://getrouter.ai/v1',
})

const response = await client.embeddings.create({
  model: 'MODEL_ID',
  input: [
    'A unified API for multiple AI models',
    'Vector search retrieves semantically similar text',
  ],
})

console.log(response.data.map((item) => item.embedding.length))

Request fields

FieldDescription
modelRequired embedding model ID
inputRequired text, text array, or supported token input
encoding_formatfloat or base64
dimensionsRequested output dimensions for compatible models

Batch inputs

Batch related texts in one request when the selected model and your input limits allow it. Preserve each response item's index so you can map vectors back to the original inputs.

Vector compatibility

Do not mix embeddings from different model IDs or dimension settings in the same vector index. Re-embed existing data if you change either one.

Tip

For retrieval systems, use the same model and preprocessing strategy for documents and user queries.

Alternative path

The API specification also exposes a model-in-path embedding endpoint:

POST /v1/engines/{model}/embeddings

Prefer /v1/embeddings for new OpenAI-compatible integrations unless your existing client requires the engine-style path.

Next steps