Search code examples
gmail-api

Gmail API Global Per Second Rate Limit


I need to be able to correctly catch and handle global rate limit errors returned from the Gmail API. How will I be able to differentiate between per-user rate limit errors and global rate limit errors?

I can't find any explicit documentation for this, but I assume that the domain attribute in the response payload will say global instead of usageLimits. Can anyone verify if this is correct?

Example below of what I assume a global rate limit error looks like

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "message": "Rate Limit Exceeded",
    "reason": "rateLimitExceeded",
   }
  ],
  "code": 403,
  "message": "Rate Limit Exceeded"
 }
}

Solution

  • You can check this by forcing the quota limit rate error for user and for domain. If you’re the admin, in Google Cloud platform console (console.cloud.google.com) you can edit, for each project and each API, the total quota rate limit and per user. Read the instructions on how to edit quota limits [1].

    You can see the “quota units” used per each Gmail API method here [2].

    About the error messages, i forced both limits as explained before and got this:

    For user:

    "errors": [
    
        "domain": "usageLimits",
        "reason": "userRateLimitExceeded",
        "message": "User Rate Limit Exceeded. Rate of requests for user exceed configured project quota. You may consider re-evaluating expected per-user traffic to the API and adjust project quota limits accordingly. You may monitor aggregate quota usage and adjust limits in the API Console: XXXXX",
        "extendedHelp": "XXXXX"
      ]
    

    Where i put the XXXXX there’s a url to modify the quota limits of that project.

    For domain (total):

      "errors": [
    
        "domain": "usageLimits",
        "reason": "rateLimitExceeded",
        "message": "Rate Limit Exceeded"
       ]
    

    [1] https://cloud.google.com/apis/docs/capping-api-usage

    [2] https://developers.google.com/gmail/api/v1/reference/quota