← All runbooks
microsoft / azure-cost

Azure Cost Management Skill

This runbook enables an AI agent to perform A

agent claude-codemodel claude-sonnet-4-6snapshot python312-uveval programmatic7 stepsv1.0.0

Deploy Azure Cost Management Skill to your jetty.io

One-click installs this runbook into a collection on your Jetty account. You can run it from the Spot dashboard, schedule it, or pipe inputs in via the API.

The shape of the run

7 steps · start to finish.

  1. 1
    Step 1

    Environment Setup

    # Verify required CLIs are present
    command -v az   >/dev/null || { echo "ERROR: az CLI not installed"; exit 1; }
    command -v jq   >/dev/null || { echo "ERROR: jq not installed"; exit 1; }
    
    # Confirm Azure login
    az account show --query "{subscriptionId:id, name:name, tenantId:tenantId}" -o json || {
      echo "ERROR: Not logged in to Azure. Run: az login"
      exit 1
    }
    
    # Confirm the scope is accessible
    SCOPE="${SCOPE:-/subscriptions/$(az account show --query id -o tsv)}"
    az rest --method GET \
      --url "${SCOPE}/providers/Microsoft.CostManagement/query?api-version=2023-11-01" \
      --headers "ClientType=GitHubCopilotForAzure" 2>&1 | head -5 || true
    
    # Create output directory
    mkdir -p /app/results
    echo "Environment ready. Scope: $SCOPE"
    

  2. 2
    Step 2

    Cost Query Workflow

    Query historical costs from the Azure Cost Management API. Use `az rest` (more reliable than `az costmanagement query`). Always include `ClientType: GitHubCopilotForAzure` header.

  3. 3
    Step 3

    Cost Optimization Workflow (if `run_optimization=true`)

    - Confirm Cost Management Reader + Monitoring Reader + Reader roles on scope - Run cost query (Step 2) first — always present the total bill alongside optimization recommendations - Use `azure__extension_azqr` MCP tool to find orphaned resources - Use `az monitor metrics list` fo

  4. 4
    Step 4

    Cost Forecast Workflow (if `run_forecast=true`)

    FORECAST_START="$(date -u +%Y-%m-01)" # first day of current month FORECAST_END="$(date -u -d 'next month - 1 day' +%Y-%m-%d)" # last day of current month

  5. 5
    Step 5

    Generate Cost Report

    Write `/app/results/cost_report.md` including:

  6. 6
    Step 6

    Iterate on Errors (max 3 rounds)

    If any API call fails:

  7. 7
    Step 7

    Write Summary and Validation

    Write `/app/results/summary.md`: