Skip to content

feat(ui): collect Azure AI Foundry resource on key add#2691

Open
steebchen wants to merge 1 commit into
mainfrom
azure-foundry-resource-validation
Open

feat(ui): collect Azure AI Foundry resource on key add#2691
steebchen wants to merge 1 commit into
mainfrom
azure-foundry-resource-validation

Conversation

@steebchen

@steebchen steebchen commented Jun 15, 2026

Copy link
Copy Markdown
Member

Problem

Adding an Azure AI Foundry provider key in the dashboard failed server-side with:

Azure AI Foundry resource is required - set via provider options or LLM_AZURE_AI_FOUNDRY_RESOURCE env var

The create-provider-key dialog had special-cased handling for azure (Azure OpenAI), google-vertex, custom, and region-based providers — but not for azure-ai-foundry. As a result the dialog only collected the API key and submitted a payload with no options.azure_ai_foundry_resource. Both key validation (validate-provider-key.ts, which calls getProviderEndpoint with skipEnvVars: true) and request-time routing then hit the if (!resource) branch and threw. Because BYOK keys skip env vars, the LLM_AZURE_AI_FOUNDRY_RESOURCE fallback never applied.

Fix

Add the missing form handling for azure-ai-foundry in the create provider key dialog, mirroring the existing Azure OpenAI block:

  • Resource Name — required field, validated client-side against ^[a-zA-Z0-9-]{1,64}$ (same regex the gateway enforces) so the error can no longer reach the server. Written to options.azure_ai_foundry_resource.
  • API Version — optional field defaulting to 2024-05-01-preview, written to options.azure_ai_foundry_api_version.

The requirement is now enforced before submission, so it is no longer possible to create a foundry key that errors at validation/request time for a missing resource.

Testing

  • pnpm format
  • pnpm exec turbo run build --filter=ui

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added Azure AI Foundry as a new provider option for creating API keys.
    • Configure resource name and optional API version settings when selecting Azure AI Foundry provider.
    • Form includes validation for Azure AI Foundry resource name format.

The provider key dialog had no fields for azure-ai-foundry, so keys
were saved without options.azure_ai_foundry_resource. The gateway then
threw "Azure AI Foundry resource is required" at request/validation
time. Add a required Resource Name field (with format validation) and
an optional API Version field, mirroring the Azure OpenAI handling.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

CreateProviderKeyDialog gains support for the azure-ai-foundry provider. Two new state fields track the Azure resource name and API version. On submit, the resource name is validated and both fields are included in the request payload options. On close, both fields are reset. The form conditionally renders these inputs when the azure-ai-foundry provider is selected.

Changes

Azure AI Foundry provider key support in CreateProviderKeyDialog

Layer / File(s) Summary
State initialization and reset
apps/ui/src/components/provider-keys/create-provider-key-dialog.tsx
Adds two useState hooks for azureAiFoundryResource and azureAiFoundryApiVersion; both are reset to defaults when the dialog closes.
Submit-time validation and payload construction
apps/ui/src/components/provider-keys/create-provider-key-dialog.tsx
Validates the resource name (character set and length) and appends azure_ai_foundry_resource plus the optional azure_ai_foundry_api_version to the provider options object on submit.
Conditional form UI
apps/ui/src/components/provider-keys/create-provider-key-dialog.tsx
Renders resource name and API version input fields inside the form only when the selected provider is azure-ai-foundry.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • theopenco/llmgateway#2128: Introduced backend/API/DB support for azure_ai_foundry_resource and azure_ai_foundry_api_version in provider key options, which this PR now surfaces in the creation dialog UI.
🚥 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 clearly and specifically summarizes the main change: adding Azure AI Foundry resource collection to the provider key creation dialog.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch azure-foundry-resource-validation

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.

Caution

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

⚠️ Outside diff range comments (1)
apps/ui/src/components/provider-keys/create-provider-key-dialog.tsx (1)

255-270: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Reset only runs through handleClose, so some close paths retain sensitive form state.

handleClose clears state, but the success path closes via setOpen(false) and onOpenChange={setOpen} does not invoke reset logic. This can keep API key/resource values in state when reopening.

Suggested fix
-const handleClose = () => {
+const handleClose = () => {
 	setOpen(false);
 	setTimeout(() => {
 		setSelectedProvider(preselectedProvider ?? "");
 		setBaseUrl("");
 		setCustomName("");
 		setToken("");
 		setAzureResource("");
 		setAzureApiVersion("2024-10-21");
 		setAzureDeploymentType("ai-foundry");
 		setAzureValidationModel("gpt-4o-mini");
 		setAzureAiFoundryResource("");
 		setAzureAiFoundryApiVersion("2024-05-01-preview");
 		setSelectedRegion("");
 		setGoogleVertexProjectId("");
 	}, 300);
 };
...
-<Dialog open={open} onOpenChange={setOpen}>
+<Dialog
+	open={open}
+	onOpenChange={(nextOpen) => {
+		if (!nextOpen) {
+			handleClose();
+			return;
+		}
+		setOpen(nextOpen);
+	}}
+>
...
-					setOpen(false);
+					handleClose();
🤖 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 `@apps/ui/src/components/provider-keys/create-provider-key-dialog.tsx` around
lines 255 - 270, The handleClose function properly resets form state, but
alternative close paths (such as the success path) call setOpen(false) directly
without triggering the reset logic, leaving sensitive values like API tokens and
resource names in state. Ensure that whenever the dialog closes through any
path, the state reset logic runs. Either modify the onOpenChange handler to
invoke the reset logic when transitioning to open=false, or refactor all close
paths to use handleClose instead of calling setOpen(false) directly, so that
sensitive form fields (setToken, setAzureResource, setBaseUrl, setCustomName,
setGoogleVertexProjectId, setAzureAiFoundryResource, and others) are
consistently cleared when the dialog is closed.
🧹 Nitpick comments (1)
apps/ui/src/components/provider-keys/create-provider-key-dialog.tsx (1)

60-62: ⚡ Quick win

Extract the Azure AI Foundry default API version to one constant (DRY).

"2024-05-01-preview" is repeated in state init, reset, placeholder, and helper text. A single constant prevents drift.

Suggested refactor
+const DEFAULT_AZURE_AI_FOUNDRY_API_VERSION = "2024-05-01-preview";
...
-const [azureAiFoundryApiVersion, setAzureAiFoundryApiVersion] =
-	useState("2024-05-01-preview");
+const [azureAiFoundryApiVersion, setAzureAiFoundryApiVersion] = useState(
+	DEFAULT_AZURE_AI_FOUNDRY_API_VERSION,
+);
...
-setAzureAiFoundryApiVersion("2024-05-01-preview");
+setAzureAiFoundryApiVersion(DEFAULT_AZURE_AI_FOUNDRY_API_VERSION);
...
-placeholder="2024-05-01-preview"
+placeholder={DEFAULT_AZURE_AI_FOUNDRY_API_VERSION}
...
-Azure AI Foundry API version (default: 2024-05-01-preview)
+Azure AI Foundry API version (default: {DEFAULT_AZURE_AI_FOUNDRY_API_VERSION})

As per coding guidelines, “Apply DRY (Don't Repeat Yourself) principles for code reuse.”

Also applies to: 266-267, 456-462

🤖 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 `@apps/ui/src/components/provider-keys/create-provider-key-dialog.tsx` around
lines 60 - 62, Extract the repeated Azure AI Foundry API version string
"2024-05-01-preview" into a single exported constant at the top of the
create-provider-key-dialog.tsx file (e.g.,
DEFAULT_AZURE_AI_FOUNDRY_API_VERSION), then replace all occurrences of this
hardcoded string with references to the constant. This includes the initial
state value in the useState call for azureAiFoundryApiVersion (lines 60-62), the
reset logic around lines 266-267, and the placeholder or helper text usages
around lines 456-462, ensuring a single source of truth for this default value
across the entire component.

Source: Coding guidelines

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

Outside diff comments:
In `@apps/ui/src/components/provider-keys/create-provider-key-dialog.tsx`:
- Around line 255-270: The handleClose function properly resets form state, but
alternative close paths (such as the success path) call setOpen(false) directly
without triggering the reset logic, leaving sensitive values like API tokens and
resource names in state. Ensure that whenever the dialog closes through any
path, the state reset logic runs. Either modify the onOpenChange handler to
invoke the reset logic when transitioning to open=false, or refactor all close
paths to use handleClose instead of calling setOpen(false) directly, so that
sensitive form fields (setToken, setAzureResource, setBaseUrl, setCustomName,
setGoogleVertexProjectId, setAzureAiFoundryResource, and others) are
consistently cleared when the dialog is closed.

---

Nitpick comments:
In `@apps/ui/src/components/provider-keys/create-provider-key-dialog.tsx`:
- Around line 60-62: Extract the repeated Azure AI Foundry API version string
"2024-05-01-preview" into a single exported constant at the top of the
create-provider-key-dialog.tsx file (e.g.,
DEFAULT_AZURE_AI_FOUNDRY_API_VERSION), then replace all occurrences of this
hardcoded string with references to the constant. This includes the initial
state value in the useState call for azureAiFoundryApiVersion (lines 60-62), the
reset logic around lines 266-267, and the placeholder or helper text usages
around lines 456-462, ensuring a single source of truth for this default value
across the entire component.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2203d84f-4574-412e-b13b-a1ca8a3c5d6d

📥 Commits

Reviewing files that changed from the base of the PR and between fad6448 and 983b7f4.

📒 Files selected for processing (1)
  • apps/ui/src/components/provider-keys/create-provider-key-dialog.tsx

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