> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.withpaygent.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.withpaygent.com/_mcp/server.

# Azure Cost Tracking Setup

Connect Microsoft Azure to track infrastructure costs in Paygent. Paygent uses the Azure Cost Management Query API with a service principal (app registration).

> **Info**
>
> **What You'll Need:** An Azure subscription on a supported offer (Pay-As-You-Go, EA, or Microsoft Customer Agreement), an Entra ID app registration, and **Cost Management Reader** + **Reader** on the subscription.

---

## Step 1 — Register an app (service principal)

1. Go to **Microsoft Entra ID** → **App registrations** → **New registration**
2. Name it (e.g. `Paygent Cost Reader`) and register
3. Note the **Application (client) ID** and **Directory (tenant) ID**
4. Under **Certificates & secrets**, create a **Client secret** and copy it once

---

## Step 2 — Grant subscription access

Assign roles to the **service principal** (Enterprise application), not your user account:

1. Open **Subscriptions** → your subscription
2. **Access control (IAM)** → **Add role assignment**
3. Add **Reader**
4. Add **Cost Management Reader**

---

## Step 3 — Connect in Paygent

1. In Paygent go to **Settings** → **Infra Cost** → **Azure**
2. Enter account name, **Tenant ID**, **Client ID**, **Client secret**, and **Subscription ID**
3. Save — Paygent verifies subscription access and stores credentials securely

---

## Billing latency & supported offers

* Cost data can lag **8–24 hours** after resources start running
* **Free Trial / Sponsorship** subscriptions often do not support Cost Management APIs — upgrade to Pay-As-You-Go if Cost Analysis fails in the Azure portal
* New **Azure Plan** subscriptions may need up to **48 hours** before Cost Management returns data

---

## Troubleshooting

| Symptom                                  | Likely cause                                                     |
| ---------------------------------------- | ---------------------------------------------------------------- |
| Auth succeeds but Cost query returns 404 | Offer not supported, or billing not provisioned yet              |
| 403 on subscription                      | Missing Reader / Cost Management Reader on the service principal |
| \$0 in Paygent but VM is running         | Normal lag — check **Cost analysis** in Azure portal first       |