Skip to content

Add Azure OpenAI provider configuration#558

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

Add Azure OpenAI provider configuration#558
Random-Word wants to merge 5 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 as a supported LLM provider with Azure-specific environment variables and onboarding guidance.
  • Documentation

    • Updated README and example env to document Azure OpenAI and prefer AZURE_OPENAI_API_KEY in detection order; clarified base URL guidance.
  • Compatibility

    • Adjusted provider detection and request behavior to prefer Azure keys for Azure endpoints; token-field handling adapts for newer models.
  • Tests

    • Added tests for 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
Contributor

coderabbitai Bot commented May 20, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds Azure OpenAI support across docs, CLI, config detection (including legacy base-URL parsing), provider wiring (Azure auth/version and GPT‑5 payload key), and tests verifying detection and request/header behavior.

Changes

Azure OpenAI Provider Integration

Layer / File(s) Summary
Configuration documentation and templates
.env.example, README.md
Add Azure OpenAI env var templates and detection-order comment; add Azure row and example entries in README provider table and sample ~/.agentmemory/.env.
CLI onboarding & diagnostics
src/cli.ts, src/cli/doctor-diagnostics.ts, src/cli/onboarding.ts
Add azure-openai onboarding choice, Azure-specific post-setup hints, and include AZURE_OPENAI_API_KEY in doctor/diagnostic key detection and messaging.
Provider detection & config helpers
src/config.ts
Export detectProviderForEnv; add Azure endpoint normalization and deployment derivation (including legacy AZURE_OPENAI_BASE_URL), call detector from loadConfig(), and expand detectLlmProviderKind() to treat valid Azure config as "llm".
OpenAI provider: Azure auth, api-version & payload
src/providers/index.ts, src/providers/openai.ts
Detect Azure baseURL and choose AZURE_OPENAI_API_KEY for Azure endpoints, prefer AZURE_OPENAI_API_VERSION over OPENAI_API_VERSION, and send max_completion_tokens for GPT‑5 models.
Tests for detection and request behavior
test/config-azure-openai.test.ts, test/openai-shared.test.ts
Add tests for provider detection (including legacy base-URL parsing), noop when deployment missing, header/auth behavior (Azure uses api-key and omits Authorization), api-version query param, and GPT‑5 max_completion_tokens.
Summarize noop-provider message
src/functions/summarize.ts
Include AZURE_OPENAI in the provider.name === "noop" error/help string.

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant Config
  participant Provider
  participant AzureAPI
  CLI->>Config: loadConfig()/runOnboarding (env)
  Config->>Provider: detectProviderForEnv -> OpenAI config (azure baseURL/deployment)
  Provider->>AzureAPI: HTTP request (api-key header or Authorization, api-version, payload)
  AzureAPI-->>Provider: response
  Provider-->>CLI: summarize result / error
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 counts tokens, tidy and new,
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 'Add Azure OpenAI provider configuration' clearly and accurately summarizes the main change in the changeset.
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

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
Contributor

@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 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
Contributor

@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
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
Contributor

@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
Ross Story and others added 3 commits May 20, 2026 13:26
Spells out concrete provider env vars in runtime hints and selects AZURE_OPENAI_API_KEY when OPENAI_BASE_URL is Azure-shaped but provided through the environment.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Resolves the OpenAI provider conflict while keeping Azure OpenAI GPT-5 token handling and upstream non-streaming requests.

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

@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.

♻️ Duplicate comments (1)
src/providers/openai.ts (1)

98-99: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Arbitrary Azure deployment names will cause incorrect token field selection.

This issue was previously flagged: Azure deployments can use arbitrary names (e.g., prod-chat, my-gpt5-model) that don't match the ^gpt-5... pattern in usesMaxCompletionTokens(). When a GPT-5 deployment has a non-matching name, the code sends max_tokens instead of max_completion_tokens, causing Azure to reject the request.

The past review comment (lines 98-99) provides a detailed solution using an OPENAI_TOKEN_LIMIT_FIELD environment variable override with validation and fallback to pattern detection.

🤖 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 98 - 99, The token-field selection code
that assigns body[usesMaxCompletionTokens(this.model) ? "max_completion_tokens"
: "max_tokens"] = this.maxTokens will mis-detect Azure GPT-5 deployments with
arbitrary names; change the logic to first check an environment override
(OPENAI_TOKEN_LIMIT_FIELD) with validation (only allow "max_tokens" or
"max_completion_tokens"), use that value if valid, otherwise fall back to the
existing usesMaxCompletionTokens(this.model) pattern detection, and ensure the
chosen field is used when setting body[...] so Azure receives the correct token
field; update any related unit tests for setTokenField behavior and document the
env var.
🤖 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.

Duplicate comments:
In `@src/providers/openai.ts`:
- Around line 98-99: The token-field selection code that assigns
body[usesMaxCompletionTokens(this.model) ? "max_completion_tokens" :
"max_tokens"] = this.maxTokens will mis-detect Azure GPT-5 deployments with
arbitrary names; change the logic to first check an environment override
(OPENAI_TOKEN_LIMIT_FIELD) with validation (only allow "max_tokens" or
"max_completion_tokens"), use that value if valid, otherwise fall back to the
existing usesMaxCompletionTokens(this.model) pattern detection, and ensure the
chosen field is used when setting body[...] so Azure receives the correct token
field; update any related unit tests for setTokenField behavior and document the
env var.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f9ee3f5b-a62b-4030-aef1-51934f4e3a62

📥 Commits

Reviewing files that changed from the base of the PR and between a5dbfb6 and 4dd231f.

📒 Files selected for processing (3)
  • README.md
  • src/cli.ts
  • src/providers/openai.ts
✅ Files skipped from review due to trivial changes (2)
  • src/cli.ts
  • README.md

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