How to obtain the request size in APIM integrated with AOAI.

koozo 0 Reputation points
2025-02-25T03:10:10.0566667+00:00

#Problem

RequestSize cannot be obtained in APIM and is 0 bytes, which means that the "quota" policy and alerts in metrics cannot be executed as expected.

#What I want to solve

I want to set the RquestSize.

#Background

When using AOAI, I decided to go through APIM.

The reason for using APIM is that you can use subscription keys and policies.

In the policy, I want to limit the usage fee for one day.

This needs to be set for each subscription.

As far as I could tell, it could not be set by the usage fee.

Next, I found that there were policies for "azure-openai-token-limit" and "quota".

"azure-openai-token-limit" limits by token. That's fine, but it's in 1-minute units, so it didn't meet my requirements.

"Quota" limits by data volume. I thought it would be fine. However, as I continued to verify, I found that it was only working with ResponseSize. This means it can't be used.

But is that really the case? I checked Application Insights. I noticed that the RequestSize was not set in the ApiManagementGatewayLogs. The image shows the value of "Custom Measurements" when the Request was displayed in "Search for Transactions".

Perhaps the problem is not with the "quota" policy, but with the RequestSize being 0 bytes?

Response Size: 1748

Request Size: 0

I also started it from POSTMAN, and have pasted the size from there for reference.

So, what should I do to set the RequestSize correctly?

I look forward to any advice on how to solve this. Please help me.

As additional information, the AOAI log "AzureDiagnostics" output the body size for both the Request and Response as shown below. So there is no problem with AOAI, and I have determined that it is a problem on the APIM side.

requestLength: 498

responseLength: 1018User's image

User's image

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,312 questions
{count} votes

Your answer

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