OpenAI
Use OpenAI completion and embedding models with Anvia.
Use @anvia/openai when you want OpenAI completion and embedding models through Anvia's normalized runtime.
Completion Model
import { AgentBuilder } from "@anvia/core";
import { OpenAIClient } from "@anvia/openai";
const client = new OpenAIClient({ apiKey });
const model = client.completionModel("gpt-5.5");
const agent = new AgentBuilder("support", model)
.instructions("Answer support questions clearly.")
.build();
const response = await agent.prompt("Hello!").send();completionModel(...) returns a reusable model instance. Pass it to agents, extractors, or pipeline prompt steps.
Embedding Model
import { embedDocuments } from "@anvia/core/embeddings";
const embeddings = client.embeddingModel("text-embedding-3-small");
const embedded = await embedDocuments(embeddings, documents, {
id: (doc) => doc.id,
content: (doc) => `${doc.title}\n${doc.body}`,
});Use embedding models for document preprocessing and retrieval.
Model Listing
const models = await client.listModels();listModels() fetches OpenAI's /models endpoint and returns a normalized ModelList. When baseUrl is set, the request goes to that OpenAI-compatible endpoint instead.
OpenAI's model list is usually sparse, so fields such as contextLength may be omitted unless the compatible gateway returns them.
Custom Client Options
Use the constructor when credentials or base URL come from your own configuration system.
const client = new OpenAIClient({
apiKey: config.openai.apiKey,
baseUrl: config.openai.baseUrl,
});You can also pass an existing OpenAI SDK client when your app already owns provider setup.
Capabilities
| Capability | Example |
|---|---|
| Completion | client.completionModel("gpt-5.5") |
| Embeddings | client.embeddingModel("text-embedding-3-small") |
| Model listing | client.listModels() |
| Compatible endpoint | new OpenAIClient({ baseUrl, apiKey }) |
Credentials are passed explicitly to the constructor. Anvia does not read environment variables.
