Skip to main content

Models

Model Agnosticism

RadarOS is model-agnostic. You can use OpenAI, Anthropic, Google Gemini, Vertex AI, Ollama, or any custom provider through a unified ModelProvider interface. Switch models with a single line change—no refactoring required.

Unified Interface

All providers implement the same generate() and stream() methods. Your agent code stays identical.

Easy Switching

Swap openai("gpt-4o") for anthropic("claude-sonnet-4-20250514") without touching the rest of your app.

ModelProvider Interface

Every model in RadarOS implements the ModelProvider interface:
interface ModelProvider {
  readonly providerId: string;
  readonly modelId: string;
  generate(messages: ChatMessage[], options?: ModelConfig & { tools?: ToolDefinition[] }): Promise<ModelResponse>;
  stream(messages: ChatMessage[], options?: ModelConfig & { tools?: ToolDefinition[] }): AsyncGenerator<StreamChunk>;
}
providerId
string
Unique identifier for the provider (e.g., "openai", "anthropic").
modelId
string
The specific model identifier (e.g., "gpt-4o", "claude-sonnet-4-20250514").
generate
(messages, options?) => Promise<ModelResponse>
Non-streaming completion. Returns the full response with message, usage, and finish reason.
stream
(messages, options?) => AsyncGenerator<StreamChunk>
Streaming completion. Yields text deltas, tool call chunks, and finish events.

Factory Functions

Use factory functions to create model instances. Each returns a ModelProvider ready for agents, teams, and workflows.
FactoryProviderReturnsConfig
openai(modelId, config?)OpenAIModelProvider{ apiKey?, baseURL? }
anthropic(modelId, config?)AnthropicModelProvider{ apiKey? }
google(modelId, config?)Google GeminiModelProvider{ apiKey? }
vertex(modelId, config?)Google Vertex AIModelProvider{ project?, location?, credentials? }
ollama(modelId, config?)Ollama (local)ModelProvider{ host? } (default: http://localhost:11434)
openaiRealtime(modelId?, config?)OpenAI RealtimeRealtimeProvider{ apiKey?, baseURL? }
googleLive(modelId?, config?)Gemini LiveRealtimeProvider{ apiKey? }

Switching Models in One Line

import { Agent, openai, anthropic, google, vertex, ollama } from "@radaros/core";

// OpenAI
const model = openai("gpt-4o");

// Anthropic
const model = anthropic("claude-sonnet-4-20250514");

// Google Gemini (API key)
const model = google("gemini-2.5-flash");

// Google Vertex AI (GCP auth)
const model = vertex("gemini-2.5-flash", { project: "my-project" });

// Local Ollama (no API key)
const model = ollama("llama3.1");

const agent = new Agent({
  name: "Assistant",
  model,
  instructions: "You are a helpful assistant.",
});

Realtime Providers (Voice)

For voice agents, use the realtime helpers that return a RealtimeProvider:
import { VoiceAgent, openaiRealtime, googleLive } from "@radaros/core";

// OpenAI Realtime
const agent = new VoiceAgent({
  name: "assistant",
  provider: openaiRealtime("gpt-4o-realtime-preview"),
});

// Google Gemini Live
const agent = new VoiceAgent({
  name: "assistant",
  provider: googleLive("gemini-2.5-flash-native-audio-preview-12-2025"),
});

ModelConfig Options

Pass these options to generate() or stream() (or set them on agents):
temperature
number
Sampling temperature (0–2). Lower = more deterministic. Typical: 0.7.
maxTokens
number
Maximum tokens in the completion. Provider-specific limits apply.
topP
number
Nucleus sampling. Alternative to temperature for some providers.
stop
string[]
Stop sequences. Generation stops when any of these strings are produced.
responseFormat
'text' | 'json' | object
Output format: "text" (default), "json" (JSON object), or { type: "json_schema", schema, name? } for structured output.
apiKey
string
Per-request API key override. Use when you need to override the key set at construction (e.g., multi-tenant).

Example: ModelConfig Usage

const response = await model.generate(messages, {
  temperature: 0.3,
  maxTokens: 1024,
  responseFormat: "json",
});

Next Steps