Skip to content

Embeddings & rerank

Embeddings and rerank run in their own per-organization lane pool and never consume interactive or background lanes.

POST /v1/embeddings takes the OpenAI shape:

Terminal window
curl https://gw.lunaroute.com/v1/embeddings \
-H "LUNAROUTE-API-KEY: $LUNAROUTE_API_KEY" \
-H "content-type: application/json" \
-d '{"model": "…", "input": ["first document", "second document"]}'
Field Rule
model Required; must be embedding-capable.
input A string or an array of strings; arrays are bounded by the model’s max batch size. Empty strings are rejected. Token-id arrays are not accepted.
encoding_format float (default) or base64.
dimensions Only for models that support it.
user Ignored.

Unknown fields are rejected. The response is TEI’s OpenAI-compatible body with model rewritten to the public model id and a LunaRoute request id.

Requests are capped at 2 MiB of body. Inputs are never silently truncated — an over-length input fails rather than being cut.

POST /v1/rerank takes the Cohere v2 shape, so LangChain / LlamaIndex rerank clients work unchanged:

{
"model": "",
"query": "",
"documents": ["", ""],
"top_n": 5,
"return_documents": false
}

return_documents: true echoes the document text back. The response is the Cohere v2 envelope (id, results[].index / relevance_score, meta.billed_units.search_units), so Cohere SDKs parse it directly.

The model’s input limit bounds each query + document pair. A long query shrinks the room every document has; there is no separate query limit. Cohere’s max_tokens_per_doc, rank_fields, and max_chunks_per_doc are accepted and ignored — nothing is truncated or chunked.

Terminal window
GET /v1/embeddings/models
GET /v1/rerank/models

Each returns the models available for that task with their declared limits and the organization’s effective policy.

Validation errors use 400 with codes such as invalid_input, batch_too_large, unknown_field, invalid_query, invalid_documents, invalid_top_n, and input_too_long. A missing or wrong-capability model gives 404 model_not_found or 400 model_not_embedding_capable / model_not_rerank_capable. When the operator has the feature switched off, all routes answer 503 embeddings_disabled.