Embeddings and models
Create vector embeddings and discover models supported by a provider endpoint.
Embeddings
import { embedding } from "any-llm-ts";
const result = await embedding({
provider: "openai",
model: "text-embedding-3-small",
input: ["First document", "Second document"],
});
for (const item of result.data) {
console.log(item.index, item.embedding);
}The result normalizes token usage and vector data:
result.provider;
result.model;
result.usage.promptTokens;
result.usage.totalTokens;You can request dimensions and an encoding format when the provider supports them:
await llm.embedding({
model: "text-embedding-3-small",
input: "Hello",
dimensions: 512,
encodingFormat: "float",
});OpenAI-compatible providers send encodingFormat to the SDK. Gemini and Voyage return
floats only, so encodingFormat: "base64" is encoded locally as little-endian float32
bytes (the same layout OpenAI clients decode). float and an unset format keep numeric
vectors. Any other value raises UnsupportedParameterError.
Together embeddings use the same normalized result and usage fields.
List models
import { listModels } from "any-llm-ts";
const models = await listModels({ provider: "openai" });
for (const model of models) {
console.log(model.id, model.ownedBy);
}Or use a reusable client:
const models = await llm.listModels();Some providers expose compatible inference endpoints but no model-list endpoint. Check
metadata.capabilities.listModels before relying on discovery. Azure AI Inference exposes its
configured model through the Foundry /info endpoint. Bedrock lists only foundation models that
support on-demand invocation, plus system-defined inference profile IDs. Cohere follows
next_page_token on the native catalog so later pages, including rerank models, are not dropped.
See batches and reranking for relevance scoring APIs.