1

I am trying to do a simple call to get the email address of an account:

gmail().users().getProfile("me").execute().getEmailAddress();

However it always returns a user-rate-limited response:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 429 unknown
{
  "code" : 429,
  "errors" : [ {
    "domain" : "usageLimits",
    "message" : "User-rate limit exceeded.  Retry after 2019-09-18T18:49:00.748Z",
    "reason" : "rateLimitExceeded"
  } ],
  "message" : "User-rate limit exceeded.  Retry after 2019-09-18T18:49:00.748Z"
}

Regardless of waiting after the time mentioned, it always is returning this response. I had it retry for once an hour for the past 14 hours and it is still giving this response. I have checked my API quota and confirmed there is no other usage of the user for GMail in the timeframe.

I do have exponential backoff implemented, however due to an internal issue on my script yesterday there were many requests in a short period of time to the GMail API. As expected it hit the rate limit, but it appears that the rate limitation has not "turned off" since. Is this user-account blacklisted? How can I get the account up and running again?

  • It seems like the sending limits are bound to the whole account (that has sets of many email addresses/aliases) ? Google is so confusing. – Martin Zvarík Jun 26 '23 at 08:41

2 Answers2

2

According to Gmail API documentation:

Mail Sending Limits The Gmail API enforces the standard daily mail sending limits.

If these limits are exceeded a HTTP 429 Too Many Requests "User-rate limit exceeded" error mentioning "(Mail sending)" is returned with a time to retry.

The email sending limits

are applied over a rolling 24-hour period.

This explains why you needed to wait 24 hours since the original issue.

Have a look at the email sending limits, so you know which quota you exceeded and need avoid it in the future.

ziganotschka
  • 25,866
  • 2
  • 16
  • 33
  • Hi @ziganotschka I stumbled upon this thread as I was looking for "User-rate limit exceeded. Retry after " error from Gmail API. In my case, I am using messages().get method. Even in the original question, it was 'get' request. So, I don't understand how email 'sending' limits will apply for a get request? Am I missing something? Thanks. – Urjit Jul 13 '20 at 12:05
  • It specifies [here](https://developers.google.com/gmail/api/v1/reference/quota): `usage limit that applies to ALL requests made from your application` and `Per User Rate Limit: 250 quota units per user per second` and `messages.get: 5 quota units`. – ziganotschka Jul 13 '20 at 12:43
  • Thanks for your response. I was focused on the 'per-user limits' section on that page, and it only mentions sending / bandwidth limits and concurrent req. Also, the per-method quota usage section starts off by mentioning "Daily usage limit" So, at least I find this page quite confusing. Just to be sure I understood this right, I can make at most 5 message.get calls per second, and the 6th call will result in user-rate limit exceeded (for simplicity, keeping aside the moving avg allowing short bursts aspect)? – Urjit Jul 14 '20 at 06:05
  • Should be more like 50 calls per second, but it depends on how they calculate the rate (per second? per minute? per 100 miliseconds?)? Basically - if you keep getting the error - decrease your request speed, e.g. with exponential backoff. – ziganotschka Jul 14 '20 at 07:01
0

Maybe the answer is patience, or maybe it's luck. But now after roughly 24 hours since the original issue with the requests my account appears to be working again.