Skip to content

Embeddings

Turns text into vectors for search, clustering and retrieval. OpenAI-compatible body and response, with the cost of the request in usage.

Markdown
On this page
POST/v1/embeddings

This endpoint takes an OpenAI embeddings request and answers in the same format, so the OpenAI SDKs' embeddings.create works against it unchanged. Lykia picks a provider for the model the same way it does for chat: your project's own provider keys first, then Lykia's direct connections, cheapest first, moving to the next candidate when one fails. Reservations, key limits, project budgets and request records work as they do for POST /chat/completions.

Only models that produce vectors can be used here. They are left out of the default GET /models list, which is meant for chat; list them with GET /models?output_modalities=embedding.

Request body

modelstringrequired

An embedding model id (for example openai/text-embedding-3-small), or a preset as @name whose model is an embedding model (for example @embedding). A chat model returns 400 with the code unsupported_model; a preset whose model is not an embedding model returns preset_modality_mismatch.

inputstring | string[]required

The text to embed: one string, or an array of 1 to 2,048 non-empty strings. Token arrays are not accepted (400, unsupported_input).

dimensionsinteger

The length of the vectors, for models that let you choose it.

encoding_formatstring

float (default) or base64. Lykia returns base64 even for providers that only return floats.

modelsstring[]

Fallback models, as in chat.

providerobject

Provider preferences, as in chat. See Provider routing.

userstring

and metadata (object) — Tags stored with the request record and never sent to the provider. See Tags and usage breakdown.

Example

The vectors in the response below are shortened to four numbers.

Request
curl https://api.getlykia.com/v1/embeddings \
  -H "Authorization: Bearer $LYKIA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/text-embedding-3-small",
    "input": ["Refund policy for annual plans", "How do I reset my password?"],
    "dimensions": 256,
    "user": "tenant-42",
    "metadata": { "feature": "search" }
  }'
Response200
{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "index": 0,
      "embedding": [0.385695, 0.449977, 0.707107, 0.385695]
    },
    {
      "object": "embedding",
      "index": 1,
      "embedding": [0.641223, 0.569976, 0.427482, 0.284988]
    }
  ],
  "model": "openai/text-embedding-3-small",
  "provider": "openai",
  "usage": {
    "prompt_tokens": 15,
    "total_tokens": 15,
    "cost": 0.000001,
    "is_byok": false,
    "cost_details": {
      "upstream_cost": 0.000001,
      "platform_fee": 0,
      "is_byok": false
    }
  }
}

Response

objectstring

Always list.

dataarray

One item per input, in the same order.

objectstring

Always embedding.

indexinteger

The position of the input this vector belongs to.

embeddingnumber[] | string

The vector, or a base64 string with encoding_format: "base64".

modelstring

The model that produced the vectors; with a preset, the real model.

providerstring

The id of the provider that served the request.

usageobject

prompt_tokens and total_tokens (the input tokens), cost in USD, is_byok and cost_details, as in chat.

The response carries the request id in the X-Generation-Id header, and X-Lykia-Preset when model was a preset. Embedding requests are priced per input token at the model's prompt price. When a provider does not report token counts, Lykia estimates them at about four characters per token. Look the record up with GET /generation; its endpoint is embeddings.

Errors

The status codes are the same as for POST /chat/completions, with the body described in Errors. A provider that returns fewer vectors than inputs gives 502, and the request is not billed.