Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Build and deploy AI applications on Azure AI Foundry using Microsoft's model catalog and AI services
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.sh
1#!/bin/bash2# query_capacity.sh3# Queries available capacity for an Azure OpenAI model.4#5# Usage:6# ./query_capacity.sh <model-name> [model-version] [region] [sku]7# Examples:8# ./query_capacity.sh o3-mini # List versions9# ./query_capacity.sh o3-mini 2025-01-31 # All regions10# ./query_capacity.sh o3-mini 2025-01-31 eastus2 # Specific region11# ./query_capacity.sh o3-mini 2025-01-31 "" Standard # Different SKU1213set -euo pipefail1415MODEL_NAME="${1:?Usage: $0 <model-name> [model-version] [region] [sku]}"16MODEL_VERSION="${2:-}"17REGION="${3:-}"18SKU="${4:-GlobalStandard}"1920SUB_ID=$(az account show --query id -o tsv)2122# If no version, list available versions23if [ -z "$MODEL_VERSION" ]; then24LOC="${REGION:-eastus}"25echo "Available versions for $MODEL_NAME:"26az cognitiveservices model list --location "$LOC" \27--query "[?model.name=='$MODEL_NAME'].{Version:model.version, Format:model.format}" \28--output table 2>/dev/null29exit 030fi3132# Build URL33if [ -n "$REGION" ]; then34URL="https://management.azure.com/subscriptions/${SUB_ID}/providers/Microsoft.CognitiveServices/locations/${REGION}/modelCapacities"35else36URL="https://management.azure.com/subscriptions/${SUB_ID}/providers/Microsoft.CognitiveServices/modelCapacities"37fi3839# Query capacity40CAPACITY_RESULT=$(az rest --method GET --url "$URL" \41--url-parameters api-version=2024-10-01 modelFormat=OpenAI modelName="$MODEL_NAME" modelVersion="$MODEL_VERSION" \422>/dev/null)4344# Get regions with capacity45REGIONS_WITH_CAP=$(echo "$CAPACITY_RESULT" | jq -r ".value[] | select(.properties.skuName==\"$SKU\" and .properties.availableCapacity > 0) | .location" 2>/dev/null | sort -u)4647if [ -z "$REGIONS_WITH_CAP" ]; then48echo "No capacity found for $MODEL_NAME v$MODEL_VERSION ($SKU)"49echo "Try a different SKU or version."50exit 051fi5253echo "Capacity: $MODEL_NAME v$MODEL_VERSION ($SKU)"54echo ""55printf "%-22s %-12s %-15s %s\n" "Region" "Available" "Quota" "SKU"56printf -- '-%.0s' {1..60}; echo ""5758for region in $REGIONS_WITH_CAP; do59avail=$(echo "$CAPACITY_RESULT" | jq -r ".value[] | select(.location==\"$region\" and .properties.skuName==\"$SKU\") | .properties.availableCapacity" 2>/dev/null | head -1)6061# Check subscription quota62usage_json=$(az cognitiveservices usage list --location "$region" --subscription "$SUB_ID" -o json 2>/dev/null || echo "[]")63quota_avail=$(echo "$usage_json" | jq -r --arg name "OpenAI.$SKU.$MODEL_NAME" \64'[.[] | select(.name.value == $name)] | if length > 0 then .[0].limit - .[0].currentValue else 0 end' 2>/dev/null || echo "?")6566if [ "$quota_avail" = "0" ]; then67quota_display="0 (none)"68elif [ "$quota_avail" = "?" ]; then69quota_display="?"70else71quota_display="${quota_avail}K"72fi7374printf "%-22s %-12s %-15s %s\n" "$region" "${avail}K TPM" "$quota_display" "$SKU"75done76