Embeddings
Turn text into vectors with an embedding model.
Follows OpenAI's Embeddings format. Use an embedding model from /models?type=embeddings, or from GET /v1/models, which lists them with an embeddings output modality. Send the key as Authorization: Bearer sk-df-... or x-api-key.
Send a request
curl https://deference.si/v1/embeddings \
-H "Authorization: Bearer $DEFERENCE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/text-embedding-3-small",
"input": "A ledger is a list of entries."
}'import os
from openai import OpenAI
client = OpenAI(base_url="https://deference.si/v1", api_key=os.environ["DEFERENCE_API_KEY"])
result = client.embeddings.create(
model="openai/text-embedding-3-small",
input="A ledger is a list of entries.",
)
print(len(result.data[0].embedding))import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://deference.si/v1",
apiKey: process.env.DEFERENCE_API_KEY,
});
const result = await client.embeddings.create({
model: "openai/text-embedding-3-small",
input: "A ledger is a list of entries.",
});
console.log(result.data[0].embedding.length);Request body
- modelstringRequired
- An embedding model id.
- inputstring | arrayRequired
- The text to embed, or an array of strings.
- encoding_formatstring
float(default) returns an array of numbers;base64returns a base64 string.- dimensionsinteger
- Output size, for models that support shortening.
Deference replaces user with an account tag.
Response
{
"object": "list",
"data": [{ "object": "embedding", "index": 0, "embedding": [0.0123, -0.0456] }],
"model": "openai/text-embedding-3-small",
"usage": { "prompt_tokens": 8, "total_tokens": 8 }
}The embedding array is shortened here. A call with usage.cost is charged that cost plus OpenRouter's 5% platform fee. Deference adds no markup. The charge is final when the body has no generation id, and provisional when it does. When no cost is reported, token counts with a generation id are a provisional estimate. Without a reported cost or a generation id, nothing is charged yet and the hold stays reserved. x-deference-cost is that amount in micro-dollars.