Reputation: 11
I'm trying to send the below API translate request to the Microsoft Azure text translation API but get an unexpected error with code 429001 and message "The server rejected the request because the client has exceeded request limits.". The request is trying to translate 190 HTML strings with a total content-length of 45099.
Based on this documentation, the limits should be 50000 for content length and 1000 for number of strings to translate, my request is well under both of these.
Sending short requests with 2 HTML strings to translate works for me. I've reproduced the problem from the command line using httpie, it originally appeared in an HTTPS request from Java code. Both ways lead to the same result. And in case it is relevant, I'm on a "F0 Free" Azure subscription tier.
Why do I get the 429 error code?
I'm fine with having to observer certain request limitations but would like to figure out if either a) the documentation is wrong and what the real limits are or b) what I'm doing wrong/misunderstanding in the documentation
And for bonus points, what is the distinction between the 429000, 429001 and 429002 error codes, all of which are documented as "The server rejected the request because the client has exceeded request limits."?
Here is the request with key and region X-ed out and body shortened because of StackOverflow question body limit (see this gist for the full request and response):
POST /translate?api-version=3.0&from=de&to=en&textType=html HTTP/1.1
Connection: keep-alive
Content-Length: 45099
User-Agent: Java/17.0.1
Accept: application/json; charset=UTF-8
Content-Type: application/json; charset=UTF-8
Ocp-Apim-Subscription-Key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Ocp-Apim-Subscription-Region: XXXXXXXXXXXXXXXXXX
Host: api.cognitive.microsofttranslator.com
[{"Text":"<DIV/><DIV/> <DIV/> <DIV/> <DIV/><DIV/><DIV/>Geringe Entdeckungswahrscheinlichkeit der Fehlfunktion, da Nachweisverfahren unsicher bzw. keine Erfahrung mit dem festgelegten Nachweisverfahren<DIV/><DIV/>\r\n \r\n "},{"Text":"<DIV/><DIV/.... verhindert<DIV/>"}]
Response:
HTTP/1.1 429 Too Many Requests
Date: Wed, 22 Nov 2023 09:20:34 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Expose-Headers: X-RequestId
X-RequestId: 5d465614-96dc-42b1-a676-ed5fb08fa641.EUWE.1122T0920
X-Content-Type-Options: nosniff
Strict-Transport-Security: max-age=31536000; includeSubDomains
{"error":{"code":429001,"message":"The server rejected the request because the client has exceeded request limits."}}
Upvotes: 0
Views: 909
Reputation: 11
Thanks to a comment by @RishabhM I was able to solve the mystery.
The returned error "The server rejected the request because the client has exceeded request limits."
does indeed refer to "Character limits per hour" - which seem to be enforced on a sliding window per minute. See the linked documentation page
With my "F0 Free" subscription tier, the hourly limit is 2 million characters, i.e. around 33,000 characters per minute. As my single request has more than 33,000 characters, it is rejected right away.
I've tested this with sending three (identical) requests of around 13,000 characters each right after each other. The first two get translated, the third request - which brings the total above 33,000 - gets rejected with the above error message.
After waiting for a minute I get the same behavior again.
The documentation on the linked page is somewhat vague on the "Character limits per hour":
The hourly quota should be consumed evenly throughout the hour. [...] You're likely to receive an out-of-quota response under the following circumstances:
You've reached or surpass the quota limit. You've sent a large portion of the quota in too short a period of time.
The error message could also be improved, pointing to the "limits per hour", especially as these limits can supersede the per request limits documented above.
Upvotes: 1