OpenAI ​
@anvia/openai turns OpenAI APIs into Anvia model contracts. Create the provider client once at the server boundary, choose the model capability the workflow needs, and pass that model into agents, completions, retrieval, or media pipelines.
import { OpenAIClient } from '@anvia/openai'
export const openai = new OpenAIClient({
apiKey: process.env.OPENAI_API_KEY!,
})Choose a model ​
Use completionModel() for agents, direct completions, tools, and structured output.
Use embeddingModel() for retrieval and semantic search.
Use imageGenerationModel(), speechGenerationModel(), and transcriptionModel() for their separate media contracts.
Use listModels() for administrative model inventory.
OpenAI completion models accept api: 'responses' | 'chat' on completionModel({ modelId, api }). api is optional and defaults to 'chat' (Chat Completions); pass 'responses' for the Responses API. baseUrl changes only the endpoint — it does not select the API. The differences are covered in Responses and Chat.
gpt-6-astra is in the known model list with context limits and reasoningEffort controls restricted to its documented set (low, medium, high, xhigh, max).
What the provider owns ​
The package maps Anvia requests, content, tool calls, streams, usage, and media results to and from OpenAI. The application still owns instructions, tool permissions, memory, tenant routing, credential storage, fallback policy, retries, and observability.
Keep those boundaries visible in code. A provider model should be an injected dependency, not the place where product behavior or authorization decisions are hidden.
Start here ​
- Install and configure the client.
- Create a completion model for an agent or direct request.
- Compare Responses and Chat.
- Add only the additional capability models the workflow uses.
- Review the production checklist.