Skip to main content

Azure OpenAI

Use OpenAI’s GPT-4o, GPT-4o-mini, o-series, and other models through Azure OpenAI Service. Same OpenAI capabilities, but authenticated with Azure credentials, billed through Azure, and deployed in your own Azure subscription with enterprise compliance.
azureOpenai() uses the openai SDK’s built-in AzureOpenAI class. All OpenAI features — tool calling, streaming, JSON mode, vision, reasoning — work identically to the direct openai() provider.

Setup

The Azure OpenAI provider uses the same OpenAI SDK:
npm install openai

Factory

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

const model = azureOpenai("gpt-4o");
modelId
string
required
The model or deployment name. This is passed as the model parameter to the API.
config
AzureOpenAIConfig
Optional configuration. See Config below.

Supported Models

ModelDescription
gpt-4oLatest flagship model. Vision, audio, tool calling.
gpt-4o-miniSmaller, faster, cost-effective.
gpt-4-turboHigh capability, larger context.
o1-previewReasoning-optimized model.
o3-miniFast reasoning model.
You must create a deployment for each model in the Azure AI Studio portal. The deployment name becomes the modelId (or you can use config.deployment). See Azure OpenAI docs for setup instructions.

Config

apiKey
string
Azure OpenAI API key. Falls back to AZURE_OPENAI_API_KEY env var.
endpoint
string
Azure OpenAI endpoint URL. Falls back to AZURE_OPENAI_ENDPOINT env var. Format: https://<resource-name>.openai.azure.com
deployment
string
Deployment name. Falls back to AZURE_OPENAI_DEPLOYMENT env var. If not set, modelId is used.
apiVersion
string
default:"2024-10-21"
Azure API version. Falls back to AZURE_OPENAI_API_VERSION env var.

Authentication Methods

export AZURE_OPENAI_API_KEY="..."
export AZURE_OPENAI_ENDPOINT="https://my-resource.openai.azure.com"
const model = azureOpenai("gpt-4o");

Method 2: Explicit Config

const model = azureOpenai("gpt-4o", {
  apiKey: "...",
  endpoint: "https://my-resource.openai.azure.com",
  deployment: "my-gpt4o-deployment",
  apiVersion: "2024-10-21",
});

Tool Calling

Tool calling works identically to the direct OpenAI provider:
import { Agent, azureOpenai, defineTool } from "@radaros/core";
import { z } from "zod";

const agent = new Agent({
  name: "azure-assistant",
  model: azureOpenai("gpt-4o"),
  instructions: "You are a helpful assistant.",
  tools: [
    defineTool({
      name: "getWeather",
      description: "Get current weather for a city",
      parameters: z.object({ city: z.string() }),
      execute: async ({ city }) => `${city}: 22°C, Partly Cloudy`,
    }),
  ],
});

const result = await agent.run("What's the weather in London?");
console.log(result.text);

Reasoning Models (o-series)

Azure OpenAI supports the o-series reasoning models with the same reasoning config:
const agent = new Agent({
  name: "analyst",
  model: azureOpenai("o3-mini"),
  instructions: "Solve problems step by step.",
  reasoning: {
    effort: "high",
  },
});

const result = await agent.run("Calculate the compound interest on $10,000 at 5% for 10 years, compounded monthly.");
console.log(result.text);

Multi-Modal Support

Azure OpenAI GPT-4o supports images, audio, and files — same as the direct OpenAI provider:
import { Agent, azureOpenai, type ContentPart } from "@radaros/core";
import { readFileSync } from "node:fs";

const agent = new Agent({
  name: "vision-agent",
  model: azureOpenai("gpt-4o"),
  instructions: "Analyze images and documents.",
});

const imageData = readFileSync("chart.png").toString("base64");
const result = await agent.run([
  { type: "text", text: "What trends does this chart show?" },
  { type: "image", data: imageData, mimeType: "image/png" },
] as ContentPart[]);

Full Example

import { Agent, azureOpenai, CostTracker, defineTool } from "@radaros/core";
import { z } from "zod";

const costTracker = new CostTracker({
  pricing: {
    "gpt-4o": { promptPer1k: 0.0025, completionPer1k: 0.01 },
  },
});

const agent = new Agent({
  name: "enterprise-assistant",
  model: azureOpenai("gpt-4o", {
    endpoint: "https://my-company.openai.azure.com",
    apiVersion: "2024-10-21",
  }),
  instructions: "You are an enterprise assistant for internal use.",
  tools: [
    defineTool({
      name: "searchDocs",
      description: "Search internal documentation",
      parameters: z.object({ query: z.string() }),
      execute: async ({ query }) => `Found 3 results for "${query}"...`,
    }),
  ],
  costTracker,
  maxToolRoundtrips: 3,
});

const result = await agent.run("Find the onboarding docs for new engineers");
console.log(result.text);
console.log(`Cost: $${costTracker.getSummary().totalCost.toFixed(4)}`);

Azure OpenAI vs Direct OpenAI

Featureopenai() (Direct)azureOpenai() (Azure)
AuthOpenAI API keyAzure API key / Azure AD
BillingOpenAI billingAzure billing (consolidated)
Data residencyOpenAI serversYour Azure region
VPC / PrivateNoYes (Private Endpoints)
ComplianceSOC2SOC2, HIPAA, FedRAMP, GDPR
Prompt CachingYesYes
ModelsAll OpenAI modelsModels you deploy

Environment Variables

VariableDescription
AZURE_OPENAI_API_KEYAzure OpenAI API key
AZURE_OPENAI_ENDPOINTAzure OpenAI endpoint URL
AZURE_OPENAI_DEPLOYMENTDefault deployment name
AZURE_OPENAI_API_VERSIONAPI version (default: 2024-10-21)

Cross-References