Hi fredrikfridborn,
Thanks for reaching out to Microsoft Q&A.
To track token usage in Azure OpenAI deployments and filter by a custom UUID for each request, you can consider the following approach:
Embedding Metadata in Requests: When you send a request to the Azure OpenAI endpoint, include the UUID in a way that you can track it later, like within the request headers or payload. Although Azure OpenAI doesn’t directly support custom metadata, you can log this in your application layer.
Custom Logging and Metrics Collection:
- In your application that interacts with Azure OpenAI, you can log the UUID along with the token usage for each completion request. Azure OpenAI responses contain token usage information (prompt tokens, completion tokens, and total tokens).
- Use Azure Monitor Logs or Azure Application Insights to track these custom logs. You can send custom logs from your application to Application Insights, including both the UUID and token usage.
- Token Usage Monitoring:
- After receiving the response from Azure OpenAI, extract the token usage data from the response ('usage' object in the API response).
- Combine the UUID and token usage in a custom metric and send it to Azure Monitor using Azure Monitor Custom Metrics or Application Insights.
- This will allow you to filter and split the token usage based on the UUID in your monitoring dashboard.
Visualizing in Azure Monitor:
- Use Azure Metrics Explorer or Azure Log Analytics to create visualizations based on the custom metric you’ve sent (e.g., token usage per UUID). You can filter and split by UUID in your dashboards.
Here is the general flow:
- Send request with UUID.
- Receive token usage in response.
- Log UUID and token usage.
- Push custom metrics to Azure Monitor/Application Insights.
- Create filters and visualizations based on UUID.
Please 'Upvote'(Thumbs-up) and 'Accept' as an answer if the reply was helpful. This will benefit other community members who face the same issue.