OpenAI Plugin Deep Dive
Overview
The OpenAI plugin connects Ever Works to OpenAI's API for AI-powered content generation, conversational AI, and text embeddings. It extends the BaseAiProvider abstract class and uses the shared AiOperations utility (which wraps LangChain) to provide a consistent interface across all AI provider plugins. Users supply their own API key to connect directly to OpenAI.
Architecture
The plugin extends BaseAiProvider from @ever-works/plugin/abstract, which provides common AI provider scaffolding including tiered model resolution and configuration merging. The actual API communication is handled by AiOperations from @ever-works/plugin/ai, which wraps LangChain's OpenAI integration.
OpenAiPlugin (extends BaseAiProvider)
|-- AiOperations (@ever-works/plugin/ai)
|-- LangChain (@langchain/openai)
|-- OpenAI REST API
On onLoad, the plugin creates an AiOperations instance with default configuration. Each request then calls resolveConfig(options.settings) to merge user-provided settings (API key, model, temperature) with the defaults, ensuring per-request customisation.
Configuration
Environment Variables
| Variable | Required | Description |
|---|---|---|
| N/A | -- | No environment-variable fallbacks; users provide their own API key |
Settings Schema
interface OpenAiSettings {
apiKey: string; // OpenAI API key (x-secret, user-scoped, required)
defaultModel: string; // Default model for all tasks (default: 'gpt-5.1')
simpleModel: string; // Model for tags, short descriptions (default: 'gpt-5-nano')
mediumModel: string; // Model for listings, summaries (default: 'gpt-4o-mini')
complexModel: string; // Model for full-page generation (default: 'gpt-5.1')
temperature: number; // Response randomness, 0-2 (default: 0.7, hidden)
maxTokens: number; // Max response length (default: 4096, hidden)
baseUrl: string; // API endpoint (default: 'https://api.openai.com/v1', hidden)
}
configurationMode:user-required-- each user must provide their own OpenAI API key.- Model fields use the
x-widget: 'model-select'custom widget for UI rendering. temperature,maxTokens, andbaseUrlare hidden from the default settings UI but available for advanced configuration.
Capabilities
| Capability | Supported | Details |
|---|---|---|
| Structured output | Yes | JSON mode and function calling |
| Streaming | Yes | Server-sent events via async iterables |
| Tool calling | Yes | Function/tool calling for structured extraction |
| Vision | Yes | Image analysis with multimodal models |
| Embeddings | Yes | text-embedding-3-small and others |
| Max context | 128,000 tokens | For supported models like GPT-4o |
API Reference
Chat Completion
| Method | Signature | Description |
|---|---|---|
createChatCompletion | (options: ChatCompletionOptions) => Promise<ChatCompletionResponse> | Single-shot completion |
createStreamingChatCompletion | (options: ChatCompletionOptions) => AsyncIterable<ChatCompletionChunk> | Streaming completion via async generator |
Embeddings
| Method | Signature | Description |
|---|---|---|
createEmbedding | (options: EmbeddingOptions) => Promise<EmbeddingResponse> | Generate text embeddings |