POST/v1/embeddings

Embeddings

Create a vector embedding for input text.

OpenAI-dialect embeddings. Typically served by platform-hosted open-weight models (e.g. qwen/qwen3-embedding-8b).

Request body

FieldTypeRequiredNotes
modelstringyesAn embedding alias (e.g. qwen/qwen3-embedding-8b).
inputstring | string[] | number[][]yesText (or token arrays) to embed.
encoding_formatfloat | base64nobase64 returns the vector base64-encoded.
dimensionsintegernoForwarded to the provider (model-dependent).
userstringnoForwarded to the provider unchanged.

Code sample

curl https://api.<domain>/v1/embeddings \
  -H "Authorization: Bearer $TOKENFACTORY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen/qwen3-embedding-8b",
    "input": "The quick brown fox"
  }'
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.<domain>/v1",
    api_key=os.environ["TOKENFACTORY_API_KEY"],
)

response = client.embeddings.create(
    model="qwen/qwen3-embedding-8b",
    input="The quick brown fox",
)
print(response.data[0].embedding[:5])

Response

{
  "object": "list",
  "data": [
    { "object": "embedding", "index": 0, "embedding": [0.1, 0.2, "…"] }
  ],
  "model": "qwen/qwen3-embedding-8b",
  "usage": { "prompt_tokens": 4, "total_tokens": 4, "prompt_tokens_details": { "cached_tokens": 0, "cache_write_tokens": 0 } },
  "provider_metadata": { "provider": "configured-backend" }
}

Guaranteed fields: object: "list", data[].{object, index, embedding}, model (your alias), usage{prompt_tokens, total_tokens}, and provider_metadata.

usage.prompt_tokens_details.{cached_tokens,cache_write_tokens} are always present, defaulting to 0 when the backend didn't report caching — the gateway normalizes this shape the same way it does for Chat Completions, so an embeddings backend that omits the field (or sends it as null) never produces a different observable shape than one that reports real cache numbers.

Errors

Standard error surface — see Errors.

We use strictly necessary cookies to record your choice and run this site. We do not use cookies for advertising or tracking. See the Cookie Policy.