Skip to content

Generate Embeddings via OpenAI-Compatible API

LLMosaic provides a /v1/embeddings endpoint that accepts raw text input and returns high-dimensional vector embeddings. The endpoint is fully compatible with OpenAI client libraries, making it easy to integrate into existing workflows.

You’ll learn how to: - Submit text or batched input for embedding
- Interpret the embedding vector output
- Use the output for semantic search and retrieval


Steps

Step 0 — Embed a single piece of text

Submits one string for embedding.

curl -X POST "${EMBED_BASE}/${EMBED_MODEL}/v1/embeddings" \
  -H "Authorization: Bearer ${EMBED_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "model":"'"${EMBED_MODEL}"'",
    "input":["Your text here"]
  }'

import requests

resp = requests.post(
  f"{EMBED_BASE}/{EMBED_MODEL}/v1/embeddings",
  headers={"Authorization":f"Bearer {EMBED_KEY}", "Content-Type":"application/json"},
  json={"model":EMBED_MODEL, "input":["Your text here"]}
)
print(resp.json())

const res = await fetch(
  `${EMBED_BASE}/${EMBED_MODEL}/v1/embeddings`, {
    method:"POST",
    headers:{
      "Authorization":`Bearer ${EMBED_KEY}`,
      "Content-Type":"application/json"
    },
    body: JSON.stringify({ model: EMBED_MODEL, input:["Your text here"] })
  }
);
console.log(await res.json());


Step 1 — Embed a batch of texts

Submits an array of strings for embedding in one call.

curl -X POST "${EMBED_BASE}/${EMBED_MODEL}/v1/embeddings" \
  -H "Authorization: Bearer ${EMBED_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "model":"'"${EMBED_MODEL}"'",
    "input":["Text one","Text two","Text three"]
  }'

import requests

resp = requests.post(
  f"{EMBED_BASE}/{EMBED_MODEL}/v1/embeddings",
  headers={"Authorization":f"Bearer {EMBED_KEY}", "Content-Type":"application/json"},
  json={"model":EMBED_MODEL, "input":["Text one","Text two","Text three"]}
)
print(resp.json())

const res = await fetch(
  `${EMBED_BASE}/${EMBED_MODEL}/v1/embeddings`, {
    method:"POST",
    headers:{
      "Authorization":`Bearer ${EMBED_KEY}`,
      "Content-Type":"application/json"
    },
    body: JSON.stringify({ model: EMBED_MODEL, input:["Text one","Text two","Text three"] })
  }
);
console.log(await res.json());