<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Enterprise Architecture on Robin Su</title><link>https://robinsujob.github.io/tags/enterprise-architecture/</link><description>Recent content in Enterprise Architecture on Robin Su</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Wed, 29 Apr 2026 00:00:00 +0800</lastBuildDate><atom:link href="https://robinsujob.github.io/tags/enterprise-architecture/index.xml" rel="self" type="application/rss+xml"/><item><title>Building Resilient Azure AI Architecture with API Management Gateway (Part 2) — Retry Observability and Alerting</title><link>https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/</link><pubDate>Wed, 29 Apr 2026 00:00:00 +0800</pubDate><guid>https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/</guid><description>&lt;img src="https://robinsujob.github.io/" alt="Featured image of post Building Resilient Azure AI Architecture with API Management Gateway (Part 2) — Retry Observability and Alerting" /&gt;&lt;p&gt;In the previous article &lt;a class="link" href="../azure-apim-ai-resilience/" &gt;&lt;em&gt;Building Resilient Azure AI Architecture with API Management Gateway&lt;/em&gt;&lt;/a&gt;, we built a resilient gateway architecture for multiple Microsoft Foundry resources using Azure API Management — Backend Load Balancing Pool for load distribution, and a &lt;code&gt;retry&lt;/code&gt; policy that automatically switches to healthy instances when backends return 4xx/5xx errors. This mechanism makes backend failures nearly invisible to clients.&lt;/p&gt;
&lt;p&gt;But &amp;ldquo;invisible&amp;rdquo; is precisely the challenge for operations teams: &lt;strong&gt;The Retry mechanism, while protecting clients, also hides the details of intermediate failures.&lt;/strong&gt; When a request goes through 3 retries and ultimately returns 200, operations staff have no way of knowing why the first two attempts failed — was it a 429 rate limit? A 404 deployment not found? Or a 500 server error? Which backend had the issue? What did the error body say?&lt;/p&gt;
&lt;p&gt;This article builds on the previous architecture to achieve complete Retry observability through &lt;strong&gt;Application Insights Diagnostic Logs&lt;/strong&gt;, &lt;strong&gt;without modifying any Policy code&lt;/strong&gt;, helping developers and operations teams:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;📋 &lt;strong&gt;Record detailed information for each Retry failure&lt;/strong&gt; — including the failed backend address, HTTP status code, error response body, and APIM request ID&lt;/li&gt;
&lt;li&gt;🔍 &lt;strong&gt;Reconstruct complete Retry chains via KQL queries&lt;/strong&gt; — using operation_Id to correlate all retry records for the same request&lt;/li&gt;
&lt;li&gt;🔔 &lt;strong&gt;Configure automated alerts&lt;/strong&gt; — notify the operations team via email when Retry failure counts exceed thresholds&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="1-architecture-overview"&gt;1. Architecture Overview
&lt;/h3&gt;&lt;p&gt;This article adds an Application Insights observability layer on top of the APIM + Foundry resilient architecture from the previous article. No changes to existing APIM Policies or Backend configurations are needed — Retry monitoring and alerting are achieved entirely through Diagnostic Logs configuration.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Components from the previous article (unchanged):&lt;/strong&gt;&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Component&lt;/th&gt;
 &lt;th&gt;Role&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Azure API Management&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Unified gateway, executing routing, Retry, and load balancing policies&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Backend Load Balancing Pool&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Pool of multiple Foundry resources, distributing requests via Round-Robin&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;New components in this article:&lt;/strong&gt;&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Component&lt;/th&gt;
 &lt;th&gt;Role&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Application Insights&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Receives APIM native telemetry (&lt;code&gt;requests&lt;/code&gt; / &lt;code&gt;dependencies&lt;/code&gt;), recording details of each Retry backend call&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Log Alert&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Automatically triggers alert notifications based on KQL queries when failure counts exceed thresholds&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Action Group&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Defines alert actions (Email/SMS/Webhook)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Core design principles:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Zero code changes&lt;/strong&gt; — No Policy modifications needed, fully implemented through APIM Diagnostic Logs configuration&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Native Telemetry&lt;/strong&gt; — APIM&amp;rsquo;s &lt;code&gt;dependencies&lt;/code&gt; table automatically records each &lt;code&gt;forward-request&lt;/code&gt; call (including intermediate Retry failures), combined with Backend Response Headers to log and Body bytes configuration to capture error details and Foundry request IDs&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Full Retry chain visibility&lt;/strong&gt; — All Retry attempts for the same request share the same &lt;code&gt;operation_Id&lt;/code&gt;, making it easy to reconstruct the complete retry chain in KQL&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Proactive alerting&lt;/strong&gt; — Log Alert rules automatically detect failure trends and promptly notify the operations team&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The following steps will guide you through building the complete Retry observability solution:&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Section&lt;/th&gt;
 &lt;th&gt;Action&lt;/th&gt;
 &lt;th&gt;Goal&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;2&lt;/td&gt;
 &lt;td&gt;Create Application Insights&lt;/td&gt;
 &lt;td&gt;Set up log storage and query infrastructure&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;3&lt;/td&gt;
 &lt;td&gt;Bind APIM Logger&lt;/td&gt;
 &lt;td&gt;Associate APIM with App Insights&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;4&lt;/td&gt;
 &lt;td&gt;Configure API Diagnostic Logs&lt;/td&gt;
 &lt;td&gt;Enable App Insights logging for the target API, configure Verbosity, Backend Response Headers and Body&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;5&lt;/td&gt;
 &lt;td&gt;Verify Data&lt;/td&gt;
 &lt;td&gt;Confirm Retry records in the dependencies table in App Insights&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;6&lt;/td&gt;
 &lt;td&gt;Configure Alert Rules&lt;/td&gt;
 &lt;td&gt;Create Log Alert + Action Group for automated email notifications&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id="2-create-an-application-insights-instance"&gt;2. Create an Application Insights Instance
&lt;/h3&gt;&lt;p&gt;Create a workspace-based Application Insights instance in the same subscription and region as APIM to receive APIM telemetry data.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2-1) In the Azure Portal search bar, type Application Insights and select the &lt;strong&gt;Application Insights&lt;/strong&gt; service&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="401px" data-flex-grow="167" height="1408" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/2-1-search-application-insights.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/2-1-search-application-insights_hu_acf1cf99e17b7e8b.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/2-1-search-application-insights_hu_61fc3fb0044de7d7.png 1600w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/2-1-search-application-insights.png 2357w" width="2357"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2-2) Click &lt;strong&gt;+ Create&lt;/strong&gt;, fill in the following key configurations and complete creation&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="232px" data-flex-grow="96" height="1442" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/2-2-create-app-insights.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/2-2-create-app-insights_hu_2128c60a8f4cd365.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/2-2-create-app-insights.png 1396w" width="1396"&gt;&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Configuration&lt;/th&gt;
 &lt;th&gt;Recommended Value&lt;/th&gt;
 &lt;th&gt;Description&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;Subscription&lt;/td&gt;
 &lt;td&gt;Same as APIM&lt;/td&gt;
 &lt;td&gt;Keep in the same subscription for easier management&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Resource group&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;apim-ai-hub&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;Same resource group as APIM&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Name&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;ai-hub-app-insight&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;Specify an Application Insights instance name&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Region&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;Japan East&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;Same region as APIM to reduce data transmission latency&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Workspace&lt;/td&gt;
 &lt;td&gt;Default&lt;/td&gt;
 &lt;td&gt;System automatically creates a Log Analytics workspace, or select one you&amp;rsquo;ve created&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;

 &lt;blockquote&gt;
 &lt;p&gt;&lt;strong&gt;📝 Note:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Application Insights is workspace-based, with underlying data stored in a Log Analytics workspace. A workspace is automatically associated during creation — no manual creation needed.&lt;/p&gt;

 &lt;/blockquote&gt;
&lt;h3 id="3-bind-apim-logger"&gt;3. Bind APIM Logger
&lt;/h3&gt;&lt;p&gt;Associate the Application Insights instance created in the previous step with APIM, enabling APIM to send telemetry data to App Insights.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3-1) Navigate to the APIM instance → Left menu &lt;strong&gt;Monitoring&lt;/strong&gt; → &lt;strong&gt;Application Insights&lt;/strong&gt; → Click &lt;strong&gt;+ Add&lt;/strong&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="440px" data-flex-grow="183" height="1451" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/3-1-bind-apim-logger.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/3-1-bind-apim-logger_hu_cf14459b12773009.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/3-1-bind-apim-logger_hu_8a6c1a171bfb24d4.png 1600w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/3-1-bind-apim-logger_hu_77c3530864ca1fd1.png 2400w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/3-1-bind-apim-logger.png 2665w" width="2665"&gt;&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Configuration&lt;/th&gt;
 &lt;th&gt;Recommended Value&lt;/th&gt;
 &lt;th&gt;Description&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;Application Insights instance&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;ai-hub-app-insight&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;Select the Application Insights instance just created&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;☐ Use as default and enable basic logging for all APIs&lt;/td&gt;
 &lt;td&gt;&lt;strong&gt;Unchecked&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;When checked, this Logger becomes the global default, enabling basic logging for all APIs. Can reduce throughput by 40-50% under high traffic (&amp;gt;1000 req/s). Recommended to enable per-API in Step 4&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;☐ Add availability monitor&lt;/td&gt;
 &lt;td&gt;&lt;strong&gt;Unchecked&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;When checked, App Insights periodically validates whether the APIM gateway endpoint is responding, with results displayed in App Insights&amp;rsquo; Availability panel. Not needed for this scenario&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id="4-configure-api-diagnostic-logs"&gt;4. Configure API Diagnostic Logs
&lt;/h3&gt;&lt;p&gt;Enable Application Insights logging for the target AI API, configuring sampling rate, error recording, Backend Response, and other parameters.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;4-1) Navigate to APIM → APIs → Select target API → Switch to &lt;strong&gt;Settings&lt;/strong&gt; tab → Scroll down to &lt;strong&gt;Diagnostic Logs&lt;/strong&gt; area, click Enable&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="370px" data-flex-grow="154" height="1715" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/4-1-api-settings-diagnostic-logs.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/4-1-api-settings-diagnostic-logs_hu_6a90258f10a6380d.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/4-1-api-settings-diagnostic-logs_hu_79eb34df8dfd1a1c.png 1600w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/4-1-api-settings-diagnostic-logs_hu_7fe7c175d99acd5b.png 2400w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/4-1-api-settings-diagnostic-logs.png 2647w" width="2647"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;4-2) Select the &lt;strong&gt;Application Insights&lt;/strong&gt; tab, check &lt;strong&gt;Enable&lt;/strong&gt;, and configure with the following parameters&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="267px" data-flex-grow="111" height="1212" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/4-2-diagnostic-logs-config.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/4-2-diagnostic-logs-config_hu_872049444957e930.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/4-2-diagnostic-logs-config.png 1350w" width="1350"&gt;&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Configuration&lt;/th&gt;
 &lt;th&gt;Recommended Value&lt;/th&gt;
 &lt;th&gt;Description&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Destination&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;ai-hub-app-insight&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;Select the bound App Insights instance. ⚠️ If it shows &amp;ldquo;No App Insights were configured&amp;rdquo;, go back to Step 3 to bind the Logger first&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Sampling (%)&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;100&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;Sampling rate, 100 for full recording (can be adjusted to 25-50 for production)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Always log errors&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;✅ Enable&lt;/td&gt;
 &lt;td&gt;Ensures error requests are not filtered by sampling — all 4xx/5xx are recorded even when Sampling &amp;lt; 100%&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Log client IP address&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;✅ Enable&lt;/td&gt;
 &lt;td&gt;Records caller IP, useful for troubleshooting&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Support custom metrics&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Unchecked&lt;/td&gt;
 &lt;td&gt;Only needed when using the &lt;code&gt;emit-metric&lt;/code&gt; policy, not used in this article&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Verbosity&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;⚠️ &lt;code&gt;Information&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;Controls the logging level for native telemetry, &lt;strong&gt;recommended to select Information or Verbose&lt;/strong&gt; (see explanation below)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Correlation protocol&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;W3C&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;Modern standard, supports cross-service distributed tracing using &lt;code&gt;traceparent&lt;/code&gt; header to correlate frontend and backend requests&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Verbosity Configuration Notes:&lt;/strong&gt;&lt;/p&gt;

 &lt;blockquote&gt;
 &lt;p&gt;&lt;strong&gt;❗ Important:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Verbosity should be set to &lt;code&gt;Information&lt;/code&gt; or &lt;code&gt;Verbose&lt;/code&gt;, not &lt;code&gt;Error&lt;/code&gt;.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Verbosity controls the logging level for the entire request chain&lt;/strong&gt; — successful final requests (200) are treated as information level, failed requests (4xx/5xx) are treated as error level.&lt;/p&gt;

 &lt;/blockquote&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Verbosity&lt;/th&gt;
 &lt;th&gt;Final Request Successful (200)&lt;/th&gt;
 &lt;th&gt;Final Request Failed (4xx/5xx)&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Information&lt;/strong&gt; ✅&lt;/td&gt;
 &lt;td&gt;✅ &lt;code&gt;requests&lt;/code&gt; recorded + ✅ All &lt;code&gt;dependencies&lt;/code&gt; recorded (including intermediate Retry failures)&lt;/td&gt;
 &lt;td&gt;✅ &lt;code&gt;requests&lt;/code&gt; recorded + ✅ All &lt;code&gt;dependencies&lt;/code&gt; recorded&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Error&lt;/strong&gt; ❌&lt;/td&gt;
 &lt;td&gt;❌ &lt;strong&gt;Nothing recorded&lt;/strong&gt; (both request and dependencies are lost)&lt;/td&gt;
 &lt;td&gt;✅ &lt;code&gt;requests&lt;/code&gt; recorded + ✅ Associated &lt;code&gt;dependencies&lt;/code&gt; recorded&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;

 &lt;blockquote&gt;
 &lt;p&gt;&lt;strong&gt;⚠️ Warning:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;When Verbosity=Error:&lt;/strong&gt; If 2 out of 3 Retry attempts fail (404) but the 3rd attempt succeeds (200), the entire request chain &lt;strong&gt;will not appear in any table&lt;/strong&gt; — including those 2 intermediate failed dependency records. This creates a blind spot for Retry observability.&lt;/p&gt;
&lt;p&gt;Selecting &lt;code&gt;Information&lt;/code&gt; ensures that regardless of whether the final result is success or failure, all Retry processes are fully recorded.&lt;/p&gt;

 &lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;Additional settings — Backend Response Configuration:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This is the key configuration for achieving Retry observability. Check &lt;strong&gt;Backend Response&lt;/strong&gt;, configure Headers to log and Body bytes — APIM will include this information in the &lt;code&gt;Properties&lt;/code&gt; field of the &lt;code&gt;dependencies&lt;/code&gt; table.&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Configuration&lt;/th&gt;
 &lt;th&gt;Recommended Value&lt;/th&gt;
 &lt;th&gt;Description&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Headers to log&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;apim-request-id&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;Records the request tracking ID returned by Foundry, used for locating backend requests when submitting support tickets to Microsoft&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Body bytes to log&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;1024&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;Records the first 1KB of response body, capturing error JSON details (e.g., &lt;code&gt;DeploymentNotFound&lt;/code&gt;, &lt;code&gt;Too Many Requests&lt;/code&gt;, etc.)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;

 &lt;blockquote&gt;
 &lt;p&gt;&lt;strong&gt;📝 Note:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Headers to log and Body bytes apply to &lt;strong&gt;all sampled requests&lt;/strong&gt; (including successful ones), without distinguishing between success and failure. This data appears in two App Insights tables:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;requests&lt;/code&gt; table&lt;/strong&gt; — Records the final request returned to the client (frontend perspective)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;dependencies&lt;/code&gt; table&lt;/strong&gt; — Records each &lt;code&gt;forward-request&lt;/code&gt; call (backend perspective, &lt;strong&gt;including each intermediate Retry attempt&lt;/strong&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The &lt;code&gt;dependencies&lt;/code&gt; table is the core data source for Retry observability.&lt;/p&gt;

 &lt;/blockquote&gt;
&lt;p&gt;Click &lt;strong&gt;Save&lt;/strong&gt; to complete the configuration.&lt;/p&gt;

 &lt;blockquote&gt;
 &lt;p&gt;&lt;strong&gt;⚠️ Warning:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Configuration changes take &lt;strong&gt;several minutes&lt;/strong&gt; to propagate to APIM gateway instances. If you test immediately and see no data, please wait 5 minutes before checking.&lt;/p&gt;

 &lt;/blockquote&gt;
&lt;h3 id="5-verify-data"&gt;5. Verify Data
&lt;/h3&gt;&lt;p&gt;After configuration is complete, send a few test requests that will trigger Retry (e.g., call a non-existent model deployment), wait approximately 5 minutes, then verify data in Application Insights.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;5-1) Navigate to Application Insights → Monitoring → ① Logs, ② Switch to Tables view, ③ Find the &lt;code&gt;dependencies&lt;/code&gt; table under the Application Insights category and click Run&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="357px" data-flex-grow="149" height="1691" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/5-1-dependencies-retry-records.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/5-1-dependencies-retry-records_hu_9e2b1c9bfe29f3e2.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/5-1-dependencies-retry-records_hu_2d9636b048ff0ea2.png 1600w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/5-1-dependencies-retry-records_hu_8f8d132eb0a3836c.png 2400w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/5-1-dependencies-retry-records.png 2522w" width="2522"&gt;&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;dependencies&lt;/code&gt; table generates an independent record for &lt;strong&gt;each &lt;code&gt;forward-request&lt;/code&gt; call&lt;/strong&gt; within the &lt;code&gt;retry&lt;/code&gt; block — including intermediate failed Retry attempts and the final successful request. In the results on the right, you can see multiple records pointing to different backends (e.g., &lt;code&gt;ai-hub-swedencentral-02&lt;/code&gt;, &lt;code&gt;ai-hub-eastus2-01&lt;/code&gt;, etc.), all belonging to the same request&amp;rsquo;s Retry chain.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;5-2) Expand a single record to view detailed fields and customDimensions&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="380px" data-flex-grow="158" height="1779" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/5-2-dependency-custom-dimensions.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/5-2-dependency-custom-dimensions_hu_3ec02de0c7557683.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/5-2-dependency-custom-dimensions_hu_da9d711ed95de465.png 1600w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/5-2-dependency-custom-dimensions_hu_4b398a8a1c40a260.png 2400w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/5-2-dependency-custom-dimensions.png 2824w" width="2824"&gt;&lt;/p&gt;
&lt;p&gt;After expanding, you can see the complete information of the dependency record, with key troubleshooting fields highlighted:&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Field&lt;/th&gt;
 &lt;th&gt;Description&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;&lt;code&gt;target&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Full address of the requested backend&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;&lt;code&gt;resultCode&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;HTTP status code&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;code&gt;duration&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;Call duration&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;code&gt;success&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;Whether successful&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;&lt;code&gt;Response-Body&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Success/error response JSON details&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;&lt;code&gt;Response-apim-request-id&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Foundry-side request ID (different for each Retry), useful for submitting troubleshooting tickets&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;

 &lt;blockquote&gt;
 &lt;p&gt;&lt;strong&gt;💡 Tip:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Use &lt;code&gt;operation_Id&lt;/code&gt; to link all Retry records for the same request together, reconstructing the complete retry chain. &lt;code&gt;Response-apim-request-id&lt;/code&gt; can be used to locate specific backend requests when submitting support tickets to Microsoft.&lt;/p&gt;

 &lt;/blockquote&gt;
&lt;h3 id="6-configure-alert-rules"&gt;6. Configure Alert Rules
&lt;/h3&gt;&lt;p&gt;Automatically notify the operations team via email when Retry failure counts exceed thresholds. Alert rules are created on &lt;strong&gt;Application Insights&lt;/strong&gt; (not APIM).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;6-1) Write and verify KQL query on the Logs page&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Navigate to Application Insights → Monitoring → &lt;strong&gt;Logs&lt;/strong&gt;, ① create a new query tab, ② switch to &lt;strong&gt;KQL mode&lt;/strong&gt;, ③ enter the following query and ④ click &lt;strong&gt;Run&lt;/strong&gt; to verify results:&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="375px" data-flex-grow="156" height="1172" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-1-kql-query-in-logs.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-1-kql-query-in-logs_hu_642be3aedad56c4.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-1-kql-query-in-logs_hu_cc2065b85fea4e56.png 1600w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-1-kql-query-in-logs.png 1836w" width="1836"&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;span class="lnt"&gt;4
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;dependencies
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;| where success == false
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;| where resultCode in (&amp;#34;429&amp;#34;, &amp;#34;500&amp;#34;, &amp;#34;502&amp;#34;, &amp;#34;503&amp;#34;, &amp;#34;504&amp;#34;) or toint(resultCode) &amp;gt;= 400
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;| summarize FailureCount = count()
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Adjust the status code filter as needed:&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Scenario&lt;/th&gt;
 &lt;th&gt;Filter Condition&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;All failures&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;where success == false&lt;/code&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Rate limiting only (429)&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;where resultCode == &amp;quot;429&amp;quot;&lt;/code&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;5xx server errors only&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;where toint(resultCode) &amp;gt;= 500&lt;/code&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;429 + 5xx&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;where resultCode == &amp;quot;429&amp;quot; or toint(resultCode) &amp;gt;= 500&lt;/code&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Exclude 404&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;where success == false and resultCode != &amp;quot;404&amp;quot;&lt;/code&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Confirm the query returns the expected FailureCount value.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;6-2) Click the &lt;strong&gt;&lt;code&gt;...&lt;/code&gt;&lt;/strong&gt; menu in the top right → &lt;strong&gt;+ New alert rule&lt;/strong&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="342px" data-flex-grow="142" height="647" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-2-new-alert-rule.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-2-new-alert-rule_hu_cc3b6550b8d4b269.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-2-new-alert-rule.png 922w" width="922"&gt;&lt;/p&gt;
&lt;p&gt;The system will automatically carry over the current KQL query into the Alert rule&amp;rsquo;s Condition configuration.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;6-3) Confirm query and Measurement configuration on the Condition tab&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="267px" data-flex-grow="111" height="1473" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-3-alert-condition-measurement.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-3-alert-condition-measurement_hu_581e6c3507c648d5.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-3-alert-condition-measurement_hu_918929b7c5602c7b.png 1600w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-3-alert-condition-measurement.png 1642w" width="1642"&gt;&lt;/p&gt;
&lt;p&gt;Three key configurations highlighted in the screenshot:&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Annotation&lt;/th&gt;
 &lt;th&gt;Configuration&lt;/th&gt;
 &lt;th&gt;Value&lt;/th&gt;
 &lt;th&gt;Description&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;①&lt;/td&gt;
 &lt;td&gt;&lt;strong&gt;Search query&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;KQL from previous step (auto-populated)&lt;/td&gt;
 &lt;td&gt;Contains &lt;code&gt;success == false&lt;/code&gt; + status code filter + &lt;code&gt;summarize FailureCount = count()&lt;/code&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;②&lt;/td&gt;
 &lt;td&gt;&lt;strong&gt;Measure&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;FailureCount&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;⚠️ Must select &lt;code&gt;FailureCount&lt;/code&gt; (auto-detected from KQL&amp;rsquo;s summarize). If it defaults to &lt;code&gt;Table rows&lt;/code&gt;, switch manually&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;③&lt;/td&gt;
 &lt;td&gt;&lt;strong&gt;Aggregation granularity&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;3 hours&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;Aggregation granularity — aggregates FailureCount within this time range into a single data point for evaluation&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Other settings keep defaults:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Query type&lt;/strong&gt;: Aggregated logs&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Aggregation type&lt;/strong&gt;: Total (sum of FailureCount)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;6-4) Scroll down to configure Alert logic&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="358px" data-flex-grow="149" height="1113" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-4-alert-logic-threshold.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-4-alert-logic-threshold_hu_e8c567663cf0217.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-4-alert-logic-threshold_hu_10bae5d7c67dab9d.png 1600w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-4-alert-logic-threshold.png 1661w" width="1661"&gt;&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Configuration&lt;/th&gt;
 &lt;th&gt;Value&lt;/th&gt;
 &lt;th&gt;Description&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;Threshold type&lt;/td&gt;
 &lt;td&gt;&lt;strong&gt;Static&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Use fixed threshold&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Operator&lt;/td&gt;
 &lt;td&gt;&lt;strong&gt;Greater than&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Trigger when FailureCount exceeds threshold&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Threshold value&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;10&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;Adjust based on business tolerance&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Frequency of evaluation&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;15 minutes&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;Evaluate every 15 minutes&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;

 &lt;blockquote&gt;
 &lt;p&gt;&lt;strong&gt;📝 Note:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;📊 The &lt;strong&gt;Preview&lt;/strong&gt; chart below displays the FailureCount trend and threshold line (dashed), helping you assess whether the threshold setting is reasonable. Areas where the blue solid line exceeds the dashed threshold line indicate periods that would trigger alerts.&lt;/p&gt;
&lt;p&gt;💰 Estimated monthly cost is approximately &lt;strong&gt;$0.50 USD&lt;/strong&gt; (depends on evaluation frequency).&lt;/p&gt;

 &lt;/blockquote&gt;
&lt;p&gt;Click &lt;strong&gt;Next: Actions &amp;gt;&lt;/strong&gt; to proceed.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;6-5) Configure alert actions on the Actions tab&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If the Portal displays the &lt;strong&gt;Use quick actions (preview)&lt;/strong&gt; option (new UI), you can complete Action Group creation directly on this page without creating one separately:&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="387px" data-flex-grow="161" height="1521" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-5-quick-actions-preview.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-5-quick-actions-preview_hu_e24a82964c1c43b7.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-5-quick-actions-preview_hu_32781c44552b9774.png 1600w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-5-quick-actions-preview_hu_ef08194da7af03db.png 2400w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-5-quick-actions-preview.png 2453w" width="2453"&gt;&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Annotation&lt;/th&gt;
 &lt;th&gt;Configuration&lt;/th&gt;
 &lt;th&gt;Description&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;①&lt;/td&gt;
 &lt;td&gt;&lt;strong&gt;Use quick actions (preview)&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Select this option, and the Portal will automatically create an Action Group&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;②&lt;/td&gt;
 &lt;td&gt;&lt;strong&gt;Quick actions panel&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Fill in Action group name, Display name, check Email and enter email address → &lt;strong&gt;Save&lt;/strong&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;③&lt;/td&gt;
 &lt;td&gt;&lt;strong&gt;Email subject&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Custom alert email subject, e.g., &lt;code&gt;AI Hub Retry Alert&lt;/code&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;

 &lt;blockquote&gt;
 &lt;p&gt;&lt;strong&gt;📝 Note:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If the Portal doesn&amp;rsquo;t show the quick actions option (legacy UI), select &lt;strong&gt;Use action groups&lt;/strong&gt; → &lt;strong&gt;+ Create action group&lt;/strong&gt;, and follow steps 6-6 ~ 6-8 below to create one manually.&lt;/p&gt;

 &lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;6-6) Fill in Action Group basic information&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="449px" data-flex-grow="187" height="843" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-6-action-group-basics.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-6-action-group-basics_hu_7bf86028e786560d.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-6-action-group-basics.png 1578w" width="1578"&gt;&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Configuration&lt;/th&gt;
 &lt;th&gt;Value&lt;/th&gt;
 &lt;th&gt;Description&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;Region&lt;/td&gt;
 &lt;td&gt;&lt;strong&gt;Global&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Recommended to select Global for Action Groups&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Action group name&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;ai-hub-retry-alert-action&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;Unique identifier&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Display name&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;AI-Hub-Retry&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;Limited to 12 characters, displayed in notifications&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;6-7) Switch to the Notifications tab and configure email notifications&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="519px" data-flex-grow="216" height="1056" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-7-action-group-notifications.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-7-action-group-notifications_hu_f73f8c20a5afca11.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-7-action-group-notifications_hu_7e3cabadfe52490a.png 1600w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-7-action-group-notifications.png 2286w" width="2286"&gt;&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Configuration&lt;/th&gt;
 &lt;th&gt;Value&lt;/th&gt;
 &lt;th&gt;Description&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;Notification type&lt;/td&gt;
 &lt;td&gt;&lt;strong&gt;Email/SMS message/Push/Voice&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Select notification method&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Name&lt;/td&gt;
 &lt;td&gt;Recipient name&lt;/td&gt;
 &lt;td&gt;Notification recipient identifier&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Email&lt;/td&gt;
 &lt;td&gt;✅ Check and enter email&lt;/td&gt;
 &lt;td&gt;Alert email recipient address&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;

 &lt;blockquote&gt;
 &lt;p&gt;&lt;strong&gt;📝 Note:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The Actions tab allows configuration of richer automated actions (Automation Runbook, Azure Function, Logic App, Webhook, etc.). These are not used in this article — simply skip.&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="421px" data-flex-grow="175" height="816" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-8-action-group-actions.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-8-action-group-actions_hu_c23fee3f12422516.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-8-action-group-actions.png 1434w" width="1434"&gt;&lt;/p&gt;

 &lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;6-8) Switch to the Review + create tab, confirm configuration and click &lt;strong&gt;Create&lt;/strong&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="282px" data-flex-grow="117" height="1348" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-8-action-group-review-create.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-8-action-group-review-create_hu_ed0653e8c8c38395.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-8-action-group-review-create.png 1584w" width="1584"&gt;&lt;/p&gt;
&lt;p&gt;After creation, you&amp;rsquo;ll receive an Azure confirmation email indicating you&amp;rsquo;ve been added to the Action Group:&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="333px" data-flex-grow="138" height="849" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-8-action-group-email-confirm.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-8-action-group-email-confirm_hu_113108bed65e44e4.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-8-action-group-email-confirm.png 1180w" width="1180"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;6-9) Return to the Alert rule&amp;rsquo;s Actions page, confirm the Action Group is associated, and fill in the email subject&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="279px" data-flex-grow="116" height="1351" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-9-alert-actions-email-subject.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-9-alert-actions-email-subject_hu_4deac364262f2076.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-9-alert-actions-email-subject.png 1576w" width="1576"&gt;&lt;/p&gt;
&lt;p&gt;Enter a custom alert email subject in the &lt;strong&gt;Email subject&lt;/strong&gt; field, e.g., &lt;code&gt;AI Hub Retry Alert&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;6-10) Switch to the Details tab and fill in Alert rule basic information&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="282px" data-flex-grow="117" height="1355" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-10-alert-details.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-10-alert-details_hu_dbcef4146041b689.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-10-alert-details.png 1595w" width="1595"&gt;&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Configuration&lt;/th&gt;
 &lt;th&gt;Value&lt;/th&gt;
 &lt;th&gt;Description&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;Severity&lt;/td&gt;
 &lt;td&gt;&lt;strong&gt;2 - Warning&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Alert severity level&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Alert rule name&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;AI-Hub-Alert&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;Alert rule name&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Region&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;Japan East&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;Same region as App Insights&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Identity&lt;/td&gt;
 &lt;td&gt;&lt;strong&gt;Default&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Use default identity&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;6-11) Switch to Review + create to confirm all configurations, click &lt;strong&gt;Create&lt;/strong&gt; to complete&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="218px" data-flex-grow="91" height="1342" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-11-alert-review-create.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-11-alert-review-create_hu_a50e8bf7c746406e.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-11-alert-review-create.png 1222w" width="1222"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;6-12) Verify alert email&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Approximately 15 minutes after creation, when FailureCount exceeds the threshold (10), you&amp;rsquo;ll receive an alert email:&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="326px" data-flex-grow="136" height="1123" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-12-alert-email-notification.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-12-alert-email-notification_hu_633484e3ccfa6737.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-12-alert-email-notification.png 1529w" width="1529"&gt;&lt;/p&gt;
&lt;p&gt;The email contains key information:&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Field&lt;/th&gt;
 &lt;th&gt;Value&lt;/th&gt;
 &lt;th&gt;Description&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;Alert name&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;AI-Hub-Alert&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;Name of the triggered alert rule&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Severity&lt;/td&gt;
 &lt;td&gt;Warning&lt;/td&gt;
 &lt;td&gt;Alert level&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Metric value&lt;/td&gt;
 &lt;td&gt;15&lt;/td&gt;
 &lt;td&gt;Actual FailureCount&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Threshold&lt;/td&gt;
 &lt;td&gt;10&lt;/td&gt;
 &lt;td&gt;Configured threshold&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Fired time&lt;/td&gt;
 &lt;td&gt;Specific time (UTC)&lt;/td&gt;
 &lt;td&gt;When the alert was triggered&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Click &lt;strong&gt;View alert details&lt;/strong&gt; in the email to jump directly to Azure Portal for details; &lt;strong&gt;View search results&lt;/strong&gt; to view the KQL query results that triggered the alert.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;6-13) (Optional) Fine-tune alert parameters&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;After the alert rule is created, navigate to Application Insights → Monitoring → &lt;strong&gt;Alerts&lt;/strong&gt; → &lt;strong&gt;Alert rules&lt;/strong&gt; → Select the corresponding rule → Click the &lt;strong&gt;Edit&lt;/strong&gt; button:&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="712px" data-flex-grow="297" height="606" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-13-alert-edit-button.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-13-alert-edit-button_hu_caf882434c1c375a.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-13-alert-edit-button_hu_3f71a1ceb886ff91.png 1600w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-13-alert-edit-button.png 1800w" width="1800"&gt;&lt;/p&gt;
&lt;p&gt;In the editing page&amp;rsquo;s &lt;strong&gt;Details tab → Advanced options&lt;/strong&gt;, fine-tune further:&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="452px" data-flex-grow="188" height="791" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-13-alert-advanced-mute.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-13-alert-advanced-mute_hu_42206efbc0e4a856.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience-part2/images/6-13-alert-advanced-mute.png 1491w" width="1491"&gt;&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Configuration&lt;/th&gt;
 &lt;th&gt;Description&lt;/th&gt;
 &lt;th&gt;Recommended Value&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Mute actions&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Enter a silent period after triggering, during which no repeat notifications are sent&lt;/td&gt;
 &lt;td&gt;✅ Check&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Mute actions for&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Silent duration — no notifications during this period even if conditions persist&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;3 hours&lt;/code&gt; (adjust as needed)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Automatically resolve alerts&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Automatically change alert status from Fired to Resolved when conditions are no longer met&lt;/td&gt;
 &lt;td&gt;Check as needed&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;

 &lt;blockquote&gt;
 &lt;p&gt;&lt;strong&gt;💡 Tip:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If the evaluation frequency is 15 minutes and Mute is not configured, &lt;strong&gt;an email notification will be sent every 15 minutes&lt;/strong&gt; while alert conditions persist. Configuring Mute prevents repeated notifications after the first alert trigger, avoiding email flooding.&lt;/p&gt;
&lt;p&gt;Additionally, you can adjust &lt;strong&gt;Aggregation granularity&lt;/strong&gt;, &lt;strong&gt;Threshold value&lt;/strong&gt;, &lt;strong&gt;Frequency of evaluation&lt;/strong&gt;, and other parameters on the editing page to optimize alert sensitivity.&lt;/p&gt;

 &lt;/blockquote&gt;
&lt;h3 id="7-appendix-advanced-kql-queries-and-client-ip-configuration-optional"&gt;7. Appendix: Advanced KQL Queries and Client IP Configuration (Optional)
&lt;/h3&gt;&lt;h4 id="7-1-enable-real-client-ip-recording"&gt;7-1) Enable Real Client IP Recording
&lt;/h4&gt;&lt;p&gt;Application Insights &lt;strong&gt;does not store client IP addresses by default&lt;/strong&gt; (privacy protection), and the &lt;code&gt;client_IP&lt;/code&gt; field displays as &lt;code&gt;0.0.0.0&lt;/code&gt;. Disable IP masking via CLI to record real IPs:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;span class="lnt"&gt;4
&lt;/span&gt;&lt;span class="lnt"&gt;5
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;az resource update &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --resource-group &amp;lt;resource-group&amp;gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --name &amp;lt;app-insights-name&amp;gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --resource-type &lt;span class="s2"&gt;&amp;#34;Microsoft.Insights/components&amp;#34;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --set properties.DisableIpMasking&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
 &lt;blockquote&gt;
 &lt;p&gt;&lt;strong&gt;⚠️ Warning:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Disabling IP masking will record real client IP addresses. Please ensure this complies with your organization&amp;rsquo;s privacy requirements.&lt;/p&gt;
&lt;p&gt;📖 Reference: Geolocation and IP address handling: &lt;a class="link" href="https://learn.microsoft.com/azure/azure-monitor/app/ip-collection" target="_blank" rel="noopener"
 &gt;https://learn.microsoft.com/azure/azure-monitor/app/ip-collection&lt;/a&gt;&lt;/p&gt;

 &lt;/blockquote&gt;
&lt;h4 id="7-2-correlate-client-ip-with-retry-failure-records"&gt;7-2) Correlate Client IP with Retry Failure Records
&lt;/h4&gt;&lt;p&gt;The &lt;code&gt;dependencies&lt;/code&gt; table itself does not contain client IP (it records APIM → backend outbound calls). You need to JOIN with the &lt;code&gt;requests&lt;/code&gt; table via &lt;code&gt;operation_Id&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;span class="lnt"&gt;11
&lt;/span&gt;&lt;span class="lnt"&gt;12
&lt;/span&gt;&lt;span class="lnt"&gt;13
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;dependencies
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;| where timestamp &amp;gt; ago(1h)
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;| where success == false
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;| join kind=leftouter (
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; requests 
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; | project operation_Id, req_client_IP = client_IP
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; ) on operation_Id
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;| project timestamp, target, resultCode, 
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; ClientIP = req_client_IP,
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; ErrorBody = tostring(customDimensions[&amp;#34;Response-Body&amp;#34;]),
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; APIMRequestId = tostring(customDimensions[&amp;#34;Response-apim-request-id&amp;#34;]),
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; operation_Id
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;| order by timestamp desc
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
 &lt;blockquote&gt;
 &lt;p&gt;&lt;strong&gt;📝 Note:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Both &lt;code&gt;requests&lt;/code&gt; and &lt;code&gt;dependencies&lt;/code&gt; tables have a &lt;code&gt;client_IP&lt;/code&gt; field, but with different meanings:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;requests.client_IP&lt;/code&gt;&lt;/strong&gt; — IP of the client calling APIM (real client)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;dependencies.client_IP&lt;/code&gt;&lt;/strong&gt; — APIM gateway&amp;rsquo;s outbound IP (not the client)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When JOINing, use renaming (e.g., &lt;code&gt;req_client_IP&lt;/code&gt;) to avoid field conflicts.&lt;/p&gt;

 &lt;/blockquote&gt;
&lt;h4 id="7-3-more-useful-kql-queries"&gt;7-3) More Useful KQL Queries
&lt;/h4&gt;&lt;p&gt;&lt;strong&gt;Reconstruct complete Retry chain by operation_Id (including the successful attempt):&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;span class="lnt"&gt;4
&lt;/span&gt;&lt;span class="lnt"&gt;5
&lt;/span&gt;&lt;span class="lnt"&gt;6
&lt;/span&gt;&lt;span class="lnt"&gt;7
&lt;/span&gt;&lt;span class="lnt"&gt;8
&lt;/span&gt;&lt;span class="lnt"&gt;9
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;dependencies
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;| where timestamp &amp;gt; ago(1h)
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;| summarize CallCount = count(),
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; Backends = make_list(target),
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; StatusCodes = make_list(resultCode),
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; Durations = make_list(duration)
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; by operation_Id
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;| where CallCount &amp;gt; 1
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;| order by CallCount desc
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Failure trend chart:&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;span class="lnt"&gt;4
&lt;/span&gt;&lt;span class="lnt"&gt;5
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;dependencies
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;| where timestamp &amp;gt; ago(24h)
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;| where success == false
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;| summarize FailureCount = count() by bin(timestamp, 5m), target
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;| render timechart
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;strong&gt;For alerting (grouped by backend + status code):&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;span class="lnt"&gt;4
&lt;/span&gt;&lt;span class="lnt"&gt;5
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;dependencies
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;| where timestamp &amp;gt; ago(2h)
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;| where success == false
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;| summarize FailureCount = count() by target, resultCode
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;| where FailureCount &amp;gt; 0
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;h3 id="summary"&gt;Summary
&lt;/h3&gt;&lt;p&gt;Through this article&amp;rsquo;s implementation, we&amp;rsquo;ve built a complete Retry observability solution on top of the resilient gateway architecture from the previous article:&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Capability&lt;/th&gt;
 &lt;th&gt;Implementation&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Each Retry failure recorded&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;APIM native &lt;code&gt;dependencies&lt;/code&gt; table automatically records each &lt;code&gt;forward-request&lt;/code&gt; call&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Error Body recording&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Backend Response Body bytes=1024, error JSON details appear in Properties&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Request tracking IDs&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;operation_Id&lt;/code&gt; (unchanged across Retries) + &lt;code&gt;Response-apim-request-id&lt;/code&gt; (Foundry-side ID)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Call duration&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Native &lt;code&gt;DurationMs&lt;/code&gt; field, precise to milliseconds&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;KQL queries&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Support aggregation analysis by backend, status code, and time dimensions&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Automated alerting&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Log Alert rules + Action Group email notifications&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;For users who have already deployed the resilient architecture from the previous article, this article &lt;strong&gt;requires no Policy code changes&lt;/strong&gt; — complete Retry observability is achieved solely through APIM Diagnostic Logs configuration (binding App Insights + &lt;strong&gt;setting Verbosity to Information&lt;/strong&gt; + enabling Backend Response Headers/Body).&lt;/p&gt;
&lt;p&gt;Those errors hidden by the Retry mechanism are now clearly recorded in Application Insights&amp;rsquo; &lt;code&gt;dependencies&lt;/code&gt; table, ready for operations staff to review and address.&lt;/p&gt;
&lt;h3 id="references"&gt;References
&lt;/h3&gt;&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Document&lt;/th&gt;
 &lt;th&gt;Link&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;How to integrate Azure API Management with Azure Application Insights&lt;/td&gt;
 &lt;td&gt;&lt;a class="link" href="https://learn.microsoft.com/azure/api-management/api-management-howto-app-insights" target="_blank" rel="noopener"
 &gt;https://learn.microsoft.com/azure/api-management/api-management-howto-app-insights&lt;/a&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Diagnostic - Create Or Update REST API&lt;/td&gt;
 &lt;td&gt;&lt;a class="link" href="https://learn.microsoft.com/rest/api/apimanagement/diagnostic/create-or-update" target="_blank" rel="noopener"
 &gt;https://learn.microsoft.com/rest/api/apimanagement/diagnostic/create-or-update&lt;/a&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Application Insights telemetry data model&lt;/td&gt;
 &lt;td&gt;&lt;a class="link" href="https://learn.microsoft.com/azure/azure-monitor/app/data-model-complete" target="_blank" rel="noopener"
 &gt;https://learn.microsoft.com/azure/azure-monitor/app/data-model-complete&lt;/a&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Geolocation and IP address handling (IP masking)&lt;/td&gt;
 &lt;td&gt;&lt;a class="link" href="https://learn.microsoft.com/azure/azure-monitor/app/ip-collection" target="_blank" rel="noopener"
 &gt;https://learn.microsoft.com/azure/azure-monitor/app/ip-collection&lt;/a&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Subscriptions in Azure API Management&lt;/td&gt;
 &lt;td&gt;&lt;a class="link" href="https://learn.microsoft.com/azure/api-management/api-management-subscriptions" target="_blank" rel="noopener"
 &gt;https://learn.microsoft.com/azure/api-management/api-management-subscriptions&lt;/a&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Tutorial: Create a log search alert for an Azure resource&lt;/td&gt;
 &lt;td&gt;&lt;a class="link" href="https://learn.microsoft.com/azure/azure-monitor/alerts/tutorial-log-alert" target="_blank" rel="noopener"
 &gt;https://learn.microsoft.com/azure/azure-monitor/alerts/tutorial-log-alert&lt;/a&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Create and manage action groups&lt;/td&gt;
 &lt;td&gt;&lt;a class="link" href="https://learn.microsoft.com/azure/azure-monitor/alerts/action-groups" target="_blank" rel="noopener"
 &gt;https://learn.microsoft.com/azure/azure-monitor/alerts/action-groups&lt;/a&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Kusto Query Language (KQL) overview&lt;/td&gt;
 &lt;td&gt;&lt;a class="link" href="https://learn.microsoft.com/azure/data-explorer/kusto/query/" target="_blank" rel="noopener"
 &gt;https://learn.microsoft.com/azure/data-explorer/kusto/query/&lt;/a&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Performance implications and log sampling&lt;/td&gt;
 &lt;td&gt;&lt;a class="link" href="https://learn.microsoft.com/azure/api-management/api-management-howto-app-insights#performance-implications-and-log-sampling" target="_blank" rel="noopener"
 &gt;https://learn.microsoft.com/azure/api-management/api-management-howto-app-insights#performance-implications-and-log-sampling&lt;/a&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Azure Monitor pricing&lt;/td&gt;
 &lt;td&gt;&lt;a class="link" href="https://azure.microsoft.com/pricing/details/monitor/" target="_blank" rel="noopener"
 &gt;https://azure.microsoft.com/pricing/details/monitor/&lt;/a&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;</description></item><item><title>Building Resilient Azure AI Architecture with API Management Gateway</title><link>https://robinsujob.github.io/p/azure-apim-ai-resilience/</link><pubDate>Fri, 03 Apr 2026 00:00:00 +0800</pubDate><guid>https://robinsujob.github.io/p/azure-apim-ai-resilience/</guid><description>&lt;img src="https://robinsujob.github.io/" alt="Featured image of post Building Resilient Azure AI Architecture with API Management Gateway" /&gt;&lt;p&gt;As enterprise demand for AI capabilities grows, organizations are deeply integrating Microsoft Foundry model services into core business systems. As AI moves from experimentation to production, &lt;strong&gt;high availability, elastic scaling, unified governance, and security controls&lt;/strong&gt; become unavoidable themes.&lt;/p&gt;
&lt;p&gt;In production, a single subscription instance fails to meet requirements for &lt;strong&gt;continuity, stability, and throughput&lt;/strong&gt;. A mature architecture consolidates resources across subscriptions, &lt;strong&gt;aggregating AI quotas&lt;/strong&gt; to maximize throughput, with traffic distribution, automatic failover, and unified access control.&lt;/p&gt;
&lt;p&gt;Azure API Management (APIM), as Azure&amp;rsquo;s native API gateway, is naturally suited for this role. By deploying APIM as the unified entry point, combined with the following capabilities, we can build an &lt;strong&gt;enterprise-grade, highly resilient AI architecture&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;🔀 &lt;strong&gt;Backend Load Balancing Pool&lt;/strong&gt; — Load balancing and failover across subscriptions and Foundry instances, aggregating distributed quotas&lt;/li&gt;
&lt;li&gt;🔐 &lt;strong&gt;Managed Identity&lt;/strong&gt; — Zero-key secure authentication between APIM and backend AI services&lt;/li&gt;
&lt;li&gt;🛡️ &lt;strong&gt;Unified API Governance&lt;/strong&gt; — Request routing, traffic control, log auditing, and policy management at the gateway layer&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This article walks through a complete hands-on example: from resource deployment and identity configuration to load balancing policies, building a production-ready resilient gateway architecture targeting multiple Microsoft Foundry resources.&lt;/p&gt;
&lt;h2 id="architecture-overview"&gt;Architecture Overview
&lt;/h2&gt;&lt;p&gt;&lt;img alt="1-Architecture" class="gallery-image" data-flex-basis="289px" data-flex-grow="120" height="683" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/1-Architecture-en.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/1-Architecture-en_hu_10ff4595295ffe34.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience/images/1-Architecture-en.png 823w" width="823"&gt;&lt;/p&gt;
&lt;p&gt;This architecture uses a &lt;strong&gt;centralized API gateway + multi-subscription backend pattern&lt;/strong&gt;, with APIM as the unified entry point, distributing requests round-robin to Foundry instances across multiple subscriptions and regions.&lt;/p&gt;
&lt;p&gt;Core design principles:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Unified Entry Point&lt;/strong&gt; — Clients only need the APIM endpoint; the pool uses Round-Robin by default&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Simplified Security Authentication&lt;/strong&gt; — Zero-key communication via Managed Identity; clients only need a single API Key&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cross-Subscription Quota Aggregation&lt;/strong&gt; — Aggregate quotas across subscriptions into a unified capacity pool&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cross-Region Disaster Recovery&lt;/strong&gt; — APIM automatically routes to healthy instances when a region becomes unavailable&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;APIM&amp;rsquo;s Policy engine also provides flexible traffic control:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Pinned Routing&lt;/strong&gt; — via &lt;code&gt;X-AI-Foundry-Target&lt;/code&gt; header&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Auto Failover&lt;/strong&gt; — Auto-retry with exponential backoff on 4xx/5xx&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Request Tracing&lt;/strong&gt; — &lt;code&gt;X-AI-Foundry-Backend&lt;/code&gt; response header for tracing&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Architecture setup steps:&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Section&lt;/th&gt;
 &lt;th&gt;Action&lt;/th&gt;
 &lt;th&gt;Goal&lt;/th&gt;
 &lt;th&gt;Platform&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;1&lt;/td&gt;
 &lt;td&gt;Create APIM instance&lt;/td&gt;
 &lt;td&gt;Set up the unified gateway entry point and enable Managed Identity&lt;/td&gt;
 &lt;td&gt;Azure Portal&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;2&lt;/td&gt;
 &lt;td&gt;Create Foundry resources&lt;/td&gt;
 &lt;td&gt;Build the backend resource pool across multiple subscriptions and regions&lt;/td&gt;
 &lt;td&gt;Azure Portal&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;3&lt;/td&gt;
 &lt;td&gt;Deploy AI models&lt;/td&gt;
 &lt;td&gt;Enable AI service capability on backend resources (using Sora2 as an example)&lt;/td&gt;
 &lt;td&gt;Foundry Portal&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;4&lt;/td&gt;
 &lt;td&gt;Configure RBAC&lt;/td&gt;
 &lt;td&gt;Grant APIM Managed Identity permission to access backends&lt;/td&gt;
 &lt;td&gt;Azure Portal&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;5&lt;/td&gt;
 &lt;td&gt;Configure Backend + LB Pool&lt;/td&gt;
 &lt;td&gt;Register backends and create the load balancing pool&lt;/td&gt;
 &lt;td&gt;Azure Portal (APIM)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;6&lt;/td&gt;
 &lt;td&gt;Create API + Policy&lt;/td&gt;
 &lt;td&gt;Define the API entry point and configure routing and failover&lt;/td&gt;
 &lt;td&gt;Azure Portal (APIM)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;7&lt;/td&gt;
 &lt;td&gt;Test and validate&lt;/td&gt;
 &lt;td&gt;Verify load balancing and pinned backend routing&lt;/td&gt;
 &lt;td&gt;curl / Postman&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;hr&gt;
&lt;h2 id="create-apim-instance"&gt;Create APIM Instance
&lt;/h2&gt;&lt;p&gt;Create an API Management instance in Azure Portal, selecting v2 Tier, and enable &lt;strong&gt;System Assigned Managed Identity&lt;/strong&gt; during creation.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Portal Steps:&lt;/strong&gt; Search &lt;code&gt;API Management Service&lt;/code&gt; → + Create → Fill in configuration → Enable on the Managed identity tab → Review + install&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="185px" data-flex-grow="77" height="1506" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/2-3-basics-config.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/2-3-basics-config_hu_14e08ccbc5610987.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience/images/2-3-basics-config.png 1163w" width="1163"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="475px" data-flex-grow="198" height="562" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/2-4-managed-identity.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/2-4-managed-identity_hu_4043f457949cc774.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience/images/2-4-managed-identity.png 1114w" width="1114"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;CLI Alternative:&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;span class="lnt"&gt;11
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;az rest --method PUT &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --url &lt;span class="s2"&gt;&amp;#34;https://management.azure.com/subscriptions/&amp;lt;subscription-id&amp;gt;/resourceGroups/&amp;lt;resource-group&amp;gt;/providers/Microsoft.ApiManagement/service/&amp;lt;apim-name&amp;gt;?api-version=2024-05-01&amp;#34;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --body &lt;span class="s1"&gt;&amp;#39;{
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s1"&gt; &amp;#34;location&amp;#34;: &amp;#34;&amp;lt;region&amp;gt;&amp;#34;,
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s1"&gt; &amp;#34;sku&amp;#34;: { &amp;#34;name&amp;#34;: &amp;#34;&amp;lt;BasicV2|StandardV2|PremiumV2&amp;gt;&amp;#34;, &amp;#34;capacity&amp;#34;: 1 },
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s1"&gt; &amp;#34;identity&amp;#34;: { &amp;#34;type&amp;#34;: &amp;#34;SystemAssigned&amp;#34; },
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s1"&gt; &amp;#34;properties&amp;#34;: {
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s1"&gt; &amp;#34;publisherName&amp;#34;: &amp;#34;&amp;lt;organization-name&amp;gt;&amp;#34;,
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s1"&gt; &amp;#34;publisherEmail&amp;#34;: &amp;#34;&amp;lt;admin-email&amp;gt;&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s1"&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s1"&gt; }&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;strong&gt;After Creation:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Status: &lt;strong&gt;Online&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Record &lt;strong&gt;Gateway URL&lt;/strong&gt; (for example: &lt;code&gt;https://&amp;lt;apim-name&amp;gt;.azure-api.net&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Record the Managed Identity &lt;strong&gt;Object (principal) ID&lt;/strong&gt; for RBAC&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="728px" data-flex-grow="303" height="644" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/2-6-apim-dashboard.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/2-6-apim-dashboard_hu_2b05d081fb5fa317.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience/images/2-6-apim-dashboard_hu_e21fb9797c99f7a2.png 1600w, https://robinsujob.github.io/p/azure-apim-ai-resilience/images/2-6-apim-dashboard.png 1956w" width="1956"&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="create-foundry-resources"&gt;Create Foundry Resources
&lt;/h2&gt;&lt;p&gt;Create Foundry resources across multiple subscriptions and regions, each with a corresponding project.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Portal Steps:&lt;/strong&gt; Search &lt;code&gt;Microsoft Foundry&lt;/code&gt; → Create a resource → Fill in Subscription / Region / Name / Project name → Create&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="220px" data-flex-grow="91" height="1512" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/3-3-create-foundry-resource.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/3-3-create-foundry-resource_hu_e040e90bd75b1db3.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience/images/3-3-create-foundry-resource.png 1386w" width="1386"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;CLI Alternative:&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;span class="lnt"&gt;11
&lt;/span&gt;&lt;span class="lnt"&gt;12
&lt;/span&gt;&lt;span class="lnt"&gt;13
&lt;/span&gt;&lt;span class="lnt"&gt;14
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;az cognitiveservices account create &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --subscription &amp;lt;subscription-id&amp;gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --resource-group &amp;lt;resource-group&amp;gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --name &amp;lt;foundry-resource-name&amp;gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --location &amp;lt;region-code&amp;gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --kind AIServices --sku S0 &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --custom-domain &amp;lt;foundry-resource-name&amp;gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --allow-project-management &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;az cognitiveservices account project create &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --subscription &amp;lt;subscription-id&amp;gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --name &amp;lt;foundry-resource-name&amp;gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --resource-group &amp;lt;resource-group&amp;gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --project-name &amp;lt;project-name&amp;gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --location &amp;lt;region-code&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Example Resource Distribution:&lt;/strong&gt;&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Subscription&lt;/th&gt;
 &lt;th&gt;Region&lt;/th&gt;
 &lt;th&gt;Resource Name&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;Subscription A&lt;/td&gt;
 &lt;td&gt;East US 2&lt;/td&gt;
 &lt;td&gt;foundry-eastus2-01&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Subscription A&lt;/td&gt;
 &lt;td&gt;Sweden Central&lt;/td&gt;
 &lt;td&gt;foundry-swedencentral-01&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Subscription B&lt;/td&gt;
 &lt;td&gt;East US 2&lt;/td&gt;
 &lt;td&gt;foundry-eastus2-02&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Subscription B&lt;/td&gt;
 &lt;td&gt;Sweden Central&lt;/td&gt;
 &lt;td&gt;foundry-swedencentral-02&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;hr&gt;
&lt;h2 id="deploy-models"&gt;Deploy Models
&lt;/h2&gt;&lt;p&gt;Deploy AI models in each Foundry resource via the Foundry Portal.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Portal Steps:&lt;/strong&gt; In &lt;a class="link" href="https://ai.azure.com/nextgen/" target="_blank" rel="noopener"
 &gt;Foundry Portal&lt;/a&gt;, select the target project → Build → Models → Deploy a base model → Search for a model (for example &lt;code&gt;sora-2&lt;/code&gt;) → Deploy → Default settings&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="491px" data-flex-grow="204" height="924" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/4-2-search-sora2.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/4-2-search-sora2_hu_e7087db313cdf721.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience/images/4-2-search-sora2_hu_956f92a0935b1b90.png 1600w, https://robinsujob.github.io/p/azure-apim-ai-resilience/images/4-2-search-sora2.png 1891w" width="1891"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="455px" data-flex-grow="189" height="1006" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/4-5-playground.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/4-5-playground_hu_b6ecf169c4389d93.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience/images/4-5-playground_hu_50733a65436bad42.png 1600w, https://robinsujob.github.io/p/azure-apim-ai-resilience/images/4-5-playground.png 1911w" width="1911"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;CLI Alternative:&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;az cognitiveservices account deployment create &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --subscription &amp;lt;subscription-id&amp;gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --resource-group &amp;lt;resource-group&amp;gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --name &amp;lt;foundry-resource-name&amp;gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --deployment-name &amp;lt;deployment-name&amp;gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --model-name &amp;lt;model-name&amp;gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --model-version &amp;lt;model-version&amp;gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --model-format &amp;lt;model-format&amp;gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --sku-name &amp;lt;sku-name&amp;gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --sku-capacity &amp;lt;capacity&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
 &lt;blockquote&gt;
 &lt;p&gt;Model names, versions, and SKUs vary by region. See: &lt;a class="link" href="https://learn.microsoft.com/azure/foundry/foundry-models/concepts/models-sold-directly-by-azure" target="_blank" rel="noopener"
 &gt;Models and Region Availability&lt;/a&gt;&lt;/p&gt;

 &lt;/blockquote&gt;
&lt;hr&gt;
&lt;h2 id="configure-rbac"&gt;Configure RBAC
&lt;/h2&gt;&lt;p&gt;Grant the &lt;code&gt;Cognitive Services OpenAI User&lt;/code&gt; role to APIM&amp;rsquo;s Managed Identity on &lt;strong&gt;each Foundry resource&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Portal Steps:&lt;/strong&gt; Go to the Foundry resource → Access control (IAM) → + Add → Add role assignment → Search &lt;code&gt;Cognitive Services OpenAI User&lt;/code&gt; → In Members choose Managed identity → Select the API Management service → Review + assign&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="296px" data-flex-grow="123" height="1042" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/5-3-select-role.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/5-3-select-role_hu_7d310acac9aba761.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience/images/5-3-select-role.png 1287w" width="1287"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="378px" data-flex-grow="157" height="1166" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/5-4-select-managed-identity.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/5-4-select-managed-identity_hu_d617d34d874084d4.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience/images/5-4-select-managed-identity_hu_66bfce957da67b8d.png 1600w, https://robinsujob.github.io/p/azure-apim-ai-resilience/images/5-4-select-managed-identity.png 1840w" width="1840"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;CLI Alternative:&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;span class="lnt"&gt;11
&lt;/span&gt;&lt;span class="lnt"&gt;12
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Get APIM Managed Identity Principal ID&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;az apim show &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --subscription &amp;lt;subscription-id&amp;gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --name &amp;lt;apim-name&amp;gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --resource-group &amp;lt;resource-group&amp;gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --query &lt;span class="s2"&gt;&amp;#34;identity.principalId&amp;#34;&lt;/span&gt; -o tsv
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Assign role for each Foundry resource&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;az role assignment create &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --assignee &amp;lt;principal-id&amp;gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --role &lt;span class="s2"&gt;&amp;#34;Cognitive Services OpenAI User&amp;#34;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --scope /subscriptions/&amp;lt;subscription-id&amp;gt;/resourceGroups/&amp;lt;resource-group&amp;gt;/providers/Microsoft.CognitiveServices/accounts/&amp;lt;foundry-resource-name&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
 &lt;blockquote&gt;
 &lt;p&gt;&lt;code&gt;Cognitive Services OpenAI User&lt;/code&gt; is the minimum permission role—allows inference calls but not resource configuration changes.&lt;/p&gt;

 &lt;/blockquote&gt;
&lt;hr&gt;
&lt;h2 id="configure-backend--lb-pool"&gt;Configure Backend + LB Pool
&lt;/h2&gt;&lt;h3 id="create-backend"&gt;Create Backend
&lt;/h3&gt;&lt;p&gt;Create a Backend for each Foundry resource with Managed Identity authentication.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Get OpenAI Endpoint:&lt;/strong&gt; On the project Home page in &lt;a class="link" href="https://ai.azure.com/nextgen/" target="_blank" rel="noopener"
 &gt;Foundry Portal&lt;/a&gt;, find &lt;strong&gt;Azure OpenAI endpoint&lt;/strong&gt;, or use the CLI:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;span class="lnt"&gt;4
&lt;/span&gt;&lt;span class="lnt"&gt;5
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;az cognitiveservices account show &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --subscription &amp;lt;subscription-id&amp;gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --resource-group &amp;lt;resource-group&amp;gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --name &amp;lt;foundry-resource-name&amp;gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --query &lt;span class="s2"&gt;&amp;#34;properties.endpoints.\&amp;#34;OpenAI Language Model Instance API\&amp;#34;&amp;#34;&lt;/span&gt; -o tsv
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Portal Steps:&lt;/strong&gt; APIM → Backends → + Create new backend → Fill in Name / Runtime URL → Managed Identity tab → Client identity = System assigned → Resource ID = &lt;code&gt;https://cognitiveservices.azure.com&lt;/code&gt; → Create&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="299px" data-flex-grow="124" height="1647" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/6-3-create-backend.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/6-3-create-backend_hu_6b4ff1c24b7d40ce.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience/images/6-3-create-backend_hu_3c50fe44b4ab8742.png 1600w, https://robinsujob.github.io/p/azure-apim-ai-resilience/images/6-3-create-backend.png 2052w" width="2052"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Key Configuration:&lt;/strong&gt;&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Configuration&lt;/th&gt;
 &lt;th&gt;Example Value&lt;/th&gt;
 &lt;th&gt;Description&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;Name&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;&amp;lt;foundry-resource-name&amp;gt;&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;Recommended to match the Foundry resource name&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Runtime URL&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;https://&amp;lt;foundry-resource-name&amp;gt;.openai.azure.com/openai/v1&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;Foundry OpenAI endpoint (+ &lt;code&gt;openai/v1&lt;/code&gt;)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Client identity&lt;/td&gt;
 &lt;td&gt;System assigned identity&lt;/td&gt;
 &lt;td&gt;Use APIM system-assigned managed identity&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Resource ID&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;https://cognitiveservices.azure.com&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;Token audience, &lt;strong&gt;fixed value&lt;/strong&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;CLI Alternative:&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;span class="lnt"&gt;11
&lt;/span&gt;&lt;span class="lnt"&gt;12
&lt;/span&gt;&lt;span class="lnt"&gt;13
&lt;/span&gt;&lt;span class="lnt"&gt;14
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;az rest --method PUT &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --url &lt;span class="s2"&gt;&amp;#34;https://management.azure.com/subscriptions/&amp;lt;subscription-id&amp;gt;/resourceGroups/&amp;lt;resource-group&amp;gt;/providers/Microsoft.ApiManagement/service/&amp;lt;apim-name&amp;gt;/backends/&amp;lt;backend-name&amp;gt;?api-version=2024-05-01&amp;#34;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --body &lt;span class="s1"&gt;&amp;#39;{
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s1"&gt; &amp;#34;properties&amp;#34;: {
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s1"&gt; &amp;#34;url&amp;#34;: &amp;#34;https://&amp;lt;foundry-resource-name&amp;gt;.openai.azure.com/openai/v1&amp;#34;,
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s1"&gt; &amp;#34;protocol&amp;#34;: &amp;#34;http&amp;#34;,
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s1"&gt; &amp;#34;credentials&amp;#34;: {
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s1"&gt; &amp;#34;managedIdentity&amp;#34;: {
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s1"&gt; &amp;#34;clientId&amp;#34;: null,
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s1"&gt; &amp;#34;resource&amp;#34;: &amp;#34;https://cognitiveservices.azure.com&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s1"&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s1"&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s1"&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s1"&gt; }&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;h3 id="create-lb-pool"&gt;Create LB Pool
&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Portal Steps:&lt;/strong&gt; APIM → Backends → Load balancer tab → + Create new pool → Fill in Pool Name → Select all Backends → Send requests evenly (Round-robin) → Create&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="375px" data-flex-grow="156" height="774" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/6-6-create-pool.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/6-6-create-pool_hu_3af9a6228e0fc588.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience/images/6-6-create-pool.png 1212w" width="1212"&gt;&lt;/p&gt;

 &lt;blockquote&gt;
 &lt;p&gt;Portal provides two options: &lt;strong&gt;Send requests evenly&lt;/strong&gt; (Round-robin) or &lt;strong&gt;Customize weight and priority&lt;/strong&gt;.&lt;/p&gt;

 &lt;/blockquote&gt;
&lt;hr&gt;
&lt;h2 id="create-api--policy"&gt;Create API + Policy
&lt;/h2&gt;&lt;h3 id="create-api"&gt;Create API
&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Portal Steps:&lt;/strong&gt; APIM → APIs → + Add API → HTTP → Fill in Display name / API URL suffix (&lt;code&gt;openai/v1&lt;/code&gt;) → Leave Web service URL empty → Create&lt;/p&gt;
&lt;p&gt;Then add Operations: create &lt;code&gt;/*&lt;/code&gt; wildcard path for POST, GET, and DELETE.&lt;/p&gt;

 &lt;blockquote&gt;
 &lt;p&gt;This example uses wildcard &lt;code&gt;/*&lt;/code&gt; to proxy all requests. For finer control, create operations for specific paths like &lt;code&gt;/videos/*&lt;/code&gt; for Sora2.&lt;/p&gt;

 &lt;/blockquote&gt;
&lt;h3 id="configure-policy"&gt;Configure Policy
&lt;/h3&gt;&lt;p&gt;Select All operations → click &lt;code&gt;&amp;lt;/&amp;gt;&lt;/code&gt; in Inbound processing → paste the policy below, update the pool name → Save&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;span class="lnt"&gt;11
&lt;/span&gt;&lt;span class="lnt"&gt;12
&lt;/span&gt;&lt;span class="lnt"&gt;13
&lt;/span&gt;&lt;span class="lnt"&gt;14
&lt;/span&gt;&lt;span class="lnt"&gt;15
&lt;/span&gt;&lt;span class="lnt"&gt;16
&lt;/span&gt;&lt;span class="lnt"&gt;17
&lt;/span&gt;&lt;span class="lnt"&gt;18
&lt;/span&gt;&lt;span class="lnt"&gt;19
&lt;/span&gt;&lt;span class="lnt"&gt;20
&lt;/span&gt;&lt;span class="lnt"&gt;21
&lt;/span&gt;&lt;span class="lnt"&gt;22
&lt;/span&gt;&lt;span class="lnt"&gt;23
&lt;/span&gt;&lt;span class="lnt"&gt;24
&lt;/span&gt;&lt;span class="lnt"&gt;25
&lt;/span&gt;&lt;span class="lnt"&gt;26
&lt;/span&gt;&lt;span class="lnt"&gt;27
&lt;/span&gt;&lt;span class="lnt"&gt;28
&lt;/span&gt;&lt;span class="lnt"&gt;29
&lt;/span&gt;&lt;span class="lnt"&gt;30
&lt;/span&gt;&lt;span class="lnt"&gt;31
&lt;/span&gt;&lt;span class="lnt"&gt;32
&lt;/span&gt;&lt;span class="lnt"&gt;33
&lt;/span&gt;&lt;span class="lnt"&gt;34
&lt;/span&gt;&lt;span class="lnt"&gt;35
&lt;/span&gt;&lt;span class="lnt"&gt;36
&lt;/span&gt;&lt;span class="lnt"&gt;37
&lt;/span&gt;&lt;span class="lnt"&gt;38
&lt;/span&gt;&lt;span class="lnt"&gt;39
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-xml" data-lang="xml"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;&amp;lt;policies&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;inbound&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="c"&gt;&amp;lt;!-- Read request header so callers can pin a backend --&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;set-variable&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;target&amp;#34;&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;@(context.Request.Headers.GetValueOrDefault(&amp;#34;&lt;/span&gt;&lt;span class="err"&gt;X-AI-Foundry-Target&amp;#34;,&lt;/span&gt; &lt;span class="err"&gt;&amp;#34;&amp;#34;))&amp;#34;&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="c"&gt;&amp;lt;!-- Backend load balancing pool name --&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;set-variable&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;pool_name&amp;#34;&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;&amp;lt;your-ai-hub-pool-name&amp;gt;&amp;#34;&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;choose&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;when&lt;/span&gt; &lt;span class="na"&gt;condition=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;@(context.Variables.GetValueOrDefault&amp;lt;string&amp;gt;(&amp;#34;&lt;/span&gt;&lt;span class="err"&gt;target&amp;#34;)&lt;/span&gt; &lt;span class="err"&gt;!=&lt;/span&gt; &lt;span class="err"&gt;&amp;#34;&amp;#34;)&amp;#34;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;set-backend-service&lt;/span&gt; &lt;span class="na"&gt;backend-id=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;@(context.Variables.GetValueOrDefault&amp;lt;string&amp;gt;(&amp;#34;&lt;/span&gt;&lt;span class="err"&gt;target&amp;#34;))&amp;#34;&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;/when&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;otherwise&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;set-backend-service&lt;/span&gt; &lt;span class="na"&gt;backend-id=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;@((string)context.Variables[&amp;#34;&lt;/span&gt;&lt;span class="err"&gt;pool_name&amp;#34;])&amp;#34;&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;/otherwise&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;/choose&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;/inbound&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;outbound&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;set-header&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;X-AI-Foundry-Backend&amp;#34;&lt;/span&gt; &lt;span class="na"&gt;exists-action=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;override&amp;#34;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;value&amp;gt;&lt;/span&gt;@(context.Request.Url.Host.Split(&amp;#39;.&amp;#39;)[0])&lt;span class="nt"&gt;&amp;lt;/value&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;/set-header&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;/outbound&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;on-error&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;/on-error&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;backend&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;choose&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;when&lt;/span&gt; &lt;span class="na"&gt;condition=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;@(context.Variables.GetValueOrDefault&amp;lt;string&amp;gt;(&amp;#34;&lt;/span&gt;&lt;span class="err"&gt;target&amp;#34;)&lt;/span&gt; &lt;span class="err"&gt;!=&lt;/span&gt; &lt;span class="err"&gt;&amp;#34;&amp;#34;)&amp;#34;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;forward-request&lt;/span&gt; &lt;span class="na"&gt;buffer-request-body=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;true&amp;#34;&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;/when&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;otherwise&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;retry&lt;/span&gt; &lt;span class="na"&gt;condition=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;@(context.Response == null || context.Response.StatusCode &amp;gt;= 400)&amp;#34;&lt;/span&gt; &lt;span class="na"&gt;count=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;3&amp;#34;&lt;/span&gt; &lt;span class="na"&gt;interval=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;1&amp;#34;&lt;/span&gt; &lt;span class="na"&gt;delta=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;1&amp;#34;&lt;/span&gt; &lt;span class="na"&gt;max-interval=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;5&amp;#34;&lt;/span&gt; &lt;span class="na"&gt;first-fast-retry=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;true&amp;#34;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;set-backend-service&lt;/span&gt; &lt;span class="na"&gt;backend-id=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;@((string)context.Variables[&amp;#34;&lt;/span&gt;&lt;span class="err"&gt;pool_name&amp;#34;]&lt;/span&gt; &lt;span class="err"&gt;)&amp;#34;&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;forward-request&lt;/span&gt; &lt;span class="na"&gt;buffer-request-body=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;true&amp;#34;&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;/retry&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;/otherwise&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;/choose&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;/backend&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;&amp;lt;/policies&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="370px" data-flex-grow="154" height="1848" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/7-5-policy-editor-en.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/7-5-policy-editor-en_hu_bf4c944bd3751b2f.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience/images/7-5-policy-editor-en_hu_82283df76f27d876.png 1600w, https://robinsujob.github.io/p/azure-apim-ai-resilience/images/7-5-policy-editor-en_hu_fc16f38167941c1d.png 2400w, https://robinsujob.github.io/p/azure-apim-ai-resilience/images/7-5-policy-editor-en.png 2851w" width="2851"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Policy Logic:&lt;/strong&gt;&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Area&lt;/th&gt;
 &lt;th&gt;Function&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;inbound&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Read &lt;code&gt;X-AI-Foundry-Target&lt;/code&gt;; if present, route to the specified backend, otherwise use the LB Pool round-robin&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;outbound&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Return the actual backend name in the &lt;code&gt;X-AI-Foundry-Backend&lt;/code&gt; response header&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;backend&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Forward directly for pinned routing; in pool mode, auto-retry and switch backend on failure (up to 3 attempts with exponential backoff)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;hr&gt;
&lt;h2 id="test-and-validate"&gt;Test and Validate
&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;Prerequisites:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Gather the following before testing:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Get Gateway URL: APIM → Overview → Gateway URL&lt;/li&gt;
&lt;li&gt;Get API Key: APIM → Subscriptions → Built-in all-access → Show keys → Primary key&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="506px" data-flex-grow="211" height="1116" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/8-2-subscription-key.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/8-2-subscription-key_hu_73484fdc0f89d8c9.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience/images/8-2-subscription-key_hu_a8585cc5e1155571.png 1600w, https://robinsujob.github.io/p/azure-apim-ai-resilience/images/8-2-subscription-key.png 2355w" width="2355"&gt;&lt;/p&gt;
&lt;h3 id="test-1-load-balancing"&gt;Test 1: Load Balancing
&lt;/h3&gt;&lt;p&gt;Send consecutive requests without &lt;code&gt;X-AI-Foundry-Target&lt;/code&gt;, and observe &lt;code&gt;X-AI-Foundry-Backend&lt;/code&gt; rotating across backends:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;curl -D - -o /dev/null --location &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s1"&gt;&amp;#39;https://&amp;lt;apim-gateway-url&amp;gt;/openai/v1/videos&amp;#39;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --header &lt;span class="s1"&gt;&amp;#39;Ocp-Apim-Subscription-Key: &amp;lt;your-subscription-key&amp;gt;&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Expected: &lt;code&gt;X-AI-Foundry-Backend&lt;/code&gt; changes with each request, confirming Round-robin is working.&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="295px" data-flex-grow="123" height="1961" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/8-3-round-robin-test.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/8-3-round-robin-test_hu_7f93d3fde652e814.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience/images/8-3-round-robin-test_hu_a47e59e6a4cc2c60.png 1600w, https://robinsujob.github.io/p/azure-apim-ai-resilience/images/8-3-round-robin-test_hu_54b55a659d650932.png 2400w, https://robinsujob.github.io/p/azure-apim-ai-resilience/images/8-3-round-robin-test.png 2415w" width="2415"&gt;&lt;/p&gt;
&lt;h3 id="test-2-pinned-backend-routing"&gt;Test 2: Pinned Backend Routing
&lt;/h3&gt;&lt;p&gt;Use &lt;code&gt;X-AI-Foundry-Target&lt;/code&gt; header to pin to a specific backend:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;span class="lnt"&gt;4
&lt;/span&gt;&lt;span class="lnt"&gt;5
&lt;/span&gt;&lt;span class="lnt"&gt;6
&lt;/span&gt;&lt;span class="lnt"&gt;7
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;curl -s -D - -o /dev/null --location &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s1"&gt;&amp;#39;https://&amp;lt;apim-gateway-url&amp;gt;/openai/v1/responses&amp;#39;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --header &lt;span class="s1"&gt;&amp;#39;Content-Type: application/json&amp;#39;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --header &lt;span class="s1"&gt;&amp;#39;Ocp-Apim-Subscription-Key: &amp;lt;your-subscription-key&amp;gt;&amp;#39;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --header &lt;span class="s1"&gt;&amp;#39;X-AI-Foundry-Target: &amp;lt;backend-name&amp;gt;&amp;#39;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --data &lt;span class="s1"&gt;&amp;#39;{&amp;#34;model&amp;#34;: &amp;#34;&amp;lt;model-name&amp;gt;&amp;#34;, &amp;#34;input&amp;#34;: &amp;#34;Hello&amp;#34;}&amp;#39;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;|&lt;/span&gt; grep -i X-AI-Foundry-Backend
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Expected: &lt;code&gt;X-AI-Foundry-Backend&lt;/code&gt; consistently returns the specified backend name.&lt;/p&gt;
&lt;p&gt;&lt;img class="gallery-image" data-flex-basis="423px" data-flex-grow="176" height="1056" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/8-4-pinned-backend-test.png" srcset="https://robinsujob.github.io/p/azure-apim-ai-resilience/images/8-4-pinned-backend-test_hu_dfc5dea219569ee5.png 800w, https://robinsujob.github.io/p/azure-apim-ai-resilience/images/8-4-pinned-backend-test_hu_f665edd6a0ac1aeb.png 1600w, https://robinsujob.github.io/p/azure-apim-ai-resilience/images/8-4-pinned-backend-test.png 1865w" width="1865"&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="faq"&gt;FAQ
&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;Q: Why not use APIM Backend&amp;rsquo;s Circuit Breaker?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This architecture targets load balancing and quota aggregation. Circuit Breaker would &amp;ldquo;break&amp;rdquo; on backend failure, but a 429 on one model shouldn&amp;rsquo;t block other models on the same backend. Simple failover via &lt;code&gt;retry&lt;/code&gt; + &lt;code&gt;set-backend-service&lt;/code&gt; is more appropriate.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Q: Is this architecture only for Sora2?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;No. It applies to any Foundry / Azure OpenAI model service (Responses API, Chat Completions, Embeddings, Image Generation, etc.)—just point the Backend URL to the corresponding endpoint.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="reference-documentation"&gt;Reference Documentation
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;Microsoft Foundry Overview: &lt;a class="link" href="https://learn.microsoft.com/azure/foundry/what-is-foundry" target="_blank" rel="noopener"
 &gt;https://learn.microsoft.com/azure/foundry/what-is-foundry&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Foundry RBAC: &lt;a class="link" href="https://learn.microsoft.com/azure/foundry-classic/openai/how-to/role-based-access-control" target="_blank" rel="noopener"
 &gt;https://learn.microsoft.com/azure/foundry-classic/openai/how-to/role-based-access-control&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;APIM v2 Tier: &lt;a class="link" href="https://learn.microsoft.com/azure/api-management/v2-service-tiers-overview" target="_blank" rel="noopener"
 &gt;https://learn.microsoft.com/azure/api-management/v2-service-tiers-overview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Backends &amp;amp; LB Pool: &lt;a class="link" href="https://learn.microsoft.com/azure/api-management/backends" target="_blank" rel="noopener"
 &gt;https://learn.microsoft.com/azure/api-management/backends&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Managed Identity: &lt;a class="link" href="https://learn.microsoft.com/azure/api-management/api-management-howto-use-managed-service-identity" target="_blank" rel="noopener"
 &gt;https://learn.microsoft.com/azure/api-management/api-management-howto-use-managed-service-identity&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Retry Policy: &lt;a class="link" href="https://learn.microsoft.com/azure/api-management/retry-policy" target="_blank" rel="noopener"
 &gt;https://learn.microsoft.com/azure/api-management/retry-policy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Video Generation / Sora2: &lt;a class="link" href="https://learn.microsoft.com/azure/foundry/openai/concepts/video-generation" target="_blank" rel="noopener"
 &gt;https://learn.microsoft.com/azure/foundry/openai/concepts/video-generation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Models &amp;amp; Regions: &lt;a class="link" href="https://learn.microsoft.com/azure/foundry/foundry-models/concepts/models-sold-directly-by-azure" target="_blank" rel="noopener"
 &gt;https://learn.microsoft.com/azure/foundry/foundry-models/concepts/models-sold-directly-by-azure&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Error Codes: &lt;a class="link" href="https://learn.microsoft.com/azure/foundry/openai/supported-languages#error-handling" target="_blank" rel="noopener"
 &gt;https://learn.microsoft.com/azure/foundry/openai/supported-languages#error-handling&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;</description></item></channel></rss>