OpenAI provider
Standalone — usable in any Node project, no
@warlock.js/corerequired.
@warlock.js/ai-openai is the OpenAI provider adapter for
@warlock.js/ai. It turns OpenAI Chat Completions into
a vendor-neutral ModelContract you pass to any agent, workflow, or
supervisor.
It also works with any OpenAI-compatible endpoint — Azure OpenAI,
OpenRouter, local LLM gateways — by passing a custom baseURL.
Install
Section titled “Install”npm install @warlock.js/ai @warlock.js/ai-openaiyarn add @warlock.js/ai @warlock.js/ai-openaipnpm add @warlock.js/ai @warlock.js/ai-openaiConstruct
Section titled “Construct”import { OpenAISDK } from "@warlock.js/ai-openai";
const openai = new OpenAISDK({ apiKey: process.env.OPENAI_API_KEY!,});
// Or route through an OpenAI-compatible endpoint:const openrouter = new OpenAISDK({ apiKey: process.env.OPENROUTER_API_KEY!, baseURL: "https://openrouter.ai/api/v1", provider: "openrouter",});Use as a model
Section titled “Use as a model”const model = openai.model({ name: "gpt-4o-mini" });// Pass to any @warlock.js/ai agent / workflow / supervisor.Use as an embedder
Section titled “Use as an embedder”const embedder = openai.embedder({ name: "text-embedding-3-small" });const { vector } = await embedder.embed("Hello world");Capabilities
Section titled “Capabilities”- Structured output — always on (
response_format: json_schema, strict: true). - Vision — auto-detected for
gpt-4o*,gpt-4-turbo*,gpt-4.1*,o1*,o3*,chatgpt-4o*. Override with thevisionflag. - Streaming — token deltas, tool-call fragments, terminal
done. - Per-model pricing — pass a
pricingmap (USD per million tokens) for a cost breakdown in the agent’s usage report.
For the full surface (pricing config, streaming caveats, embedding
dimension truncation, token counting), see the
setup-openai skill.