Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Deploy, evaluate, and manage AI agents end-to-end on Microsoft Azure AI Foundry
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
models/deploy-model/capacity/scripts/query_capacity.ps1
1<#2.SYNOPSIS3Queries available capacity for an Azure OpenAI model and validates if a target is achievable.4.PARAMETER ModelName5The model name (e.g., "gpt-4o", "o3-mini")6.PARAMETER ModelVersion7The model version (e.g., "2025-01-31"). If omitted, lists available versions.8.PARAMETER Region9Optional. Check capacity in a specific region only.10.PARAMETER SKU11SKU to check (default: GlobalStandard)12.EXAMPLE13.\query_capacity.ps1 -ModelName o3-mini14.\query_capacity.ps1 -ModelName o3-mini -ModelVersion 2025-01-31 -Region eastus215#>16param(17[Parameter(Mandatory)][string]$ModelName,18[string]$ModelVersion,19[string]$Region,20[string]$SKU = "GlobalStandard"21)2223$ErrorActionPreference = "Stop"2425$subId = az account show --query id -o tsv2627# If no version provided, list available versions first28if (-not $ModelVersion) {29Write-Host "Available versions for $ModelName`:"30$loc = if ($Region) { $Region } else { "eastus" }31az cognitiveservices model list --location $loc `32--query "[?model.name=='$ModelName'].{Version:model.version, Format:model.format}" `33--output table 2>$null34return35}3637# Build URL parameters38$urlParams = @("api-version=2024-10-01", "modelFormat=OpenAI", "modelName=$ModelName", "modelVersion=$ModelVersion")3940if ($Region) {41$url = "https://management.azure.com/subscriptions/$subId/providers/Microsoft.CognitiveServices/locations/$Region/modelCapacities"42} else {43$url = "https://management.azure.com/subscriptions/$subId/providers/Microsoft.CognitiveServices/modelCapacities"44}4546$raw = az rest --method GET --url $url --url-parameters @urlParams 2>$null | Out-String | ConvertFrom-Json4748# Filter by SKU49$filtered = $raw.value | Where-Object { $_.properties.skuName -eq $SKU -and $_.properties.availableCapacity -gt 0 }5051if (-not $filtered) {52Write-Host "No capacity found for $ModelName v$ModelVersion ($SKU)" -ForegroundColor Red53Write-Host "Try a different SKU or version."54return55}5657Write-Host "Capacity: $ModelName v$ModelVersion ($SKU)"58Write-Host ""59$filtered | ForEach-Object {60# Check subscription quota for this region61$quotaDisplay = "?"62try {63$usageData = az cognitiveservices usage list --location $_.location --subscription $subId -o json 2>$null | Out-String | ConvertFrom-Json64$usageEntry = $usageData | Where-Object { $_.name.value -eq "OpenAI.$SKU.$ModelName" }65if ($usageEntry) {66$quotaAvail = [int]$usageEntry.limit - [int]$usageEntry.currentValue67$quotaDisplay = if ($quotaAvail -gt 0) { "${quotaAvail}K" } else { "0 (at limit)" }68} else {69$quotaDisplay = "0 (none)"70}71} catch {72$quotaDisplay = "?"73}74[PSCustomObject]@{75Region = $_.location76SKU = $_.properties.skuName77Available = "$($_.properties.availableCapacity)K TPM"78Quota = $quotaDisplay79}80} | Sort-Object { [int]($_.Available -replace '[^\d]','') } -Descending | Format-Table -AutoSize81