Anvia
Providers

OpenAI

Use OpenAI models through the Anvia provider layer.

Use OpenAIClient when you want OpenAI completion and embedding models through Anvia's normalized runtime.

Environment

export OPENAI_API_KEY=...

Completion Model

import { AgentBuilder } from "@anvia/core";
import { OpenAIClient } from "@anvia/openai";

const client = new OpenAIClient({ apiKey });
const model = client.completionModel("gpt-5");

const agent = new AgentBuilder("support", model)
  .instructions("Answer support questions clearly.")
  .build();

completionModel(...) returns a reusable model instance. Pass it to agents, extractors, or pipeline steps.

Embedding Model

const embeddings = client.embeddingModel("text-embedding-3-small");

Use embedding models for document preprocessing and retrieval.

const embedded = await embedDocuments(embeddings, documents, {
  id: (doc) => doc.id,
  content: (doc) => `${doc.title}\n${doc.body}`,
});

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.