Monitoring Cost and Allocating It Across Teams
This lesson covers a cost strategy for agent solutions, whose costs grow quickly and are often shared across teams: measuring usage, managing quotas and allocations, attributing cost through chargebacks, and controlling spending with budgets and alerts.
Learning outcomes
After completing this lesson, you will be able to:
- Measure usage at the deployment, agent and request levels.
- Divide quota through allocations.
- Choose an attribution mechanism for chargeback or showback.
- Track unit economics such as cost per completed task.
Measuring usage
Usage is measured at several levels. Azure Monitor metrics report tokens per deployment. Trace spans report tokens per agent, step and run, with custom attributes for feature, team and tenant. The API Management AI gateway's token metric policy emits token counts with dimensions such as subscription (consumer), API and custom values, which is the most practical source for per-consumer usage. Microsoft Cost Management reports actual charges by subscription, resource group, resource and tag.
Sources of usage data
Quotas and allocations
Model quota is assigned per subscription, region and model as TPM, and each deployment receives part of it. Allocations divide the quota between deployments and teams deliberately, so that one workload cannot starve another. At the gateway, the token limit policy enforces per-consumer TPM and longer-period token quotas (hourly, daily, monthly), turning allocations into enforced limits. Provisioned throughput reservations give predictable cost for steady workloads.
Quota and allocation
Chargebacks, budgets and anomalies
Chargeback bills each business unit for its consumption; showback reports it without billing. Attribution mechanisms are compared in the following table.
| Mechanism | Granularity | Notes |
|---|---|---|
| Separate subscriptions or resource groups | Per team | Simple; duplicates resources |
| Resource tags | Per resource | Cannot split one shared deployment |
| APIM subscription per consumer with token metrics | Per consumer on shared deployments | Most precise for shared model access |
| Custom span attributes | Per feature, tenant or agent | Needs telemetry analysis |
Budgets in Cost Management send alerts at thresholds of actual or forecast spend, and cost anomaly detection highlights sudden increases. In agent systems, a sudden increase is often a runaway loop or an attack, so cost alerts are connected to the same response process as reliability alerts.
Can it split a shared deployment's cost?
Unit economics
Total spend shows whether a budget is at risk, but it does not show whether the solution is efficient. Teams therefore track cost per unit of value, such as cost per completed workflow, per resolved support case or per processed document, calculated from token usage in traces and the prices of the deployments used.
Unit cost makes changes comparable. A new prompt that raises total spend because traffic grew is acceptable, while one that raises the cost per resolved case without improving quality is a regression. Breaking the unit cost down by agent and step shows where optimization pays off, for example a planner that uses a large model for every request, or a retrieval step that sends far more context than the answer needs.
Cost per resolved case
Shared model costs
Five departments share two model deployments through their own agents. Finance wants to charge each department for its token usage, and IT wants to stop any department from consuming more than 40% of capacity.
Route all agent traffic through the API Management AI gateway with one subscription per department; the token metric policy records usage per subscription for chargeback, and the token limit policy caps each subscription's TPM at 40% of capacity. Tags on the deployments cannot split shared usage, and separate deployments per department would fragment quota.
How is token usage enforced per consumer on a shared deployment?
Show answer
With the API Management token limit policy, applied to each consumer's subscription.
Exam Tips
Remember for the exam
- Per-consumer usage on shared deployments: APIM subscriptions with token metrics.
- Enforce allocations with the APIM token limit policy.
- Budgets and anomaly alerts catch runaway loops; treat them like incidents.