User-Level Token Usage in Azure AI Foundry

Sree Aravind M 40 Reputation points
2026-10-28T08:03:42.65+00:00

We need to track token usage at the individual user level in Azure AI Foundry. Please confirm whether this is supported and provide guidance on how to identify the token consumption for each user, including input and output tokens, for monitoring and cost analysis.

Azure AI Metrics Advisor
Azure AI Metrics Advisor

An Azure artificial intelligence analytics service that proactively monitors metrics and diagnoses issues.


1 answer

Sort by: Newest
  1. AI answer

    2026-10-28T08:04:27.3633333+00:00

    Azure AI Foundry does not provide a built-in user dimension for model token metrics; to obtain per-user usage, capture the authenticated user identifier in your application and correlate it with each response’s input and output token counts.

    What is supported out of the box

    Azure Monitor automatically collects these Foundry Models usage metrics:

    • Input Tokens (InputTokens)
    • Output Tokens (OutputTokens)
    • Total Tokens (TotalTokens)

    They can be filtered or split by dimensions such as deployment, model, version, region, and API—but not by individual end user. Therefore, they provide resource-, model-, or deployment-level totals rather than user-level attribution.^1^

    To view them:

    1. In Foundry, select My assets → Models + endpoints.
    2. Select the deployment.
    3. Open Metrics.
    4. Add Input Tokens, Output Tokens, and Total Tokens.
    5. Use Total (Sum) and optionally split by ModelDeploymentName, ModelName, or ModelVersion.

    Implement per-user token tracking

    At the application/API layer, record one telemetry event for every completed model request containing:

    • A stable, non-PII user identifier, preferably a one-way pseudonymous value derived from the authenticated identity.
    • Deployment and model.
    • Timestamp and request/trace ID.
    • Input tokens.
    • Output tokens.
    • Total tokens.
    • HTTP status and, if needed, application/workload identifier.

    For Azure OpenAI chat completions, the response usage object provides prompt_tokens, completion_tokens, and total_tokens.^2^

    A simplified C# pattern is:

    var result = await openAIClient.CompleteChatAsync(messages);
    
    var userKey = HashUserId(authenticatedUserObjectId);
    var usage = result.Value.Usage;
    
    telemetry.TrackEvent("ModelTokenUsage", new()
    {
        ["userKey"] = userKey,
        ["deployment"] = deploymentName,
        ["inputTokens"] = usage.InputTokenCount.ToString(),
        ["outputTokens"] = usage.OutputTokenCount.ToString(),
        ["totalTokens"] = usage.TotalTokenCount.ToString()
    });
    

    The exact SDK property names can vary by SDK version; the important requirement is to persist the response usage values alongside the application’s authenticated-user key.

    Aggregate the resulting Application Insights events with KQL, for example:

    customEvents
    | where name == "ModelTokenUsage"
    | extend userKey = tostring(customDimensions.userKey)
    | extend input = tolong(customDimensions.inputTokens)
    | extend output = tolong(customDimensions.outputTokens)
    | extend total = tolong(customDimensions.totalTokens)
    | summarize inputTokens=sum(input),
                outputTokens=sum(output),
                totalTokens=sum(total) by userKey
    | order by totalTokens desc
    

    For streaming requests, ensure the final usage information is available before recording the event. If a provider or response mode does not return token counts, record them as unavailable rather than zero.

    Foundry agents and tracing

    If this workload uses Foundry agents, connect Application Insights:

    1. Open the Foundry project.
    2. Select Agents → Traces → Connect.
    3. Create or select an Application Insights resource.
    4. Generate agent traffic and inspect it under Traces.

    Tracing can capture execution metadata including token usage, inputs, outputs, latency, and errors. It is off by default and starts when Application Insights is connected.^3^ Conversation details can display response and token information for individual runs.^4^

    Tracing alone should not be assumed to create the business-user mapping required for chargeback. Add the pseudonymous authenticated-user identifier to your application telemetry and correlate it using the trace or response ID.

    Access requirements include:

    • Log Analytics Reader to query telemetry.
    • Privileged Monitoring Data Reader as well if the underlying tables are protected.^4^

    Tracing can contain prompts, outputs, and other customer data. Redact personal data, avoid recording secrets, and restrict telemetry access and retention.^3^

    Cost calculation and reconciliation

    For an internal per-user estimate, apply the deployment’s applicable input and output rates separately:

    estimated user cost =
        (input tokens × input rate)
      + (output tokens × output rate)
    

    Rates and billing units vary by model, deployment type, and meter.^5^

    Use Azure Cost Management or the invoice for actual financial reconciliation. Cost Analysis supports resource- and deployment-level breakdowns, but it does not replace application-side user attribution.^6^


    References

    1. Monitor model deployments in Microsoft Foundry Models
    2. Performance and latency
    3. Tracing and data handling
    4. Set up tracing in Microsoft Foundry
    5. Plan and manage costs for Microsoft Foundry
    6. Plan to manage costs for Azure OpenAI in Azure AI Foundry Models
    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.