Skip to content

OpenAI-compatible Embeddings

model2vec-serve implements the OpenAI embeddings endpoint so existing clients can switch to a self-hosted model with only a base-URL change.

Endpoint

http
POST /v1/embeddings

Request

Headers

  • Content-Type: application/json
  • Authorization: Bearer <api_key> (when authentication is enabled)

Body

json
{
  "input": "Hello world",
  "model": "minishlab/potion-multilingual-128M",
  "encoding_format": "float"
}

Fields

FieldTypeRequiredDescription
inputstring or string[]yesText(s) to embed
modelstringnoMust match the loaded model id
encoding_formatstringno"float" or "base64"; defaults to "float"

Response

Status

200 OK

Body

json
{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "index": 0,
      "embedding": [0.0123, -0.0456, "..."]
    }
  ],
  "model": "minishlab/potion-multilingual-128M",
  "usage": {
    "prompt_tokens": 2,
    "total_tokens": 2
  }
}

When input is an array, data contains one embedding object per input in the same order.

Field descriptions

FieldTypeDescription
objectstringAlways "list"
dataEmbeddingObject[]One entry per input
modelstringLoaded model identifier
usage.prompt_tokensnumberEstimated tokens in the input
usage.total_tokensnumberSame as prompt_tokens

Validation rules

  • input must be non-empty.
  • Batch size must not exceed --max-batch-size.
  • encoding_format must be "float" or "base64".
  • If model is supplied, it must match a loaded model id.
  • If model is omitted, the configured default model is used.

Errors

Statuserror codeCause
400invalid_requestEmpty input, unsupported encoding, mismatched model, batch too large
401unauthorizedMissing or invalid API key
422unprocessable_entityMalformed JSON
500internal_errorModel inference failure

See Errors for the error body shape.

GET /v1/models

Lists all loaded models in the standard OpenAI model list format.

Response

Status: 200 OK

json
{
  "object": "list",
  "data": [
    {
      "id": "minishlab/potion-multilingual-128M",
      "object": "model",
      "created": 1686935002,
      "owned_by": "minishlab"
    }
  ]
}

Example with curl

bash
# List models
curl http://localhost:8080/v1/models

# Request embeddings
curl -X POST http://localhost:8080/v1/embeddings \
  -H "Content-Type: application/json" \
  -d '{"input":["Hello","World"],"model":"minishlab/potion-multilingual-128M"}'

Powered by model2vec