Skip to content

feat: add Azure OpenAI support to openAIAgent - #1270

Merged
isamu merged 1 commit into
receptron:mainfrom
isamu:feature/azure-openai-support
Jan 27, 2026
Merged

isamu merged 1 commit into
receptron:mainfrom
isamu:feature/azure-openai-support

Conversation

@isamu

@isamu isamu commented Jan 27, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Add Azure OpenAI support to openAIAgent by auto-detecting Azure endpoints
  • When baseURL contains .openai.azure.com, automatically use AzureOpenAI client
  • Add apiVersion config option for Azure API version (defaults to 2025-04-01-preview)

Changes

  • Import AzureOpenAI class from openai package
  • Add apiVersion to OpenAIConfig type
  • Auto-detect Azure endpoints by checking if hostname ends with .openai.azure.com
  • Add apiVersion to inputs and params schema
  • Add run_azure.ts test for Azure OpenAI

Usage

const config = {
  baseURL: "https://your-resource.openai.azure.com/",
  apiKey: process.env.AZURE_OPENAI_API_KEY,
  apiVersion: "2025-04-01-preview", // optional
  model: "gpt-4o", // deployment name
};

Test plan

  • Test with Azure OpenAI endpoint (Sweden Central)
  • Test streaming mode
  • Verify standard OpenAI still works (no regression)

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features
    • Azure OpenAI support: The agent now automatically detects and initializes Azure OpenAI deployments when a baseURL pointing to Azure is configured.
    • API version parameter: Added optional apiVersion configuration for Azure-specific deployment requirements, with a sensible default provided.

✏️ Tip: You can customize this high-level summary in your review settings.

- Import AzureOpenAI class from openai package
- Add apiVersion to OpenAIConfig type
- Auto-detect Azure endpoints by checking if hostname ends with .openai.azure.com
- Use AzureOpenAI client when Azure endpoint is detected
- Add apiVersion to inputs and params schema
- Add run_azure.ts test for Azure OpenAI

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jan 27, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The changes add Azure OpenAI support to the OpenAI agent. An optional apiVersion field is introduced to configuration and input types. The agent detects Azure endpoints via baseURL pattern matching and instantiates AzureOpenAI when applicable, with a default API version. Integration tests validate Azure compatibility with basic, model-specific, and streaming scenarios.

Changes

Cohort / File(s) Summary
Azure OpenAI Integration
llm_agents/openai_agent/src/openai_agent.ts
Imports AzureOpenAI; adds apiVersion?: string field to OpenAIConfig and OpenAIInputs types; extends instantiation logic to detect Azure endpoints (baseURL ending with .openai.azure.com) and conditionally create AzureOpenAI client with endpoint, apiKey, and apiVersion (defaults to "2025-04-01-preview"); updates openaiAgentInfo and mock agent schemas to include apiVersion parameter with description.
Azure Integration Tests
llm_agents/openai_agent/tests/run_azure.ts
New test file validating Azure OpenAI integration; includes environment-based configuration setup with baseURL, apiKey, apiVersion; three test cases covering basic invocation, model-specific execution (gpt-4o), and streaming with token callback to stdout.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Azure clouds now in our sight,
With API versions shining bright,
BaseURL patterns guide the way,
To OpenAI's sibling's bay,
Tokens stream and models soar! 🚀

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add Azure OpenAI support to openAIAgent' directly and accurately summarizes the main change in the changeset—adding Azure OpenAI support to the openAIAgent. It is concise, clear, and specific.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@llm_agents/openai_agent/src/openai_agent.ts`:
- Around line 175-191: The AzureOpenAI client instantiation inside the openai
IIFE omits the dangerouslyAllowBrowser flag causing browser runs (when forWeb is
truthy) to be rejected; update the AzureOpenAI constructor call in the openai
constant to include dangerouslyAllowBrowser: !!forWeb (matching the OpenAI call)
so both paths pass the same browser-allowing option (refer to AzureOpenAI,
OpenAI, openai, baseURL, and forWeb).
🧹 Nitpick comments (4)
llm_agents/openai_agent/tests/run_azure.ts (4)

12-15: Consider using test.skip instead of process.exit(1).

Using process.exit(1) terminates the entire test runner, which prevents other test files from executing. Consider using conditional test skipping or describe.skip for a more test-runner-friendly approach.

Proposed alternative approach
-if (!baseURL || !apiKey) {
-  console.error("AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_API_KEY are required");
-  process.exit(1);
-}
+const skipTests = !baseURL || !apiKey;
+
+if (skipTests) {
+  console.warn("Skipping Azure tests: AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_API_KEY are required");
+}

Then wrap each test:

test("test azure openai", { skip: skipTests }, async () => {
  // test body
});

25-25: Tests use no-op assertions.

assert.deepStrictEqual(true, true) always passes and doesn't validate the API response. Consider adding basic assertions to verify the response structure.

Proposed improvement
-  assert.deepStrictEqual(true, true);
+  assert.ok(res, "Response should not be null");
+  assert.ok(res.choices?.[0]?.message?.content, "Response should contain message content");

22-24: Unsafe nested property access.

The if (res) check doesn't guard against missing nested properties. Consider using optional chaining for safer access.

Proposed fix
   if (res) {
-    console.log(res.choices[0].message["content"]);
+    console.log(res.choices?.[0]?.message?.content);
   }

46-50: Callback type may not match all possible values.

The streamTokenCallback is typed as (token: string), but when dataStream mode is used, the callback receives objects. While this test only uses stream: true, using a more flexible type or unknown with type narrowing would be more robust.

Proposed improvement
     filterParams: {
-      streamTokenCallback: (token: string) => {
-        process.stdout.write(token);
+      streamTokenCallback: (token: unknown) => {
+        if (typeof token === "string") {
+          process.stdout.write(token);
+        }
       },
     },

Comment on lines +175 to +191
const openai = (() => {
if (baseURL) {
try {
const url = new URL(baseURL);
if (url.hostname.endsWith(".openai.azure.com")) {
return new AzureOpenAI({
apiKey,
endpoint: baseURL,
apiVersion: apiVersion ?? "2025-04-01-preview",
});
}
} catch {
// Invalid URL, fall through to standard OpenAI
}
}
return new OpenAI({ apiKey, baseURL, dangerouslyAllowBrowser: !!forWeb });
})();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# Find the file and check imports/type definitions
fd openai_agent.ts -type f | head -5

Repository: receptron/graphai

Length of output: 231


🏁 Script executed:

# Search for AzureOpenAI imports and usage patterns
rg "AzureOpenAI|dangerouslyAllowBrowser" --type ts --context 2

Repository: receptron/graphai

Length of output: 2428


🏁 Script executed:

# Check if there's any type definition or interface information visible
rg "new AzureOpenAI" -A 10 -B 2

Repository: receptron/graphai

Length of output: 1063


🌐 Web query:

Azure OpenAI API versions 2025 official documentation

💡 Result:

Official Microsoft documentation pages that cover Azure OpenAI API versions in 2025:

  • Azure OpenAI REST API preview reference (date-based api-version like 2025-04-01-preview) — includes the versioning scheme and calls out the 2025-04-01-preview data plane inference spec, plus a table showing control plane latest GA 2025-06-01 and latest preview 2025-07-01-preview. [1]
  • Azure OpenAI “v1” REST API reference (path-based /openai/v1/..., optional api-version=v1) — documents the GA v1 endpoints such as POST {endpoint}/openai/v1/chat/completions and notes api-version defaults to v1 if omitted. [2]
  • Azure OpenAI Responses API docs — describes the Responses API and states that v1 API is required for latest features. [3]

Sources: [1] [2] [3]


🏁 Script executed:

# Search for any type definitions or interfaces in the codebase
rg "interface.*AzureOpenAI|type.*AzureOpenAI" -A 5

Repository: receptron/graphai

Length of output: 43


🏁 Script executed:

# Look for node_modules or package.json to understand dependencies
fd package.json | head -5 | xargs cat

Repository: receptron/graphai

Length of output: 5106


🏁 Script executed:

# Search for any azure-related type hints or configuration
rg "AzureOpenAI" -B 5 -A 15 --max-count 3

Repository: receptron/graphai

Length of output: 2769


🌐 Web query:

AzureOpenAI constructor options dangerouslyAllowBrowser openai library

💡 Result:

In the official JavaScript/TypeScript openai library (openai-node), dangerouslyAllowBrowser is a constructor option (default false) that disables running the client in “browser-like” environments to avoid exposing secret credentials in client-side code. If the SDK detects a browser-like runtime and dangerouslyAllowBrowser is not true, it throws an error telling you to enable it only if you understand the risk. [1]

For Azure, the AzureOpenAI constructor accepts dangerouslyAllowBrowser too (along with Azure-specific options). The Azure constructor signature includes: baseURL, apiKey, apiVersion, endpoint, deployment, azureADTokenProvider, dangerouslyAllowBrowser, plus other shared client options. [2]

Azure-specific options are documented under AzureClientOptions (notably endpoint, deployment, apiVersion, and apiKey defaults like process.env['AZURE_OPENAI_API_KEY']). [3] The repo README also directs using AzureOpenAI for Azure usage. [4]

Example (AzureOpenAI in a browser — not recommended):

import { AzureOpenAI } from "openai";

const client = new AzureOpenAI({
  endpoint: "https://YOUR-RESOURCE.azure.openai.com/",
  apiKey: "YOUR_AZURE_OPENAI_KEY",
  apiVersion: "2024-10-01-preview",
  deployment: "YOUR_DEPLOYMENT",
  dangerouslyAllowBrowser: true, // bypass browser guard (risk: key exposure)
});

Strong recommendation: don’t use dangerouslyAllowBrowser with any long-lived secret key; proxy requests through your server instead. [1]

Sources: [1] [2] [3] [4]


Add missing dangerouslyAllowBrowser option to AzureOpenAI client.

The AzureOpenAI client is not configured with dangerouslyAllowBrowser: !!forWeb, while the standard OpenAI client receives this option (line 190). This inconsistency can cause runtime errors when the agent runs in browser environments with forWeb enabled, since AzureOpenAI will reject browser-like execution contexts by default.

Proposed fix
         if (url.hostname.endsWith(".openai.azure.com")) {
           return new AzureOpenAI({
             apiKey,
             endpoint: baseURL,
             apiVersion: apiVersion ?? "2025-04-01-preview",
+            dangerouslyAllowBrowser: !!forWeb,
           });
         }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const openai = (() => {
if (baseURL) {
try {
const url = new URL(baseURL);
if (url.hostname.endsWith(".openai.azure.com")) {
return new AzureOpenAI({
apiKey,
endpoint: baseURL,
apiVersion: apiVersion ?? "2025-04-01-preview",
});
}
} catch {
// Invalid URL, fall through to standard OpenAI
}
}
return new OpenAI({ apiKey, baseURL, dangerouslyAllowBrowser: !!forWeb });
})();
const openai = (() => {
if (baseURL) {
try {
const url = new URL(baseURL);
if (url.hostname.endsWith(".openai.azure.com")) {
return new AzureOpenAI({
apiKey,
endpoint: baseURL,
apiVersion: apiVersion ?? "2025-04-01-preview",
dangerouslyAllowBrowser: !!forWeb,
});
}
} catch {
// Invalid URL, fall through to standard OpenAI
}
}
return new OpenAI({ apiKey, baseURL, dangerouslyAllowBrowser: !!forWeb });
})();
🤖 Prompt for AI Agents
In `@llm_agents/openai_agent/src/openai_agent.ts` around lines 175 - 191, The
AzureOpenAI client instantiation inside the openai IIFE omits the
dangerouslyAllowBrowser flag causing browser runs (when forWeb is truthy) to be
rejected; update the AzureOpenAI constructor call in the openai constant to
include dangerouslyAllowBrowser: !!forWeb (matching the OpenAI call) so both
paths pass the same browser-allowing option (refer to AzureOpenAI, OpenAI,
openai, baseURL, and forWeb).

@isamu
isamu merged commit 86794b8 into receptron:main Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant