Skip to main content

OpenAI

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

Setup

Install the OpenAI SDK (required by RadarOS for OpenAI support):
npm install openai

Factory

import { openai } from "@radaros/core";

const model = openai("gpt-4o");
modelId
string
required
The OpenAI model identifier.
config
object
Optional configuration. See Config below.

Supported Models

Model IDDescription
gpt-4oLatest flagship model. Fast, capable.
gpt-4o-miniSmaller, faster, cost-effective.
gpt-4-turboHigh capability, larger context.
o1-previewReasoning-optimized model.
Pass any valid OpenAI model ID to the factory. New models are supported as soon as the OpenAI API supports them.

Config

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

Example

const model = openai("gpt-4o", {
  apiKey: process.env.OPENAI_API_KEY,
  baseURL: "https://api.openai.com/v1", // or Azure/proxy URL
});

Per-Request API Key Override

Override the API key for individual requests (e.g., multi-tenant apps):
const model = openai("gpt-4o");

// Use default key from env/config
const out1 = await agent.run("Hello");

// Override for this request
const out2 = await agent.run("Hello", { apiKey: "sk-tenant-specific-key" });
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:
import { VoiceAgent, openaiRealtime } from "@radaros/core";

const agent = new VoiceAgent({
  name: "assistant",
  provider: openaiRealtime("gpt-4o-realtime-preview"),
  instructions: "You are a voice assistant.",
  voice: "alloy",
});
openaiRealtime() is a shorthand for new OpenAIRealtimeProvider(). It accepts the same config:
openaiRealtime("gpt-4o-realtime-preview", {
  apiKey: "sk-...",    // optional, defaults to OPENAI_API_KEY env
  baseURL: "wss://...", // optional custom WebSocket endpoint
});
Requires: npm install ws See the Voice Agents docs for full details.

Full Example

import { Agent, openai } from "@radaros/core";

const agent = new Agent({
  name: "GPT Assistant",
  model: openai("gpt-4o", {
    apiKey: process.env.OPENAI_API_KEY,
  }),
  instructions: "You are a concise, helpful assistant.",
});

const output = await agent.run("What is 2 + 2?");
console.log(output.text);