Override the API key for individual requests (e.g., multi-tenant apps):
const model = openai("gpt-4o");// Use default key from env/configconst out1 = await agent.run("Hello");// Override for this requestconst 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.
OpenAI’s o-series models (o1, o3) have built-in chain-of-thought reasoning. Configure them via the reasoning config:
import { Agent, openai } from "@radaros/core";const agent = new Agent({ name: "reasoning-agent", model: openai("o3-mini"), instructions: "You are a precise, analytical assistant.", reasoning: { effort: "high", // "low" | "medium" | "high" },});const result = await agent.run( "If a train travels at 120 km/h for 2.5 hours, then slows to 80 km/h for 1.75 hours, what is the total distance?");console.log(result.text);// "The total distance is 440 km. (120 × 2.5 = 300 km) + (80 × 1.75 = 140 km)"
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. RadarOS handles these constraints automatically.
OpenAI supports strict structured output via JSON mode. When using defineTool with Zod schemas, RadarOS automatically uses OpenAI’s strict mode for more reliable function calling:
import { Agent, openai, defineTool } from "@radaros/core";import { z } from "zod";const extractTool = defineTool({ name: "extractContact", description: "Extract contact information from text", parameters: z.object({ name: z.string().describe("Full name"), email: z.string().email().describe("Email address"), phone: z.string().optional().describe("Phone number"), company: z.string().optional().describe("Company name"), }), execute: async (contact) => JSON.stringify(contact),});const agent = new Agent({ name: "extractor", model: openai("gpt-4o"), tools: [extractTool], instructions: "Extract contact info from the user's message using the extractContact tool.",});const result = await agent.run( "Reach out to Jane Doe at jane@acme.com, she works at Acme Corp");
Zod schemas are converted to JSON Schema with strict: true, ensuring the model always returns valid, well-typed arguments.