Symptoms
- Production chat or RAG calls start failing with
429minutes after an unrelated infrastructure pipeline ran. - Error text such as
Requests to the ChatCompletions_Create Operation under Azure OpenAI API version ... have exceeded token rate limit of your current ... pricing tier. - Traffic volume is normal. Nothing changed in the app.
- In the portal, the deployment's Tokens per Minute Rate Limit is much lower than you remember (for example 10K instead of 300K).
The usual story: someone raised the capacity in the portal during an earlier incident, and the IaC code still holds the old value. The next terraform apply or Bicep deployment reconciles the deployment back to what the code says.
Step 1: confirm the capacity changed (3 minutes)
RG=rg-genai-prod
ACCT=aoai-prod-swc
az cognitiveservices account deployment list -g $RG -n $ACCT \
--query "[].{name:name, sku:sku.name, capacity:sku.capacity, model:properties.model.name, version:properties.model.version, state:properties.provisioningState}" -o table
For Standard-family deployments, capacity is in units of 1,000 TPM for most models, so capacity: 10 means 10K TPM. The requests-per-minute limit is derived from it. Check the quota documentation for your model; the ratio varies by model.
Find out when it changed and who did it:
az monitor activity-log list -g $RG --offset 24h \
--query "[?operationName.value=='Microsoft.CognitiveServices/accounts/deployments/write'].{time:eventTimestamp, caller:caller, status:status.value, resource:resourceId}" -o table
A caller that is the pipeline's service principal or managed identity, at the time the 429s started, confirms it.
| Finding | Cause | Fix |
|---|---|---|
| Capacity dropped, caller = pipeline identity | IaC reverted a manual change | Step 2, then Step 4 |
sku.name changed (e.g. GlobalStandard to Standard) | Template used a different deployment type | Restore the type; quota is per type and region |
| Model version changed | Template pins an old version or sets an upgrade option | Restore the version you tested |
| Deployment recreated (delete + write events) | Resource name or immutable property changed in code | Restore, then fix the code so it updates in place |
| No write events | Not an IaC problem | Check real traffic growth or another app sharing the deployment |
Step 2: restore the capacity
Set the deployment back to the value production needs. deployment create updates an existing deployment in place when you pass the same name, model and version:
az cognitiveservices account deployment create -g $RG -n $ACCT \
--deployment-name chat-prod \
--model-name <model> --model-version <version> --model-format OpenAI \
--sku-name GlobalStandard --sku-capacity 300
Use the exact model name, version and SKU from the list output (or from before the change), so you only change the capacity.
If it fails with InsufficientQuota, the subscription's regional quota for that model and deployment type is already allocated elsewhere:
az cognitiveservices usage list -l swedencentral \
--query "[?contains(name.value, '<model>')].{name:name.value, used:currentValue, limit:limit}" -o table
Take capacity from a non-production deployment in the same subscription and region, or route traffic to a deployment in another region through your gateway.
Caution
Freeze the IaC pipeline before you fix the deployment by hand. Disable the pipeline or lock the branch. If it runs again before the code is fixed, it will undo your fix and you'll have a second outage.
Step 3: confirm
- The
listcommand shows the expected capacity andSucceeded. - The 429 rate on the
AzureOpenAIRequestsmetric (split byStatusCode) drops to baseline within a few minutes. - App error rate back to normal for 30 minutes.
Step 4: fix the code so it can't happen again
Put the real production value in code and make the plan show capacity changes clearly.
Terraform
In recent azurerm versions the capacity is in a sku block (older 3.x versions used a scale block; check your provider version's docs):
resource "azurerm_cognitive_deployment" "chat" {
name = "chat-prod"
cognitive_account_id = azurerm_cognitive_account.aoai.id
model {
format = "OpenAI"
name = var.chat_model_name
version = var.chat_model_version
}
sku {
name = "GlobalStandard"
capacity = var.chat_capacity_ktpm # e.g. 300 in prod.tfvars
}
}
If capacity is genuinely managed outside Terraform (for example by an autoscaling script), tell Terraform to leave it alone:
lifecycle {
ignore_changes = [sku[0].capacity]
}
Use ignore_changes only when another process really owns the value. Otherwise the code no longer describes production.
Bicep
resource chat 'Microsoft.CognitiveServices/accounts/deployments@2024-10-01' = {
parent: aoai
name: 'chat-prod'
sku: {
name: 'GlobalStandard'
capacity: chatCapacity
}
properties: {
model: {
format: 'OpenAI'
name: chatModelName
version: chatModelVersion
}
}
}
Run az deployment group what-if in the pipeline and fail the run, or require approval, when a deployment's sku.capacity decreases.
Gate capacity decreases in Terraform plans
terraform plan -out tf.plan
terraform show -json tf.plan | jq -r '
.resource_changes[]
| select(.type=="azurerm_cognitive_deployment" and (.change.actions | index("update")))
| select(.change.before.sku[0].capacity > .change.after.sku[0].capacity)
| "\(.address): capacity \(.change.before.sku[0].capacity) -> \(.change.after.sku[0].capacity)"'
If this prints anything, stop the pipeline and ask for approval.
Warning
Watch for plans that replace a deployment (
-/+). Replacing deletes the deployment first, so every call returnsDeploymentNotFounduntil the new one is ready. Changing the deployment name or some model properties can force replacement.
Prevent it next time
- No portal changes to production AI deployments without a follow-up PR in the same day. Note it in the incident close-out checklist.
- Use Azure Policy or a resource lock process for production Cognitive Services accounts, and limit who can write deployments.
- Alert on the activity log operation
Microsoft.CognitiveServices/accounts/deployments/writefor production accounts, so any change pages the owning team. - Keep capacity per environment in variables files, and review them when traffic grows.
- Add a post-deploy smoke test that checks each deployment's capacity and model version against expected values and fails the release if they differ.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get