Two problems show up on nearly every enterprise Azure OpenAI engagement, and they are usually solved separately and badly.
The first is control. Model deployments multiply across regions and subscriptions, each with its own endpoint and key. A model name ends up hard-coded into dozens of services, so upgrading from one model version to the next becomes a coordinated release across every team that calls it.
The second is cost. The Azure bill shows what Foundry cost. It does not show which application spent it, because every request arrives at the model with the same managed identity. Finance asks “what did each team spend on AI last month?” — and, increasingly, “which people drove it?” — and there is no defensible answer.
This project is the reference architecture and Terraform for solving both, as two layers in one codebase.
Azure API Management as a single governed entry point for every Foundry deployment.
gpt-chat, never gpt-4o-eastus-prod-v3. A model upgrade becomes a gateway change instead of forty pull requests.Per-request token accounting, turned into a number finance will accept.
Read the cost attribution guide →
| Document | What it covers |
|---|---|
| Architecture | Topology, request flow, network design, and an honest list of limitations |
| Cost attribution | The ledger schema, allocation maths, and the reconciliation loop |
| Per-user attribution (OBO) | Calling the gateway with On-Behalf-Of tokens so cost is attributed to users |
| Policies | The APIM policy pipeline section by section, and the authoring rules |
| Operations | Day-2: regenerating the pricing map, adding models, troubleshooting |
| Validation | Live-deployment evidence — load balancing, cost and per-user attribution — and the defects only a live deployment found |
| Decision records | Nine ADRs explaining why each trade-off was made |
The Terraform, policies and examples live on GitHub: muazuisah/azure-ai-gateway-cost-attribution
Three worked examples ship with it: a single-region quickstart, a production profile with private endpoints and multi-region backends, and a full chargeback deployment.
This is a personal project. It is not a Microsoft product, it is not endorsed by or affiliated with Microsoft, and it carries no support commitment. Opinions here are my own and do not represent the positions, strategies, or opinions of my employer. Microsoft, Azure, Microsoft Foundry and Azure OpenAI Service are trademarks of the Microsoft group of companies.