Stay organized with collections
Save and categorize content based on your preferences.
This page describes how to configure quotas for your API in
Cloud Endpoints Frameworks. For an overview of the functionality provided by
quotas, see
About quotas.
Java
The following procedure assumes that you have already:
Configured your API to use an API key. This is needed so that
Endpoints Frameworks can identify the
Google Cloud project that the calling application is
associated with. See
Sharing APIs protected by API key
for more information.
To configure quotas on your API:
In the file that contains the
API-scoped annotations,
add the following to your @Api annotation:
Replace YOUR_METRIC_NAME with a name that
describes the API requests counter.
Replace YOUR_METRIC_DISPLAY_NAME with the text
that is displayed on Endpoints > Services > Quotas page
to identify the quota.
Replace YOUR_QUOTA_LIMIT with an integer value.
This is the number of requests that an application associated with a
consumer's Google Cloud project can make in a minute. For
example:
Configured your API to use an API key. This is needed so that
Endpoints Frameworks can identify the
Google Cloud project that the calling application is
associated with. See
Sharing APIs protected by API key
for more information.
To configure quotas on your API:
In the file that contains the
API decorator,
create a list of LimitDefinition instances, similar to the following:
Replace YOUR_METRIC_NAME with a name that describes
the API requests counter.
Replace YOUR_METRIC_DISPLAY_NAME with the text
that is displayed on Endpoints > Services > Quotas page
to identify the quota.
Replace limit with an integer value. This is the number of requests
that an application associated with a consumer's Google Cloud
project can make in a minute. For example:
For each method that you want to apply a quota to, assign a dictionary
to the METRIC_COSTS argument of the
method decorator.
The key must be a name that you specified in the limit_definitions
argument to the API decorator, and the value is an integer that specifies
the cost for each request. For example:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003eThis page details the process of configuring quotas for APIs within Cloud Endpoints Frameworks for both Java and Python environments.\u003c/p\u003e\n"],["\u003cp\u003eThe configuration requires defining quota metrics with names, display names, and limits, specifying the maximum number of requests allowed per minute for a given Google Cloud project.\u003c/p\u003e\n"],["\u003cp\u003eQuotas are applied to specific methods within an API by defining metric costs, which are then linked to previously defined quota metrics.\u003c/p\u003e\n"],["\u003cp\u003eThe content provided also references that these are Pre-GA features that are available "as is" and might have limited support.\u003c/p\u003e\n"],["\u003cp\u003ePre-requisite steps like writing and annotating code, adding api management and deploying the api are required before configuration.\u003c/p\u003e\n"]]],[],null,["# Configuring quotas\n\n| **Beta**\n|\n|\n| This feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\nThis page describes how to configure quotas for your API in\nCloud Endpoints Frameworks. For an overview of the functionality provided by\nquotas, see\n[About quotas](/endpoints/docs/frameworks/quotas-overview). \n\n### Java\n\nThe following procedure assumes that you have already:\n\n- [Written and annotated the code](/endpoints/docs/frameworks/java/annotate-code) for your API.\n- [Added API management](/endpoints/docs/frameworks/java/adding-api-management).\n- [Deployed your API](/endpoints/docs/frameworks/java/test-deploy).\n- Configured your API to use an API key. This is needed so that Endpoints Frameworks can identify the Google Cloud project that the calling application is associated with. See [Sharing APIs protected by API key](/endpoints/docs/frameworks/java/restricting-api-access-with-api-keys-frameworks#sharing_apis_protected_by_api_key) for more information.\n\nTo configure quotas on your API:\n\n1. In the file that contains the\n [API-scoped annotations](/endpoints/docs/frameworks/java/annotations),\n add the following to your @Api annotation:\n\n ```\n limitDefinitions = {\n @ApiLimitMetric(\n name = \"YOUR_METRIC_NAME\",\n displayName = \"YOUR_METRIC_DISPLAY_NAME\",\n limit = YOUR_QUOTA_LIMIT)\n }\n ```\n - Replace \u003cvar translate=\"no\"\u003eYOUR_METRIC_NAME\u003c/var\u003e with a name that describes the API requests counter.\n - Replace \u003cvar translate=\"no\"\u003eYOUR_METRIC_DISPLAY_NAME\u003c/var\u003e with the text that is displayed on **Endpoints** \\\u003e **Services** \\\u003e **Quotas** page to identify the quota.\n - Replace \u003cvar translate=\"no\"\u003eYOUR_QUOTA_LIMIT\u003c/var\u003e with an integer value.\n This is the number of requests that an application associated with a\n consumer's Google Cloud project can make in a minute. For\n example:\n\n @Api(\n name = \"echo\",\n version = \"v1\",\n namespace =\n @ApiNamespace(\n ownerDomain = \"echo.example.com\",\n ownerName = \"echo.example.com\",\n packagePath = \"\"\n ),\n limitDefinitions = {\n @ApiLimitMetric(\n name = \"read-requests\",\n displayName = \"Read requests\",\n limit = 1000),\n @ApiLimitMetric(\n name = \"list-requests\",\n displayName = \"List requests\",\n limit = 100),\n @ApiLimitMetric(\n name = \"write-requests\",\n displayName = \"Write requests\",\n limit = 50),\n }\n )\n\n2. For each method that you want to apply a quota to, add the following\n to the `@ApiMethod` annotation:\n\n ```\n metricCosts = {\n @ApiMetricCost(\n name =\"YOUR_METRIC_NAME\",\n cost = YOUR_COST)\n }\n ```\n - Replace \u003cvar translate=\"no\"\u003eYOUR_METRIC_NAME\u003c/var\u003e with a name that you specified in the `limitDefinitions` parameter in the `@Api` annotation.\n - Replace \u003cvar translate=\"no\"\u003eYOUR_COST\u003c/var\u003e with an integer value that\n specifies the cost for each request.\n\n For example: \n\n @ApiMethod(name = \"echo\",\n metricCosts = {\n @ApiMetricCost(\n name = \"read-requests\",\n cost = 1)\n })\n public Message echo(Message message, @Named(\"n\") @Nullable Integer n) {\n // ...function code here...\n }\n\n3. [Deploy the API](/endpoints/docs/frameworks/java/test-deploy).\n\nSee the following for more information on the annotations used in quotas:\n\n- [`@ApiLimitMetric`](/endpoints/docs/frameworks/java/annotations#apilimitmetric)\n- [`@ApiMethod`: Method-scoped annotations](/endpoints/docs/frameworks/java/annotations#apimethod_method-scoped_annotations)\n\n### Python\n\nThe following procedure assumes that you have already:\n\n- Installed version 2.4.5 or later of the Endpoints Frameworks library.\n- [Created your API](/endpoints/docs/frameworks/python/create_api).\n- [Created a web server](/endpoints/docs/frameworks/python/api_server).\n- [Added API management](/endpoints/docs/frameworks/python/adding-api-management).\n- [Deployed your API](/endpoints/docs/frameworks/python/test-deploy).\n- Configured your API to use an API key. This is needed so that Endpoints Frameworks can identify the Google Cloud project that the calling application is associated with. See [Sharing APIs protected by API key](/endpoints/docs/frameworks/python/restricting-api-access-with-api-keys-frameworks#sharing_apis_protected_by_api_key) for more information.\n\nTo configure quotas on your API:\n\n1. In the file that contains the\n [API decorator](/endpoints/docs/frameworks/python/decorators-reference#defining_the_api_endpointsapi),\n create a list of `LimitDefinition` instances, similar to the following:\n\n ```\n quota_limits = [\n endpoints.LimitDefinition(\n \"YOUR_METRIC_NAME\",\n \"YOUR_METRIC_DISPLAY_NAME\",\n limit)\n ]\n ```\n - Replace \u003cvar translate=\"no\"\u003eYOUR_METRIC_NAME\u003c/var\u003e with a name that describes the API requests counter.\n - Replace \u003cvar translate=\"no\"\u003eYOUR_METRIC_DISPLAY_NAME\u003c/var\u003e with the text that is displayed on **Endpoints** \\\u003e **Services** \\\u003e **Quotas** page to identify the quota.\n - Replace `limit` with an integer value. This is the number of requests\n that an application associated with a consumer's Google Cloud\n project can make in a minute. For example:\n\n quota_limits = [\n endpoints.LimitDefinition('read-requests', 'Read Requests', 1000),\n endpoints.LimitDefinition('list-requests', 'List Requests', 100),\n endpoints.LimitDefinition('write-requests', 'Write Requests', 50),\n ]\n\n2. Add your quota to the API decorator by assigning it to the\n `limit_definitions` argument. For example:\n\n @endpoints.api(name='bookstore',\n version='v1',\n limit_definitions=quota_limits)\n\n3. For each method that you want to apply a quota to, assign a dictionary\n to the \u003cvar translate=\"no\"\u003eMETRIC_COSTS\u003c/var\u003e argument of the\n [method decorator](/endpoints/docs/frameworks/python/decorators-reference#defining_an_api_method_endpointsmethod).\n The key must be a name that you specified in the `limit_definitions`\n argument to the API decorator, and the value is an integer that specifies\n the cost for each request. For example:\n\n @endpoints.method(path='shelves/{shelf}',\n http_method='GET',\n metric_costs={'read-requests': 1})\n def get_shelf(self, request):\n # ...function code here...\n\n4. [Deploy the API](/endpoints/docs/frameworks/python/test-deploy).\n\nSee the following for more information on the decorators used in quotas:\n\n- [`limit_definitions`](/endpoints/docs/frameworks/python/decorators-reference#limit_definitions)\n- [Defining an API method (`@endpoints.method`)](/endpoints/docs/frameworks/python/decorators-reference#defining_an_api_method_endpointsmethod)"]]