Embeddings
Turn texts into vectors for search and retrieval with a model of kind embedding.
Create embeddings#
POST /v1/embeddings returns one vector per input, in the order of the inputs. input is one text or a list of up to 2048 texts. The OpenAI SDKs' embeddings call works with the base URL and key changed.
Embeddings are served Routed only. A request for the Sealed tier (by panward-tier, or by default) is refused with 400 unsupported_parameter naming panward-tier; the samples send panward-tier: routed.
embedding is offered yet404 model_not_found for every model id. The samples below show the request for when one is offered.Set PANWARD_EMBEDDING_MODEL to the id of a model of kind embedding from the model catalog. An id that is not a canonical id answers 404 model_not_found.
cat > body.json <<EOF {"model": "$PANWARD_EMBEDDING_MODEL", "input": ["Discharge note, ward 4", "Referral letter, cardiology"]} EOF curl https://api.panward.ai/v1/embeddings \ -H "Authorization: Bearer $PANWARD_API_KEY" \ -H "Content-Type: application/json" \ -H "panward-tier: routed" \ --data-binary @body.json
import os from openai import OpenAI client = OpenAI( base_url="https://api.panward.ai/v1", api_key=os.environ["PANWARD_API_KEY"], ) result = client.embeddings.create( model=os.environ["PANWARD_EMBEDDING_MODEL"], input=["Discharge note, ward 4", "Referral letter, cardiology"], extra_headers={"panward-tier": "routed"}, ) for item in result.data: print(item.index, len(item.embedding)) print(result.usage)
import OpenAI from "openai"; const client = new OpenAI({ baseURL: "https://api.panward.ai/v1", apiKey: process.env.PANWARD_API_KEY, }); const result = await client.embeddings.create( { model: process.env.PANWARD_EMBEDDING_MODEL!, input: ["Discharge note, ward 4", "Referral letter, cardiology"], }, { headers: { "panward-tier": "routed" } }, ); for (const item of result.data) console.log(item.index, item.embedding.length); console.log(result.usage);
Request fields#
| Field | Required | Values | Limits | Notes |
|---|---|---|---|---|
| model | Yes | string | Canonical id of a model of kind `embedding`. | |
| input | Yes | string | array of string | One text or up to 2048 texts. | |
| encoding_format | No | float, base64 | ||
| dimensions | No | integer | min 1 | Shorten the vectors, for models that support it. |
| user | No | string | max length 256 | Accepted for compatibility and ignored. Never stored, never forwarded upstream. |
Each input must fit the model's context; a longer one is refused with 400 context_length_exceeded.
Receipts and billing#
The response carries the same headers as a chat completion, among them panward-receipt-id, panward-tier and panward-region, and the request has a receipt like any other (Receipts and verification). panward-hold-until-verified: true is accepted: the response waits until the verification level is known and the answer is 503 verification_unavailable instead of an unverified one.
Embeddings are billed on input tokens.