Guide
Azure OpenAI cost tracking by customer, feature and team
Published
Your Azure bill tells you the total. It doesn't tell you which customer, product feature or team each Azure OpenAI call served. This guide shows how to tag those calls in your code, map deployment names to models so Responses API calls are priced, check the result against Azure Cost Management, and set budgets and alerts on the spend.
What does your Azure OpenAI bill show, and what's missing?
Your Azure bill shows what you spent. It has no customer field, so it can't show which of your customers a call served, which feature made it or which team owns it. That split exists only in your code, at the moment it makes the call, and it can't be rebuilt later from billing data.
So tracking has two halves. Per-call metering in your app records each call with its customer, feature and team. A read-only connection to Azure Cost Management imports what Azure actually billed, so you can check the metered figures against it. Token Meter stores the two apart and never merges them.
How do you track Azure OpenAI costs per customer, feature and team?
Wrap your Azure OpenAI client with the Token Meter SDK and open an action() scope, with the customer, feature and team, around the calls it covers. The SDK reads usage from the reply Azure already sent, so there is no proxy and no extra network hop, and it never throws an error into your call.
- In the Azure portal, open your Azure OpenAI resource, then Resource Management › Keys and Endpoint. Copy KEY 1 and the Endpoint, and note the name of the deployment you call (under Deployments in the Azure AI Foundry portal).
- Save them as
AZURE_OPENAI_API_KEY,AZURE_OPENAI_ENDPOINTandAZURE_OPENAI_DEPLOYMENT, next toTOKEN_METER_KEY, the ingest key from Governance › API keys. - Install the packages:
pip install "tokenmeter-sdk[azure]"ornpm install @tokenmeter/sdk openai.
import { AzureOpenAI } from "openai";
import { TokenMeterClient, wrapAzureOpenAI, action } from "@tokenmeter/sdk";
const tl = new TokenMeterClient({ apiKey: process.env.TOKEN_METER_KEY ?? "" });
const azure = wrapAzureOpenAI(
new AzureOpenAI({
endpoint: process.env.AZURE_OPENAI_ENDPOINT,
apiKey: process.env.AZURE_OPENAI_API_KEY,
apiVersion: "2024-10-21",
}),
tl,
);
await action("generate-report", { customerRef: "acme", feature: "reports", team: "growth" }, () =>
azure.chat.completions.create({
model: process.env.AZURE_OPENAI_DEPLOYMENT ?? "", // your deployment's name
messages: [{ role: "user", content: "Say hello in five words." }],
}),
);
await tl.flush(); // a short script sends its usage before it exitsChat Completions and the Responses API are recorded, streaming or not. A long-running app sends usage every 2 seconds or every 500 calls; within a few seconds the call shows on Requests with its model, tokens, cost and customer. Use an id such as cus_123 for the customer, not an email address. A call with no tags still counts in every total and shows as Unattributed.
Each call becomes five separate counts: input, output, cache read, cache write and reasoning tokens. Azure uses OpenAI's field names, so Token Meter applies the OpenAI rule: cached tokens are part of the prompt total and reasoning tokens part of the completion total, so both are subtracted before pricing. A count Azure didn't report stays empty rather than guessed.
Azure cache and reasoning figures are provisional
The Azure rule is inferred from OpenAI's field names and has not yet been checked with real Azure calls. The five-call cache test that proved the rule on OpenAI has not been run on a real Azure deployment yet. Treat Azure cache and reasoning figures as provisional.
| SDK wrapper | Cost Management connection | |
|---|---|---|
| What it records | Each call your app makes, with its tags. | What Azure billed, per day. |
| Split by customer, feature, team | Yes, from the action() tags. | No. |
| How fresh | A few seconds. | Syncs once a day; today is never imported. |
| Can block a call | No; it records what already happened. | No; it only reads billing data. |
The router doesn't carry your own Azure traffic
A workspace can store its own provider key in the router only for OpenAI, Anthropic and Google. Azure OpenAI appears in the router only as an endpoint that serves GPT models on Token Meter's own accounts, for auto routing on paid plans or when a workspace pays from Token Meter credits. There is no way to send your own Azure OpenAI resource's calls through it, so for those calls use the SDK wrapper.
If you also call OpenAI directly, see OpenAI cost tracking. To turn per-customer cost into margin, see LLM cost per customer. Tag details: Attribution.
How do you check the figures against your Azure invoice?
Connect the subscription that pays for Azure OpenAI through Azure Cost Management, with a service principal that has the Cost Management Reader role. Token Meter imports what Azure billed, syncs once a day, and every day compares it with the cost it metered from your calls. A day matches when the two are within 2% of the invoice.
You need to be an Owner or Admin in Token Meter, and in Azure you need permission to register apps in Entra ID and the Owner or User Access Administrator role on the subscription.
- In the Azure portal, open Microsoft Entra ID › App registrations, choose New registration, name it
tokenmeter-billingand register it. - On its Overview, copy the Application (client) ID and the Directory (tenant) ID.
- Open Certificates & secrets › Client secrets › New client secret and copy the secret's Value right away.
- Open Subscriptions, pick the subscription that pays for Azure OpenAI, and copy its Subscription ID.
- In that subscription, open Access control (IAM) › Add › Add role assignment and assign Cost Management Reader to
tokenmeter-billing. - For each Azure OpenAI resource, copy its Resource ID from Properties. It starts with
/subscriptions/. - Optional, for token usage per deployment: on each of those resources, add the role assignments Monitoring Reader and Reader for
tokenmeter-billing. - In Token Meter, open Settings › Connections, choose Connect an account and pick Azure OpenAI. Enter the Azure subscription ID, Client secret, Tenant ID, Client ID and Azure OpenAI resource IDs (comma-separated), then choose Connect and sync.
The same service principal from a terminal, with the Azure CLI:
# Sign in and pick the subscription that pays for Azure OpenAI
az login
az account set --subscription "SUBSCRIPTION_ID"
# Create the service principal with Cost Management Reader on that subscription.
# In the output: appId = Client ID, password = Client secret, tenant = Tenant ID.
az ad sp create-for-rbac --name tokenmeter-billing \
--role "Cost Management Reader" \
--scopes /subscriptions/SUBSCRIPTION_ID
# Print the resource ID of each Azure OpenAI resource
az cognitiveservices account show --name RESOURCE_NAME \
--resource-group RESOURCE_GROUP --query id --output tsv
# Optional, for token usage per deployment: run both for each resource ID
az role assignment create --assignee APP_ID --role "Monitoring Reader" --scope RESOURCE_ID
az role assignment create --assignee APP_ID --role "Reader" --scope RESOURCE_IDThe connection only reads billing and usage data; it can't change anything in Azure and is never used to make AI calls. When you save, Token Meter only checks that the tenant, client ID and secret can sign in; the Cost Management Reader role is first tested on the first sync. Client secrets expire (one year by default with the CLI), so create a new one before then and use Edit credentials.
The first sync imports the last 7 days, and the rest, up to 90 days, follows in the background. Days are UTC, today is never requested, and the newest days can lag while Azure settles them. At 07:00 UTC each day, Token Meter compares metered spend with the invoice, per day; an Azure day is first compared after a 3-day settlement delay.
| Status | Meaning |
|---|---|
| Matched | Every reconciled day in the range is within 2%. |
| Drift detected | Invoice lines exist, and at least one day differs by more than 2%. |
| Not reconciled yet | Invoice lines are imported, but no day in the range has been compared yet. |
| Awaiting invoice | No invoice lines are imported for this provider in the range. |
On Analytics › Bill, once Azure invoice lines exist for a range, the invoice is what counts toward your total, never the invoice plus metered cost. Azure fine-tuning, realtime, audio, image and preview meters show as unmapped spend, which is normal. If you pay a negotiated rate, add it with Add a private rate under Settings › Connections (expand Advanced). Imported data is in Data health › Provider usage. See AI Bill and billing imports, and tracking AI spend across providers if Azure is one of several bills.
Why do some Azure OpenAI calls show as unpriced?
Because Azure's Responses API replies with your deployment name, not the model name. Chat Completions replies with the real model, so those calls are priced with no extra work. A deployment called prod-summarizer isn't on the price list, so tell the wrapper which model each deployment runs.
const azure = wrapAzureOpenAI(
new AzureOpenAI({
endpoint: process.env.AZURE_OPENAI_ENDPOINT,
apiKey: process.env.AZURE_OPENAI_API_KEY,
apiVersion: "2025-03-01-preview",
}),
tl,
{},
{ deploymentModelMap: { "prod-summarizer": "gpt-5-2025-08-07" } },
);In Python the map is model_map; in TypeScript it is deploymentModelMap in the fourth argument (the third takes fixed tags for every call from that client). The map applies only to Azure OpenAI.
A deployment that isn't in the map keeps its own name and is never priced at a guessed rate. It shows on Data health's Unpriced list (/data-health?tab=unpriced; Owners and Admins: Settings › Workspace › Data health, then Unpriced at the bottom of Readiness) until you add it. For Azure usage per deployment as Azure reports it, give the billing connection the optional Monitoring Reader and Reader roles above. See Providers.
How do you cap Azure OpenAI spend?
Set a budget: a monthly spend limit on the whole workspace or on one customer, feature, team, provider or model, with alerts as spend climbs. For Azure OpenAI calls made from your app, budgets warn but can't block, because an enforced budget stops only router traffic and your Azure calls go straight to Azure.
- Budgets. Owners and admins create them under Governance › Budgets. They are checked every 60 seconds against spend so far this UTC calendar month, from every connected usage source. Thresholds default to 50%, 80% and 100%, each firing once a month, and a projection alert warns when the month is on course to end over budget.
- Alert rules. A Threshold rule fires when spend for a scope, optionally limited to a provider and model, reaches an amount within the UTC day or month. A Provider spike rule fires when today's spend so far reaches a set multiple of yesterday's, scaled to the part of the day that has passed.
- Provider-side enforcement. On Governance › Rules, workspace-wide policies (those with no team or environment scope) can be turned into an Azure Policy for Azure OpenAI. It limits which models can be deployed; it is not a spend cap. Review it before you apply it: Azure aliases can match more than the exact model names.
Alerts go to email, Slack or Discord channels set up on Settings › Notifications. On the Free plan you can set one advisory, workspace-wide budget; scoped budgets, alert rules and notification channels need a paid plan. See Governance and alerts.
What doesn't this cover?
- Your own Azure OpenAI resource can't be routed through the Token Meter router; its calls are metered by the SDK (the wrapper, or the Vercel AI SDK middleware with
@ai-sdk/azure). - Azure OpenAI calls that don't go through the SDK carry no customer or feature. With the billing connection, their spend still shows in the imported Azure totals.
- Azure cache and reasoning token figures are provisional until the rule is checked with real Azure calls.
- Subscriptions billed in a currency other than US dollars are not reconciled.
- Invoice figures are not live: Azure syncs once a day, today is never imported, and the newest days can lag.
- Budgets and alert rules can warn about Azure spend made from your app, but can't refuse those calls.
- Automatic revocation of a provider key works for OpenAI and Anthropic keys only, not Azure ones.
Start tracking Azure OpenAI costs
Create a workspace, add an ingest key, wrap your Azure OpenAI client and tag one call with a customer and feature. Then connect your subscription through Azure Cost Management to check the metered cost against your bill.