API usage quotas in GCP

By John Keyes

July 19, 2024 at 13:49

google google monitoring quotas

Introduction

In a recent discussion in the #android channel it Google API quotas came up. The core concept here was that if an API key somehow got publicly leaked, how could we limit the potential cost damage to the customer.

As with the previous post on alerts, this post does not intend to be the canonical source for all things quotas in GCP. Think of it as a very light primer.

Where are the Quotas?

They can be in multiple locations. First, we’ll take a look at Google Maps quotas. Open the side bar, hover over “Google Maps Platform” entry, and select Quotas.

Quotas page

There are a number of Google Maps APIs, so the next step is to select a specific API.

Directions API quotas

Let’s use the Directions API for this post.

After selecting the Directions API, a list of quotas are displayed.

Editing a quota

Select the quota, in this case “Requests per day”, and then press the EDIT QUOTAS button near the top of the page.

Requests per day form

The edit quota form is displayed, and one of the first things we notice is the “Unlimited” checkbox is checked. To set a numeric value for this field, this checkbox must first be unchecked, and then a number can be input in the “New value” field.

What happens when a quota is exceeded?

I can’t be sure as I haven’t tested this, but based on my reading Google will return a specific 403 for this scenario.

For example, this is the type of error returned when a BigQuery quota is exceeded:

{
  "code" : 403,
  "errors" : [ {
    "domain" : "global",
    "message" : "Quota exceeded: ...",
    "reason" : "quotaExceeded"
  } ],
  "message" : "Quota exceeded: ..."
}

Alerts shortcut

As quotas and alerts are somewhat related, Google provide a shortcut to the alerts for the Google Maps API also.

Other APIs

Quotas can be applied to other APIs also. Let’s take a look at the Google Sheets API.

After clicking the “Google Sheets API” link we are brought to the API/Service details page for that API.

API/Service Details

On this service details page, there is a familiar sounding “QUOTAS AND SYSTEM LIMITS” tab.

Quota and system limits

Pressing this opens a page with a list of quotas. From here the process is very similar to above.

Editing a quota

Again we select the individual quota, and then press “EDIT QUOTAS”:

Request per minute form

A form to edit the requests per minute quota is displayed, and a new value can be entered in the “New value” field.

Summary

And that folks is a little primer on how to set quotas in GCP. As always, if you have any improvements to this post, please let me know. Thanks.

Last updated: July 19, 2024 at 13:49