Skip to content

Add Azure OpenAI provider configuration#558

Open
Random-Word wants to merge 2 commits into
rohitg00:mainfrom
Random-Word:feature/azure-openai-support
Open

Add Azure OpenAI provider configuration#558
Random-Word wants to merge 2 commits into
rohitg00:mainfrom
Random-Word:feature/azure-openai-support

Conversation

@Random-Word
Copy link
Copy Markdown

@Random-Word Random-Word commented May 20, 2026

Summary

  • Adds Azure OpenAI as an explicit LLM provider configuration path for compression/summarization.
  • Supports Azure OpenAI API-key auth via AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT, and AZURE_OPENAI_DEPLOYMENT.
  • Preserves legacy Azure deployment URL support via AZURE_OPENAI_BASE_URL and AZURE_OPENAI_API_VERSION.
  • Sends max_completion_tokens for GPT-5 deployments such as gpt-5.4-mini, while preserving max_tokens for older models.
  • Updates onboarding, doctor hints, .env.example, and README docs.

Auth scope

This PR supports Azure OpenAI API-key auth only. Microsoft Entra ID / DefaultAzureCredential auth is being developed separately on feature/azure-openai-adc.

Validation

  • npm test -- test/config-azure-openai.test.ts test/openai-shared.test.ts test/cli-doctor-fixes.test.ts test/cli-onboarding.test.ts
  • npx tsdown
  • git diff --check

I did not run a real Azure OpenAI API-key smoke test because no AZURE_OPENAI_API_KEY credentials are present in the process environment or ~/.agentmemory/.env on this machine. The related ADC branch successfully reached the NL2SQL gpt-5.4-mini deployment and exposed the GPT-5 token parameter requirement that is now backported here.

Summary by CodeRabbit

  • New Features

    • Added Azure OpenAI support as an LLM provider (API key, endpoint, deployment, optional API version) with onboarding and CLI guidance.
  • Documentation

    • Updated README and example env to document Azure OpenAI configuration and preferred env-var detection order.
  • Compatibility

    • Improved compatibility with newer model deployments (adjusted token handling and Azure-specific request behavior).
  • Tests

    • Added tests covering Azure detection, key precedence, and request shaping.

Review Change Stack

@vercel
Copy link
Copy Markdown

vercel Bot commented May 20, 2026

Someone is attempting to deploy a commit to the rohitg00's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

📝 Walkthrough

Walkthrough

Adds Azure OpenAI as an LLM provider: docs and .env templates, exported provider detection with endpoint/deployment parsing, OpenAI provider Azure auth/version/payload handling, CLI onboarding/diagnostics updates, and tests validating detection and request behavior.

Changes

Azure OpenAI Provider Integration

Layer / File(s) Summary
Configuration Documentation and Templates
.env.example, README.md
.env.example and README.md document Azure OpenAI environment variables (API key, endpoint, deployment, API version, and optional base URL) with provider table entry and examples.
CLI Onboarding & Diagnostics
src/cli.ts, src/cli/doctor-diagnostics.ts, src/cli/onboarding.ts
Adds azure-openai onboarding option, appends Azure-specific post-setup hints for AZURE_OPENAI_ENDPOINT/AZURE_OPENAI_DEPLOYMENT, and includes AZURE_OPENAI_API_KEY in doctor/diagnostic provider-key detection and messaging.
Azure Provider Detection & Config Helpers
src/config.ts, test/config-azure-openai.test.ts
Exports detectProviderForEnv, adds endpoint normalization and deployment derivation (including legacy AZURE_OPENAI_BASE_URL parsing), uses detector in loadConfig(), and extends detectLlmProviderKind() to treat valid Azure config as "llm". Tests cover detection, legacy URL parsing, disabled-without-deployment, and key precedence in requests.
OpenAI Provider: Azure Key, Version & Payload
src/providers/index.ts, src/providers/openai.ts, test/openai-shared.test.ts
OpenAI provider detects Azure baseURL, prefers AZURE_OPENAI_API_KEY for Azure endpoints, adds AZURE_OPENAI_API_VERSION precedence, and conditionally uses max_completion_tokens for GPT-5 models. Tests assert api-key header usage, api-version query param, and GPT-5 payload shape.
Function Error Message Updates
src/functions/summarize.ts
summarize noop-provider error message includes AZURE_OPENAI among accepted LLM provider keys.

Sequence Diagram(s)

sequenceDiagram
  participant ComponentA
  participant ComponentB
  ComponentA->>ComponentB: observable interaction
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 Azure keys and endpoints in a row,
I hop through configs, gentle and slow,
Detection clicks, requests fly true,
GPT-5 listens, tokens split in two,
Hooray — Azure joins our memory zoo!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding Azure OpenAI provider configuration support across multiple files and modules.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/cli/doctor-diagnostics.ts (1)

89-97: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Require the full Azure config before this diagnostic passes.

Adding AZURE_OPENAI_API_KEY to the generic key list makes realProviderKeys() treat the Azure key alone as sufficient, so no-llm-provider-key can pass even when runtime still falls back to noop because AZURE_OPENAI_ENDPOINT + AZURE_OPENAI_DEPLOYMENT (or AZURE_OPENAI_BASE_URL) are missing. The help text should point at that full Azure tuple too.

🔧 Suggested fix
 export function realProviderKeys(env: Record<string, string>): string[] {
   return PROVIDER_KEY_NAMES.filter((k) => {
     const v = (env[k] ?? "").trim();
     if (!v) return false;
     if (PLACEHOLDER_VALUES.has(v.toLowerCase())) return false;
     // Reject values that are just dots/placeholders like "xxxx-xxxx".
     if (/^x+$/i.test(v.replace(/[-_]/g, ""))) return false;
+    if (k === "AZURE_OPENAI_API_KEY") {
+      const hasBaseUrl = !!(env["AZURE_OPENAI_BASE_URL"] ?? "").trim();
+      const hasEndpoint = !!(env["AZURE_OPENAI_ENDPOINT"] ?? "").trim();
+      const hasDeployment = !!(env["AZURE_OPENAI_DEPLOYMENT"] ?? "").trim();
+      if (!hasBaseUrl && !(hasEndpoint && hasDeployment)) return false;
+    }
     return true;
   });
 }
-        "Set at least one of: ANTHROPIC_API_KEY, AZURE_OPENAI_API_KEY, OPENAI_API_KEY, GEMINI_API_KEY, " +
-        "OPENROUTER_API_KEY, MINIMAX_API_KEY. The daemon picks the first that resolves " +
+        "Set at least one of: ANTHROPIC_API_KEY, OPENAI_API_KEY, GEMINI_API_KEY, GOOGLE_API_KEY, " +
+        "OPENROUTER_API_KEY, MINIMAX_API_KEY, or Azure OpenAI (`AZURE_OPENAI_API_KEY` plus " +
+        "`AZURE_OPENAI_ENDPOINT` + `AZURE_OPENAI_DEPLOYMENT`, or `AZURE_OPENAI_BASE_URL`). The daemon picks the first that resolves " +
         "to a real (non-placeholder) value at startup.",

Also applies to: 201-203

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/cli/doctor-diagnostics.ts` around lines 89 - 97, The diagnostic currently
treats AZURE_OPENAI_API_KEY as a standalone valid provider key; update the logic
so Azure requires the full config tuple instead: remove AZURE_OPENAI_API_KEY
from the generic PROVIDER_KEY_NAMES list and add explicit Azure validation in
realProviderKeys() (or the diagnostic function) that only marks Azure as
available when AZURE_OPENAI_API_KEY is present AND (AZURE_OPENAI_ENDPOINT and
AZURE_OPENAI_DEPLOYMENT) or AZURE_OPENAI_BASE_URL are present; also update the
user-facing help text emitted by the no-llm-provider-key diagnostic to mention
the required Azure tuple (API key + endpoint + deployment/base URL) and mirror
this change in the other diagnostic usages of the provider list (the other
occurrences of PROVIDER_KEY_NAMES / related checks).
src/functions/summarize.ts (1)

247-252: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Return the exact supported config here instead of provider shorthands.

This reason string suggests AZURE_OPENAI, which is not an env var, and it still omits OPENAI_API_KEY. Because users see this on the failure path, it should reference the exact accepted settings, including Azure's endpoint/deployment requirement.

✏️ Suggested wording
-          reason:
-            "No LLM provider key set; Summarize is a no-op. Set ANTHROPIC_API_KEY (or AZURE_OPENAI/GEMINI/OPENROUTER/MINIMAX) in ~/.agentmemory/.env to enable.",
+          reason:
+            "No LLM provider configured; Summarize is a no-op. Set ANTHROPIC_API_KEY, OPENAI_API_KEY, GEMINI_API_KEY/GOOGLE_API_KEY, OPENROUTER_API_KEY, MINIMAX_API_KEY, or AZURE_OPENAI_API_KEY + AZURE_OPENAI_ENDPOINT + AZURE_OPENAI_DEPLOYMENT in ~/.agentmemory/.env to enable.",
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/functions/summarize.ts` around lines 247 - 252, The failure message in
the return object inside summarize (src/functions/summarize.ts) uses shorthand
provider names and omits/incorrectly names env vars; update the reason string to
list the exact accepted environment variables and Azure requirements (for
example: ANTHROPIC_API_KEY, OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT and
AZURE_OPENAI_API_KEY (plus any AZURE_OPENAI_DEPLOYMENT if your code expects a
deployment name), OPENROUTER_API_KEY, GEMINI_API_KEY, MINIMAX_API_KEY) and
mention that Azure requires both endpoint and key (or deployment where
applicable) so users can set the precise config instead of provider shorthands.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/cli.ts`:
- Around line 1462-1465: Update the hint text for the "LLM provider" doctor
entry (the object with name "LLM provider") and the other similar entry around
lines 1898-1900 to list the actual environment variables the CLI reads: include
ANTHROPIC_API_KEY, OPENAI_API_KEY (public OpenAI), AZURE_OPENAI_KEY plus
AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_DEPLOYMENT (for Azure), and the
provider-specific keys such as GEMINI_API_KEY, OPENROUTER_API_KEY, and
MINIMAX_API_KEY; ensure the hint explicitly mentions the required Azure endpoint
and deployment variables rather than the generic AZURE_OPENAI name.

In `@src/cli/onboarding.ts`:
- Around line 63-64: The fallback .env skeleton only seeds AZURE_OPENAI_API_KEY
for the "azure-openai" provider (the array entry with value "azure-openai" /
envKey "AZURE_OPENAI_API_KEY"), so update the code that builds the fallback env
entries to also include the Azure endpoint/base and deployment variables (e.g.,
AZURE_OPENAI_API_BASE or AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_DEPLOYMENT or
AZURE_OPENAI_DEPLOYMENT_NAME) wherever the provider list/skeleton is defined
(the "azure-openai" entry and the corresponding fallback-generation logic
referenced around the other occurrence at lines ~234-238) so users get the full
set of required env vars when selecting Azure OpenAI.

---

Outside diff comments:
In `@src/cli/doctor-diagnostics.ts`:
- Around line 89-97: The diagnostic currently treats AZURE_OPENAI_API_KEY as a
standalone valid provider key; update the logic so Azure requires the full
config tuple instead: remove AZURE_OPENAI_API_KEY from the generic
PROVIDER_KEY_NAMES list and add explicit Azure validation in realProviderKeys()
(or the diagnostic function) that only marks Azure as available when
AZURE_OPENAI_API_KEY is present AND (AZURE_OPENAI_ENDPOINT and
AZURE_OPENAI_DEPLOYMENT) or AZURE_OPENAI_BASE_URL are present; also update the
user-facing help text emitted by the no-llm-provider-key diagnostic to mention
the required Azure tuple (API key + endpoint + deployment/base URL) and mirror
this change in the other diagnostic usages of the provider list (the other
occurrences of PROVIDER_KEY_NAMES / related checks).

In `@src/functions/summarize.ts`:
- Around line 247-252: The failure message in the return object inside summarize
(src/functions/summarize.ts) uses shorthand provider names and omits/incorrectly
names env vars; update the reason string to list the exact accepted environment
variables and Azure requirements (for example: ANTHROPIC_API_KEY,
OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_API_KEY (plus any
AZURE_OPENAI_DEPLOYMENT if your code expects a deployment name),
OPENROUTER_API_KEY, GEMINI_API_KEY, MINIMAX_API_KEY) and mention that Azure
requires both endpoint and key (or deployment where applicable) so users can set
the precise config instead of provider shorthands.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d14a2cea-2270-4107-a783-33d38438826c

📥 Commits

Reviewing files that changed from the base of the PR and between 1838f4d and 04f4509.

📒 Files selected for processing (13)
  • .env.example
  • README.md
  • src/cli.ts
  • src/cli/doctor-diagnostics.ts
  • src/cli/iii-console-install.ts
  • src/cli/onboarding.ts
  • src/config.ts
  • src/functions/summarize.ts
  • src/providers/index.ts
  • src/providers/openai.ts
  • test/config-azure-openai.test.ts
  • test/iii-console-install.test.ts
  • test/openai-shared.test.ts

Comment thread src/cli.ts
Comment on lines 1462 to 1465
name: "LLM provider",
ok: hasLlm,
hint: hasLlm ? undefined : "set ANTHROPIC_API_KEY (or GEMINI/OPENROUTER/MINIMAX) in ~/.agentmemory/.env",
hint: hasLlm ? undefined : "set ANTHROPIC_API_KEY (or AZURE_OPENAI/GEMINI/OPENROUTER/MINIMAX) in ~/.agentmemory/.env",
},
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Spell out the actual Azure/OpenAI env vars in these hints.

These messages now point users at AZURE_OPENAI, which is not a variable the CLI reads, and the doctor hint also drops OPENAI_API_KEY even though public OpenAI is still supported. Since Azure needs endpoint/deployment as well, these should name the concrete settings the runtime actually accepts.

✏️ Suggested wording
-      hint: hasLlm ? undefined : "set ANTHROPIC_API_KEY (or AZURE_OPENAI/GEMINI/OPENROUTER/MINIMAX) in ~/.agentmemory/.env",
+      hint:
+        hasLlm
+          ? undefined
+          : "set ANTHROPIC_API_KEY, OPENAI_API_KEY, GEMINI_API_KEY/GOOGLE_API_KEY, OPENROUTER_API_KEY, MINIMAX_API_KEY, or AZURE_OPENAI_API_KEY + AZURE_OPENAI_ENDPOINT + AZURE_OPENAI_DEPLOYMENT in ~/.agentmemory/.env",
-      "  1. Pick an LLM provider key (ANTHROPIC_API_KEY / AZURE_OPENAI_API_KEY / OPENAI_API_KEY / etc.)",
+      "  1. Pick an LLM provider config (e.g. ANTHROPIC_API_KEY, OPENAI_API_KEY, GEMINI_API_KEY/GOOGLE_API_KEY, or AZURE_OPENAI_API_KEY + AZURE_OPENAI_ENDPOINT + AZURE_OPENAI_DEPLOYMENT)",

Also applies to: 1898-1900

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/cli.ts` around lines 1462 - 1465, Update the hint text for the "LLM
provider" doctor entry (the object with name "LLM provider") and the other
similar entry around lines 1898-1900 to list the actual environment variables
the CLI reads: include ANTHROPIC_API_KEY, OPENAI_API_KEY (public OpenAI),
AZURE_OPENAI_KEY plus AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_DEPLOYMENT (for
Azure), and the provider-specific keys such as GEMINI_API_KEY,
OPENROUTER_API_KEY, and MINIMAX_API_KEY; ensure the hint explicitly mentions the
required Azure endpoint and deployment variables rather than the generic
AZURE_OPENAI name.

Comment thread src/cli/onboarding.ts
Adds Azure OpenAI API-key configuration for LLM compression and summarization, including endpoint/deployment detection, OpenAI provider key precedence, docs, onboarding, doctor hints, and focused tests.

Documents that Microsoft Entra ID / DefaultAzureCredential auth is not implemented yet; this PR supports Azure OpenAI API-key auth only.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Random-Word Random-Word force-pushed the feature/azure-openai-support branch from 04f4509 to fdd8cb8 Compare May 20, 2026 04:26
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/cli/doctor-diagnostics.ts (1)

89-97: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Don’t treat AZURE_OPENAI_API_KEY alone as a valid LLM configuration.

Doctor now reports success when only AZURE_OPENAI_API_KEY is set, but runtime Azure detection also requires endpoint/base URL and deployment/model. This can incorrectly pass diagnostics while provider still resolves to noop.

Suggested fix direction
       check: async () => {
         if (!effects.envFileExists()) {
           return { ok: false, detail: "env file missing (run env-missing fix first)" };
         }
         const env = effects.readEnvFile();
         const real = realProviderKeys(env);
+        const hasAzureKey = real.includes("AZURE_OPENAI_API_KEY");
+        const hasAzureEndpoint =
+          Boolean((env["AZURE_OPENAI_ENDPOINT"] ?? "").trim()) ||
+          Boolean((env["AZURE_OPENAI_BASE_URL"] ?? "").trim());
+        const hasAzureDeployment =
+          Boolean((env["AZURE_OPENAI_DEPLOYMENT"] ?? "").trim()) ||
+          Boolean((env["AZURE_OPENAI_MODEL"] ?? "").trim());
+        const hasUsableAzure = hasAzureKey && hasAzureEndpoint && hasAzureDeployment;
+        const hasOtherProvider = real.some((k) => k !== "AZURE_OPENAI_API_KEY");
+        const ok = hasOtherProvider || hasUsableAzure;
         return {
-          ok: real.length > 0,
-          detail: real.length > 0 ? `found: ${real.join(", ")}` : "no provider key set",
+          ok,
+          detail: ok ? `found: ${real.join(", ")}` : "no provider key set",
         };
       },

Also applies to: 201-203

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/cli/doctor-diagnostics.ts` around lines 89 - 97, The diagnostics
currently treat AZURE_OPENAI_API_KEY in PROVIDER_KEY_NAMES as a standalone valid
LLM credential; update the doctor logic so that Azure is only considered
configured when the API key plus the required Azure-specific settings are
present (e.g., AZURE_OPENAI_ENDPOINT or AZURE_OPENAI_BASE_URL and an
AZURE_OPENAI_DEPLOYMENT or model identifier). Modify the check that uses
PROVIDER_KEY_NAMES and any related validation code (referencing
PROVIDER_KEY_NAMES and the Azure-specific keys) to require the composite Azure
configuration rather than only AZURE_OPENAI_API_KEY, and mirror this change in
the similar validation handled around the other Azure-related checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/providers/index.ts`:
- Around line 100-105: The selection logic for openaiKey can miss an Azure base
supplied via environment; update the useAzureKey computation to also check
process.env.OPENAI_BASE_URL when config.baseURL is falsy (e.g., set useAzureKey
= config.baseURL ? detectAzure(config.baseURL) :
detectAzure(process.env.OPENAI_BASE_URL || "")); then keep the openaiKey
selection logic (azureKey, standardKey) so that when detectAzure reports Azure
you prefer azureKey over standardKey; reference the existing symbols azureKey,
standardKey, useAzureKey, openaiKey, detectAzure and getEnvVar to locate and
change the code.

---

Outside diff comments:
In `@src/cli/doctor-diagnostics.ts`:
- Around line 89-97: The diagnostics currently treat AZURE_OPENAI_API_KEY in
PROVIDER_KEY_NAMES as a standalone valid LLM credential; update the doctor logic
so that Azure is only considered configured when the API key plus the required
Azure-specific settings are present (e.g., AZURE_OPENAI_ENDPOINT or
AZURE_OPENAI_BASE_URL and an AZURE_OPENAI_DEPLOYMENT or model identifier).
Modify the check that uses PROVIDER_KEY_NAMES and any related validation code
(referencing PROVIDER_KEY_NAMES and the Azure-specific keys) to require the
composite Azure configuration rather than only AZURE_OPENAI_API_KEY, and mirror
this change in the similar validation handled around the other Azure-related
checks.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c3ab4006-9620-4545-9107-f667a6e35267

📥 Commits

Reviewing files that changed from the base of the PR and between 04f4509 and fdd8cb8.

📒 Files selected for processing (11)
  • .env.example
  • README.md
  • src/cli.ts
  • src/cli/doctor-diagnostics.ts
  • src/cli/onboarding.ts
  • src/config.ts
  • src/functions/summarize.ts
  • src/providers/index.ts
  • src/providers/openai.ts
  • test/config-azure-openai.test.ts
  • test/openai-shared.test.ts
✅ Files skipped from review due to trivial changes (3)
  • .env.example
  • README.md
  • src/functions/summarize.ts

Comment thread src/providers/index.ts
Comment on lines +100 to +105
const azureKey = getEnvVar("AZURE_OPENAI_API_KEY");
const standardKey = getEnvVar("OPENAI_API_KEY");
const useAzureKey = config.baseURL ? detectAzure(config.baseURL) : false;
const openaiKey = useAzureKey
? azureKey || standardKey
: standardKey || azureKey;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Resolve Azure key selection when OPENAI_BASE_URL is supplied via env only.

useAzureKey currently depends only on config.baseURL. When config.baseURL is unset but env OPENAI_BASE_URL is Azure and both keys are present, this can select the public OpenAI key and fail Azure auth.

Suggested fix
     case "openai": {
       const azureKey = getEnvVar("AZURE_OPENAI_API_KEY");
       const standardKey = getEnvVar("OPENAI_API_KEY");
-      const useAzureKey = config.baseURL ? detectAzure(config.baseURL) : false;
+      const resolvedBaseURL = config.baseURL ?? getEnvVar("OPENAI_BASE_URL");
+      const useAzureKey = resolvedBaseURL ? detectAzure(resolvedBaseURL) : false;
       const openaiKey = useAzureKey
         ? azureKey || standardKey
         : standardKey || azureKey;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/providers/index.ts` around lines 100 - 105, The selection logic for
openaiKey can miss an Azure base supplied via environment; update the
useAzureKey computation to also check process.env.OPENAI_BASE_URL when
config.baseURL is falsy (e.g., set useAzureKey = config.baseURL ?
detectAzure(config.baseURL) : detectAzure(process.env.OPENAI_BASE_URL || ""));
then keep the openaiKey selection logic (azureKey, standardKey) so that when
detectAzure reports Azure you prefer azureKey over standardKey; reference the
existing symbols azureKey, standardKey, useAzureKey, openaiKey, detectAzure and
getEnvVar to locate and change the code.

Uses max_completion_tokens for GPT-5 deployments while preserving max_tokens for existing models. This is required for Azure OpenAI gpt-5.4-mini deployments.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/providers/openai.ts`:
- Around line 91-92: The code picks the token-limit field via
usesMaxCompletionTokens(this.model) which fails for Azure deployments with
arbitrary names; add support for an environment override by reading
process.env.OPENAI_TOKEN_LIMIT_FIELD and, if present and equal to
"max_completion_tokens" or "max_tokens", use that value to choose the body key;
otherwise fall back to the existing usesMaxCompletionTokens(this.model) check.
Update the assignment that currently sets
body[usesMaxCompletionTokens(this.model) ? "max_completion_tokens" :
"max_tokens"] = this.maxTokens to first derive fieldName from
OPENAI_TOKEN_LIMIT_FIELD (validated) or from
usesMaxCompletionTokens(this.model), then set body[fieldName] = this.maxTokens,
and ensure invalid env values are ignored or logged and do not break the
fallback.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8e718de1-4e82-4f95-a23b-a5babe09181c

📥 Commits

Reviewing files that changed from the base of the PR and between fdd8cb8 and 18763de.

📒 Files selected for processing (2)
  • src/providers/openai.ts
  • test/openai-shared.test.ts

Comment thread src/providers/openai.ts
Comment on lines +91 to +92
body[usesMaxCompletionTokens(this.model) ? "max_completion_tokens" : "max_tokens"] =
this.maxTokens;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

`Azure OpenAI chat completions docs:

  1. confirm deployment names can be arbitrary and may differ from underlying model names, and
  2. confirm GPT-5/reasoning chat-completions require max_completion_tokens (not max_tokens).`

💡 Result:

Based on Azure OpenAI and Microsoft Foundry documentation, here is the confirmation for your queries: 1) Deployment names are arbitrary and distinct from underlying model names. When interacting with the Azure OpenAI API, you must use the deployment name you configured in the Azure AI Foundry portal (or Azure OpenAI Studio) rather than the underlying model name [1][2][3]. While documentation examples often use identical names for clarity, your deployment names can follow any naming convention suitable for your use case [2]. 2) GPT-5 family models (including GPT-5, GPT-5.1, and newer versions) require the use of the max_completion_tokens parameter instead of the legacy max_tokens parameter [4][5][6]. Attempting to use max_tokens with these models will result in a BadRequestError indicating that the parameter is unsupported [4][6]. This change is consistent with the updated requirements for reasoning-capable models, where max_completion_tokens is used to limit the combined total of reasoning and response tokens [7][8].

Citations:


🏁 Script executed:

fd -t f "openai.ts" src/

Repository: rohitg00/agentmemory

Length of output: 122


🏁 Script executed:

cat -n src/providers/openai.ts | head -200

Repository: rohitg00/agentmemory

Length of output: 8250


Add environment override for token-limit field selection to handle arbitrary Azure deployment names.

Azure OpenAI deployments use arbitrary names (e.g., prod-chat) as the model identifier, but the code selects between max_tokens and max_completion_tokens by pattern-matching the model name against ^gpt-5.... When a GPT-5 deployment has a non-matching name, the code incorrectly sends max_tokens instead of max_completion_tokens, causing request validation to fail.

Introduce an OPENAI_TOKEN_LIMIT_FIELD environment variable to allow explicit override, with fallback to regex detection:

Proposed implementation
     body[usesMaxCompletionTokens(this.model) ? "max_completion_tokens" : "max_tokens"] =
       this.maxTokens;
+    body[resolveTokenLimitField(this.model)] = this.maxTokens;
 function usesMaxCompletionTokens(model: string): boolean {
   return /^gpt-5(?:[.-]|$)/i.test(model);
 }
+
+function resolveTokenLimitField(
+  model: string,
+): "max_tokens" | "max_completion_tokens" {
+  const override = getEnvVar("OPENAI_TOKEN_LIMIT_FIELD")?.trim().toLowerCase();
+  if (override === "max_tokens" || override === "max_completion_tokens") {
+    return override;
+  }
+  return usesMaxCompletionTokens(model) ? "max_completion_tokens" : "max_tokens";
+}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/providers/openai.ts` around lines 91 - 92, The code picks the token-limit
field via usesMaxCompletionTokens(this.model) which fails for Azure deployments
with arbitrary names; add support for an environment override by reading
process.env.OPENAI_TOKEN_LIMIT_FIELD and, if present and equal to
"max_completion_tokens" or "max_tokens", use that value to choose the body key;
otherwise fall back to the existing usesMaxCompletionTokens(this.model) check.
Update the assignment that currently sets
body[usesMaxCompletionTokens(this.model) ? "max_completion_tokens" :
"max_tokens"] = this.maxTokens to first derive fieldName from
OPENAI_TOKEN_LIMIT_FIELD (validated) or from
usesMaxCompletionTokens(this.model), then set body[fieldName] = this.maxTokens,
and ensure invalid env values are ignored or logged and do not break the
fallback.

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