Home / AI & GenAI

AI & GenAIHow-toIntermediate

Azure Monitor alerts for Azure OpenAI - 429s, server errors, latency and token usage with az monitor

Set up the five Azure OpenAI alerts on-call needs with az monitor - throttling, 5xx, auth failures, latency and token burn - using the right metric names, dimensions and an action group.

Deepak Bhardwaj8 min read

Applies toAzure OpenAI in Microsoft Foundry (Standard, Global, Data Zone and provisioned deployments), Azure Monitor, Azure CLI 2.x

Users found out before you did: the assistant got slow, then started failing with 429s, and the first alert was a ticket. Azure OpenAI sends good platform metrics to Azure Monitor at no extra cost. You only need to alert on the right ones, split by deployment, and route the alerts to on-call.

This post creates five alerts with the CLI. Each can be pasted into a pipeline or turned into Bicep later.

The metrics to use

All of these are on the Microsoft.CognitiveServices/accounts resource. Use the REST names in CLI commands and queries.

What you want to know REST metric name Aggregation Useful dimensions
Requests, throttling and errors AzureOpenAIRequests Total ModelDeploymentName, StatusCode, IsSpillover
Prompt tokens ProcessedPromptTokens Total ModelDeploymentName
Completion tokens GeneratedTokens Total ModelDeploymentName
Prompt + completion tokens TokenTransaction Total ModelDeploymentName
Time to first byte, normalized AzureOpenAINormalizedTTFTInMS Average, Maximum ModelDeploymentName
Time to last byte AzureOpenAITTLTInMS Average, Maximum ModelDeploymentName
PTU utilisation AzureOpenAIProvisionedManagedUtilizationV2 Average, Maximum ModelDeploymentName

Warning

Don't alert on the legacy Cognitive Services Latency metric. Microsoft says it isn't suitable for Azure OpenAI. Some latency metrics, such as Time to Response and Tokens Per Second, aren't available for every deployment type. Check the current monitoring data reference for your deployment type before you alert on them.

The display names and metric list change from time to time. Confirm what your resource emits before you build alerts:

RG=rg-genai-prod; NAME=my-aoai
ID=$(az cognitiveservices account show -n $NAME -g $RG --query id -o tsv)

az monitor metrics list-definitions --resource $ID \
  --query "[?contains(name.value,'OpenAI') || contains(name.value,'Token')].{name:name.value, unit:unit}" -o table

Then look at real values split by status code for the last day:

az monitor metrics list --resource $ID --metric AzureOpenAIRequests \
  --aggregation Total --interval PT1H --offset 1d \
  --filter "StatusCode eq '*' and ModelDeploymentName eq '*'" -o table

The StatusCode values in this output are what your alert filters must match. Check them here rather than guessing.

Step 1: an action group for on-call

az monitor action-group create -g $RG -n ag-genai-oncall \
  --short-name genaioncall \
  --action email oncall-email oncall@example.com \
  --action webhook pager https://example.com/hooks/pager

AG=$(az monitor action-group show -g $RG -n ag-genai-oncall --query id -o tsv)

--short-name has a 12-character limit. Use your paging tool's webhook or an ITSM connector for the alerts that page someone, and email for the rest.

Step 2: throttling alert (429s)

A few 429s are normal when clients retry correctly. A steady stream means a deployment is out of TPM or PTU capacity. Alert per deployment, so the alert names the one in trouble:

az monitor metrics alert create -g $RG -n "aoai-429-throttling" \
  --scopes $ID \
  --condition "total AzureOpenAIRequests > 50 where StatusCode includes 429 and ModelDeploymentName includes *" \
  --window-size 5m --evaluation-frequency 1m \
  --severity 2 --action $AG \
  --description "Sustained 429s on an Azure OpenAI deployment. Check TPM quota, PTU utilisation and batch jobs."

ModelDeploymentName includes * makes the rule evaluate each deployment separately. Set the threshold from your normal traffic. 50 in 5 minutes suits a busy chat app, but is too high for a small internal tool.

Tip

On a provisioned deployment, add a second rule on AzureOpenAIProvisionedManagedUtilizationV2 with avg ... > 90. Throttling starts at 100% utilisation, so this gives you warning before the 429s begin.

Step 3: server errors (5xx)

Server errors usually mean a service problem in the region. This is the alert that should start a failover decision:

az monitor metrics alert create -g $RG -n "aoai-5xx-errors" \
  --scopes $ID \
  --condition "total AzureOpenAIRequests > 10 where StatusCode includes 500 or 503 and ModelDeploymentName includes *" \
  --window-size 5m --evaluation-frequency 1m \
  --severity 1 --action $AG \
  --description "Azure OpenAI server errors. Check Azure status and Service Health, then follow the regional outage runbook."

If the dimension values on your resource differ from these codes, for example if they are grouped into classes, change the includes list to match what Step 1 showed. If you aren't sure the multi-value or syntax works on your CLI version, create one rule per code.

Step 4: authentication failures (401 and 403)

A sudden burst of 401s usually means someone regenerated keys, removed a role assignment or changed a managed identity. Alert at low volume:

az monitor metrics alert create -g $RG -n "aoai-auth-failures" \
  --scopes $ID \
  --condition "total AzureOpenAIRequests > 20 where StatusCode includes 401 or 403" \
  --window-size 5m --evaluation-frequency 5m \
  --severity 2 --action $AG \
  --description "Azure OpenAI 401/403 burst. Check key regeneration, role assignments, managed identity and network rules."

Step 5: latency that users notice

For streaming chat, time to first byte is what users feel. A dynamic threshold learns the normal pattern for each deployment, so you don't have to pick a fixed number:

az monitor metrics alert create -g $RG -n "aoai-ttft-degraded" \
  --scopes $ID \
  --condition "avg AzureOpenAINormalizedTTFTInMS > dynamic medium 3 of 4 where ModelDeploymentName includes *" \
  --window-size 5m --evaluation-frequency 5m \
  --severity 3 --action $AG \
  --description "Azure OpenAI first-token latency above its learned baseline."

3 of 4 means three of the last four evaluation periods must breach. That stops one slow minute from paging anyone. Dynamic thresholds need some history before they fire, so a new deployment won't alert straight away.

Step 6: token burn

A runaway agent loop or a batch job sent to the wrong deployment shows up as a token spike before it shows up on the bill:

az monitor metrics alert create -g $RG -n "aoai-token-spike" \
  --scopes $ID \
  --condition "total TokenTransaction > dynamic high 2 of 3 where ModelDeploymentName includes *" \
  --window-size 15m --evaluation-frequency 5m \
  --severity 3 --action $AG \
  --description "Token usage well above baseline. Find the caller in gateway or diagnostic logs."

If you have a hard daily token budget, add a static rule on TokenTransaction with a 1-hour window at the hourly share of that budget.

Optional: a log alert with request detail

Metrics tell you that something is wrong. Diagnostic logs help you find who caused it. Send the RequestResponse category to Log Analytics:

WS=$(az monitor log-analytics workspace show -g $RG -n law-genai --query id -o tsv)

az monitor diagnostic-settings create -n to-law --resource $ID --workspace $WS \
  --logs '[{"category":"RequestResponse","enabled":true},{"category":"Audit","enabled":true}]' \
  --metrics '[{"category":"AllMetrics","enabled":true}]'

These categories go to the AzureDiagnostics table. Column names in that table can vary, so run AzureDiagnostics | where ResourceProvider == "MICROSOFT.COGNITIVESERVICES" | take 10 first. A query for the error rate per operation:

AzureDiagnostics
| where ResourceProvider == "MICROSOFT.COGNITIVESERVICES" and Category == "RequestResponse"
| where TimeGenerated > ago(15m)
| summarize total = count(), errors = countif(toint(ResultSignature) >= 500),
            p95_ms = percentile(DurationMs, 95) by OperationName, bin(TimeGenerated, 5m)
| extend error_pct = round(100.0 * errors / total, 1)
| where error_pct > 5

Turn it into an alert with az monitor scheduled-query. Older CLI versions may ask to install an extension first:

az monitor scheduled-query create -g $RG -n "aoai-error-rate-logs" \
  --scopes $WS \
  --condition "count 'Q1' > 0" \
  --condition-query Q1="AzureDiagnostics | where ResourceProvider == 'MICROSOFT.COGNITIVESERVICES' and Category == 'RequestResponse' | summarize total=count(), errors=countif(toint(ResultSignature) >= 500) by OperationName | where total > 20 and 100.0*errors/total > 5" \
  --window-size 15m --evaluation-frequency 5m \
  --severity 2 --action-groups $AG

Check that the alerts exist and fire

az monitor metrics alert list -g $RG \
  --query "[].{name:name, severity:severity, enabled:enabled}" -o table

To test the 401 rule safely, send around 25 requests with a deliberately wrong key to a non-production resource that has the same rule. You should get the email or page within about 10 minutes. Don't test throttling by flooding a production deployment.

Caution

Don't put an automatic action, such as disabling a deployment or rotating keys, on the 429 or token-spike rules unless you have tested it. A bad threshold can take production chat offline. Start with notifications only and add automation once the thresholds have proved reliable.

Prevent it next time

  • Create these rules in the same IaC module as the Azure OpenAI resource, so new deployments are covered automatically by the ModelDeploymentName includes * split.
  • Put the runbook link in each rule's --description. On-call then opens the fix straight from the alert.
  • Review thresholds monthly against real traffic. Rules that fire every day get ignored, and rules that never fire may be set too high.
  • If several apps share one deployment, add per-app alerts at the gateway (APIM or LiteLLM). The Azure OpenAI metrics can't tell you which caller is responsible.