Chapter 2 of 6 · Architecture

AI cost allocation, budgets, and gateway token chargeback

Optional module · Draft 4.5 hours

Chapter 2 of 6

Architecture at a glance#

The flow has three parts.

First, Azure Policy stages the approved cost-tag requirement on resource groups across the approved subscription and uses a managed identity to inherit those values to child resources. Second, Cost Management budget notifications watch the approved AI resource groups and meter categories. Third, API Management emits token metrics with cost-center and consumer dimensions while a per-product quota limits token use.

The repository owns the Bicep, APIM policy fragment, rate table, and KQL query. Azure holds the live policy assignments, budget, APIM policy, token metrics, and billed cost. Finance owns the rate table and reconciliation cadence.

Design choices and tradeoffs#

DecisionChosen approachBenefitsCosts and limitations
Allocation anchorStage required tags on resource groups and inherit them to resourcesBilled cost can be grouped by the same finance tags across servicesThe tag requirement is subscription-wide and stays in DoNotEnforce until approved
Budget signalFilter by resource group and meter category, then notify email and an action groupCost owners see actual and forecasted spend changes without broad subscription noiseBudgets notify only; they do not stop resources
Token signalEmit APIM token metrics with five low-cardinality dimensions from trusted gateway contextFinOps can attribute token use before billed cost landsHigh-cardinality values are dropped by metric limits
QuotaPer-product monthly token quota and tokens-per-minute rateProduct owners get a hard gateway boundary for shared routesQuotas apply at the gateway counter key, not to direct model endpoint calls
Rate tableFinance-owned JSON table, used by KQL and reportingRates are reviewable and versionedEstimated cost must be reconciled with Cost Management

Architecture guidance#

Use Azure Policy assignment structure for assignment identity, metadata, parameters, and enforcement mode.

Use Create a budget with Bicep for budget notifications, filters, forecasted thresholds, and the budget boundary.

Use llm-emit-token-metric for token metrics, custom-dimension limits, Application Insights prerequisites, and streaming token-count caveats.

Optional module

AI cost allocation, budgets, and gateway token chargeback slide deck