Function: embedText()
embedText(
opts):Promise<EmbedTextResult>
Defined in: packages/agentos/src/api/embedText.ts:645
Generates embedding vectors for one or more text inputs using a
provider-agnostic provider:model string.
Resolves credentials via the standard AgentOS provider pipeline, then dispatches to the provider's own embedding endpoint (OpenAI, OpenRouter, Mistral, Requesty, Ollama or Gemini) or to the base URL the caller set; a provider's key goes to no other host. Returns raw float arrays suitable for vector similarity search, clustering, or any downstream ML pipeline.
Parameters
opts
Embedding options including model, input text(s), and optional provider/key overrides.
Returns
Promise<EmbedTextResult>
A promise resolving to the embedding vectors, provider metadata, and token usage.
Throws
When provider resolution fails (missing API key, unknown provider, etc.).
Throws
When the call resolves to a provider with no embeddings embedText can send to (Anthropic, Groq, Together AI, xAI, MiniMax, the image providers and the CLIs), whatever its base URL and with or without a model; its key is not read and no request is sent.
Throws
When the call resolves to a provider agentos does not know and no base URL is set, on the call or on the global default; no request is sent.
Throws
When the embedding API returns a non-2xx status.
Example
import { embedText } from '@framers/agentos';
// Single input
const { embeddings } = await embedText({
provider: 'openai',
model: 'text-embedding-3-small',
input: 'Hello world',
});
console.log(embeddings[0].length); // 1536
// Batch with reduced dimensions
const batch = await embedText({
provider: 'openai',
model: 'text-embedding-3-small',
input: ['Hello', 'World'],
dimensions: 256,
});
console.log(batch.embeddings.length); // 2
console.log(batch.embeddings[0].length); // 256
See
- generateText for text generation.
- resolveModelOption for provider auto-detection behaviour.