Capping API Usage

Depending on the API, you can explicitly cap requests in a variety of ways, including: requests per day, requests per 100 seconds, and requests per 100 seconds per user.

You might want to limit the billable usage by setting caps. For example, to prevent getting billed for usage beyond the free courtesy usage limits, you can set requests per day caps.

Modify the number of requests

You can set limits to all requests to any billable API. Most APIs set default limits, but you can change that limit up to a maximum specified by Google. Some APIs set a very low limit until you enable billing on your project.

To view or change the limits for your API, do the following:

  1. Go to the GCP Console APIs & Services Dashboard page.
  2. From the projects list, select a project or create a new one.
  3. Click the name of the API you're interested in.
  4. Click Quotas.
  5. On the quota line you want to change, click the edit icon (edit), then enter your preferred total quota, up to the limit specified by Google.

Some APIs allow you to request a higher limit by submitting a form. Some APIs allow access to higher quotas only if billing is enabled on the project.

Limiting requests per second per user

To prevent individual users from using up your API quota, limit the number of requests per second per user for an API. Each API includes a default per-user limit, but you can modify that value as described in the previous section.

Individual users are identified by a unique string; if you're creating a server-side application (where the calling code is hosted on a server that you own) that makes requests on behalf of users, your requests must include the quotaUser parameter, as described below.

To identify a user, use the quotaUser=userID parameter. This value is for short term quota enforcement only, so you don't need to use a real user ID. You can choose any arbitrary string under forty characters long that uniquely identifies a user.

The quotaUser parameter is only used for capping requests per user per second. If you don't send the quotaUser parameter, then all calls are attributed to your server machines, in which case calls can't be capped by user.

View and edit all quotas for APIs in a project

You can review, edit, and request higher quota limits for all billable APIs in a given project by viewing the Quotas page found in IAM & admin.

To view and edit quotas for all billable APIs in your project, do the following:

  1. Go to the GCP Console Quotas page in IAM & admin.
  2. From the projects list, select a project or create a new one.
    The Quotas page for the selected project is displayed, listing one line item for each type of quota available in each service.
  3. Use the filters at the top of the page to adjust the list by Quota type, Service, Metric, and/or Location.
  4. To edit multiple quotas, click +EDIT QUOTAS and click the checkbox next to each quota to select one or more quotas to edit. Billing must be enabled on the project in order to click the checkboxes.
  5. In the Edit Quotas panel on the right, complete the form with your Name, Email address, and Phone number, then click Next.
  6. In the Edit Quotas panel, select the service to expand the view, then edit the quotas in that service and click Done.
  7. Repeat to edit the quotas in each of the selected services.
    • A service with an alert icon (error) has not yet been edited.
    • You can add more quotas to edit by selecting them from the list on the left.
    • You can remove a service from the Edit Quotas panel by clicking the delete icon (delete).
  8. When you are done editing quotas, click Submit request.
Czy ta strona była pomocna? Podziel się z nami swoją opinią:

Wyślij opinię na temat...