Embeddings
POST /v1/embeddings returns dense vectors from an embedding model: the models
GET /v1/models lists with the embeddings capability. No embedding model is
open to customers yet; this page describes the endpoint so an integration is
ready when one is listed in Models and pricing. Only input
tokens are billed.
from openai import OpenAIimport os
client = OpenAI(base_url="https://api.siema-ai.pl/v1", api_key=os.environ["SIEMA_API_KEY"])model = os.environ["SIEMA_EMBEDDING_MODEL"] # an id with the embeddings capability in GET /v1/models
r = client.embeddings.create( model=model, input=[ "Umowa o pracę na czas nieokreślony", "Umowa zlecenie", "Faktura korygująca", ],)vectors = [d.embedding for d in r.data] # three vectors of the model's native length, in input orderprint(r.usage.prompt_tokens)input is a string or a non-empty array of strings, up to 2048 items —
matching OpenAI’s own cap; more is 400 invalid_request with
param: "input". Two other limits apply too: the request body itself is
capped at 20 MiB by default (over that, 400 invalid_request), and a model
server reply the gateway can’t relay because it exceeds 64 MiB comes back as
502 upstream_unavailable. Split a very large batch into smaller requests if
you hit any of these. The response grows with the number of inputs times the
vector length: keep batches to a few hundred inputs, ask for shorter vectors with
dimensions where the model supports it, and use
encoding_format: base64 for big ones.
Each individual string can be up to the model’s context_length; read it from
GET /v1/models rather than hard-coding it. A longer input is rejected by the model server itself, as
400 context_length_exceeded or a plain 400 invalid_request, depending on
the message the model server returns.
Sending a chat-only model (for example speakleash/bielik-11b-v3.0-instruct) to
/v1/embeddings returns 400 invalid_request with param: "model"; use a model with the
embeddings capability.
dimensions
Section titled “dimensions”dimensions asks for shorter vectors from a model that supports shortening
(Matryoshka-trained models): the reply holds that many floats per input, unit
length, instead of the model’s native size. It is forwarded to the model server
unchanged, so the range is the model’s own; a value it does not accept is
400 invalid_request with the model server’s message. Omit it for the native
length. A model’s entry in Models and pricing says whether it
supports dimensions and in what range.
r = client.embeddings.create(model=model, input=texts, dimensions=768)Shortening does not change the price: you are billed for input tokens, not for
the length of the vector. It does shrink the response, which matters for big
batches (see Input). Shortening on the server and cutting the native
vector yourself give the same vector for a Matryoshka model, as long as you
re-normalise after cutting: keep the first n values and divide them by their
L2 norm. Vectors of different lengths, or from different models, are not
comparable; pick one length and embed everything with it.
input must be text. Token-id arrays (lists of integers) are
400 invalid_request; LangChain’s OpenAIEmbeddings sends them by default, so
pass check_embedding_ctx_length=False (see
OpenAI SDK compatibility).
encoding_format
Section titled “encoding_format”encoding_format is float (the default) — each embedding comes back as an
array of numbers — or base64, where each embedding is a base64-encoded
string of little-endian float32 values. The official OpenAI SDKs can request
either; some request base64 by default and decode it back into a list of
floats for you before you ever see it. Both forms are fully supported; pick
whichever your client library sends.
Using the vectors
Section titled “Using the vectors”- Compare with cosine similarity. If your vector store expects unit vectors, normalise client-side.
- Embed queries and documents with the same model. Mixing embedding models produces meaningless distances.
- siema_ai returns dense vectors only.
Embeddings have no output tokens, so cost comes from input tokens alone.
usage.prompt_tokens in the response is what you’re charged for, when the
model server reports it, and usage.cost_micro_pln is the resulting cost. See Billing for how a
request’s cost is computed.