OpenAI provider implementation for Stratix AI Agents.

Requires explicit model configuration - no defaults provided. Supports GPT-4, GPT-3.5, and embeddings models with function calling and streaming.

import { OpenAIProvider, OPENAI_MODELS } from '@stratix/ai-openai';

const provider = new OpenAIProvider({
apiKey: process.env.OPENAI_API_KEY!,
organization: 'org-123',
models: [
* { name: gpt-5.2, pricing: { input: 1.75, output: 14.0 } },
* { name: gpt-5.1, pricing: { input: 1.25, output: 10.0 } }
]
});

const response = await provider.chat({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Hello!', timestamp: new Date() }]
});
const provider = new OpenAIProvider({
apiKey: process.env.OPENAI_API_KEY!,
models: [
{ name: 'gpt-4o', pricing: { input: 6.0, output: 22.0 } },
{ name: 'gpt-5', pricing: { input: 50.0, output: 150.0 } }
]
});
const provider = new OpenAIProvider({
apiKey: process.env.OPENAI_API_KEY!,
models: [
{ name: 'gpt-4o' },
{ name: 'gpt-4o-mini' }
]
});
for await (const chunk of provider.streamChat({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Write a story', timestamp: new Date() }]
})) {
process.stdout.write(chunk.content);
}

Implements

  • LLMProvider

Constructors

Methods

  • Sends a chat completion request

    Parameters

    • params: ChatParams

      Chat parameters

    Returns Promise<ChatResponse>

    The chat completion response

  • Streams a chat completion response

    Parameters

    • params: ChatParams

      Chat parameters

    Returns AsyncIterable<ChatChunk>

    Async iterable of chat chunks

  • Generates embeddings for the given input

    Parameters

    • params: EmbeddingParams

      Embedding parameters

    Returns Promise<EmbeddingResponse>

    The embedding vectors

  • Calculates the cost of a chat completion based on token usage. Returns 0 if no pricing information is available for the model.

    Parameters

    • model: string

      The model used

    • usage: TokenUsage

      Token usage information

    Returns number

    Cost in USD, or 0 if pricing not configured

Properties

name: "openai" = 'openai'

Unique name of the provider (e.g., 'openai', 'anthropic', 'local')

models: string[]

List of supported models