GlexirDocs
Dashboard

API

Embeddings

The Embeddings endpoint turns text into vectors you can store and compare, for search, clustering or recommendations. It is OpenAI-compatible: same request, same response.

Create embeddings

import Glexir from "@glexir/sdk";

const glexir = new Glexir({ apiKey: process.env.GLEXIR_API_KEY });

const res = await glexir.embeddings.create({
  model: "text-embedding-3-small",
  input: ["The food was delicious.", "The service was slow."],
});

const vector: number[] = res.data[0]?.embedding ?? [];
console.log(vector.length, res.usage.total_tokens);

Response:

JSON
{
  "object": "list",
  "data": [
    { "object": "embedding", "index": 0, "embedding": [0.0023, -0.0093, 0.0158] },
    { "object": "embedding", "index": 1, "embedding": [-0.0117, 0.0041, 0.0212] }
  ],
  "model": "text-embedding-3-small",
  "usage": { "prompt_tokens": 11, "total_tokens": 11 }
}

Vectors are shortened here. data[i].index matches the position of the input.

Models

The price book currently sells text-embedding-3-small and text-embedding-3-large. Call models.list() for the live list. A model that is not priced returns 403 with code model_not_priced. A model that is not an embedding model returns 400 with code model_not_found.

Use dimensions to get shorter vectors from the text-embedding-3 models:

TypeScript
import Glexir from "@glexir/sdk";

const glexir = new Glexir();

const res = await glexir.embeddings.create({
  model: "text-embedding-3-large",
  input: "Glexir",
  dimensions: 256,
});
console.log(res.data[0]?.embedding.length); // 256

Encoding format

When you leave out encoding_format, the SDK asks for compact base64 on the wire and decodes it into number[] for you. OpenAI's SDK does the same. Base64 responses are smaller than JSON floats.

If you set encoding_format, the SDK sends it unchanged and does not decode:

  • "float": embedding is a number[].
  • "base64": embedding is a base64 string of little-endian float32 values. The return type is CreateEmbeddingResponse<string>.
TypeScript
import Glexir from "@glexir/sdk";

const glexir = new Glexir();

const raw = await glexir.embeddings.create({
  model: "text-embedding-3-small",
  input: "hello",
  encoding_format: "base64",
});
const encoded: string | undefined = raw.data[0]?.embedding;

Over plain HTTP (curl), the API returns floats unless you send "encoding_format": "base64". The gateway passes either format through untouched.

Method

glexir.embeddings.create()

TypeScript
import type { APIPromise, CreateEmbeddingResponse, EmbeddingCreateParams, RequestOptions } from "@glexir/sdk";

// The method on glexir.embeddings, with its two overloads
interface Embeddings {
  create(body: EmbeddingCreateParams & { encoding_format: "base64" }, options?: RequestOptions): APIPromise<CreateEmbeddingResponse<string>>;
  create(body: EmbeddingCreateParams, options?: RequestOptions): APIPromise<CreateEmbeddingResponse>;
}

POST /embeddings. options are the per-request options described in Client configuration.

EmbeddingCreateParams
modelEmbeddingModelrequired
An embedding model ID. The type suggests text-embedding-3-small, text-embedding-3-large and text-embedding-ada-002 and accepts any string; only priced models work.
inputstring | string[] | number[] | number[][]required
Text, a list of texts, or token arrays. Each input at most 8,192 tokens, at most 2,048 inputs, at most 300,000 tokens per request. Missing input returns 400.
dimensionsnumberoptional
Output vector size. text-embedding-3 models only.
encoding_format"float" | "base64"optional
Leave it out to get decoded number[] vectors. See Encoding format above.
userstringoptional
Your end user's ID. Glexir replaces it with an identifier derived from your organization and this value before forwarding, so OpenAI's abuse checks apply to the right customer.

EmbeddingCreateParams also accepts other keys, which are sent as-is.

Response

CreateEmbeddingResponse<TVector = number[]>
object"list"required
Always list.
dataEmbedding<TVector>[]required
One entry per input, in input order.
modelstringrequired
The model that produced the vectors.
usage{ prompt_tokens: number; total_tokens: number }required
Tokens billed for the request.
_request_idstring | nulloptional
SDK only. The x-request-id header.
Embedding<TVector = number[]>
object"embedding"required
Always embedding.
indexnumberrequired
Position of the matching input.
embeddingTVectorrequired
The vector: number[] by default, string when you asked for base64.

Billing

Embeddings are billed per input token at the model's embedding rate, from usage.prompt_tokens. There is no output charge. Before the call, Glexir reserves an estimate of the input cost as a hold and settles it against the real usage when the response arrives. See Credits & billing and Pricing.

Through Batches (/v1/embeddings), embeddings cost half the standard rate.

Errors

StatusCodeWhen
400model_not_foundmodel is missing or is not an embedding model.
400noneinput is missing, or the body is not a JSON object.
402credit_balance_exhaustedYour balance cannot cover the hold.
402spend_limit_exceededThe request would pass a monthly spend limit.
403model_not_pricedThe model is not sold on Glexir.
429rate_limit_exceeded, concurrency_limit_exceededToo many requests per minute, or too many in flight.

See HTTP error codes for the full list.