Skip to main content

OpenAI

Use OpenAI’s GPT-4o, GPT-4o-mini, GPT-4-turbo, and o1 models with Agentium through the unified ModelProvider interface.

Setup

Install the OpenAI SDK (required by Agentium for OpenAI support):

Factory

string
required
The OpenAI model identifier.
object
Optional configuration. See Config below.

Supported Models

Pass any valid OpenAI model ID to the factory. New models are supported as soon as the OpenAI API supports them.

Config

string
OpenAI API key. If omitted, uses OPENAI_API_KEY environment variable.
string
Custom API base URL. Use for Azure OpenAI, proxies, or self-hosted endpoints.

Example


Per-Request API Key Override

Override the API key for individual requests (e.g., multi-tenant apps):
The apiKey in RunOpts is passed through to the model’s generate() and stream() calls.

Realtime / Voice

For real-time voice agents, use openaiRealtime() to create an OpenAI Realtime provider:
openaiRealtime() is a shorthand for new OpenAIRealtimeProvider(). It accepts the same config:
Requires: npm install ws See the Voice Agents docs for full details.

Multi-Modal Support

OpenAI GPT-4o models support images, audio, and files as input.

Images

Audio

Files

Files are sent using OpenAI’s native file input type. Both URLs and base64 data are supported:
For base64 files, the provider automatically wraps them as data: URIs for the API.

Reasoning Models (o-series)

OpenAI’s o-series models (o1, o3) have built-in chain-of-thought reasoning. Configure them via the reasoning config:
The effort parameter controls how much computation the model spends on reasoning:
  • "low" — Quick answers, minimal reasoning
  • "medium" — Balanced reasoning
  • "high" — Maximum reasoning depth, best for complex problems
Reasoning models may not support system prompts or streaming depending on the version. Agentium handles these constraints automatically.

Structured Outputs

OpenAI supports strict structured output via JSON mode. When using defineTool with Zod schemas, Agentium automatically uses OpenAI’s strict mode for more reliable function calling:
Zod schemas are converted to JSON Schema with strict: true, ensuring the model always returns valid, well-typed arguments.

Full Example