Loging ModelNames in API mangement for Background requests

Bakker, J. (Jeffrey) 0 Reputation points
2026-06-26T10:27:15.4366667+00:00

Hello.

Im using the llm-emit-token-metric policy to log token metric so that we can distribute cost across projecst in our company.

This works fine for most request. there are however. When you do a background request to a gpt model by setting background to true in the body. It starts proccessing the response in the background and you can latter get it using a get and a response_id. whe it completes the llm-emit-token-metric logs the tokens. however on the get we only know the model when we get ther response back since for get calls you only send the response id and not the model name. And the llm-emit-token-metric can only be put in the inbound section. So is there a way to ad the modelname as custum dimension for llm-emit-token-metric when using background requests?

best of regards,

Jeffrey Bakker

Azure API Management
Azure API Management

An Azure service that provides a hybrid, multi-cloud management platform for APIs.


1 answer

Sort by: Most helpful
  1. Sina Salam 30,486 Reputation points Volunteer Moderator
    2026-06-28T14:54:37.47+00:00

    Hello Bakker, J. (Jeffrey),

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    I understand that your Login ModelNames in API mangement for Background requests is having isue.

    This issue fix is only by correlating the background POST and GET. The model name cannot be reliably added from the GET response because llm-emit-token-metric runs in inbound policy. Use an external Redis-compatible cache or durable correlation store, store response_id > model during the POST, retrieve it during the GET, and pass it as the ModelName dimension. Avoid adding response_id permanently as a metric dimension because it is high-cardinality and can hit Azure Monitor custom metric limits.

    Use the below resource links for more reading and implementation steps:


    Please do not close the thread by upvoting and accepting the answer if any part of it is helpful.

    Was this answer helpful?

    0 comments No comments

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.