Cloud Endpoints 提供配額,讓您控管應用程式呼叫您 API 的頻率。您可以設定配額來指定使用量限制,藉此保護 API 免於收到呼叫應用程式的過量要求。過多的要求可能源自於簡單的打字錯誤,或是設計不佳的系統導致不必要的 API 呼叫。無論原因為何,一旦來源的流量達到特定程度,就必須封鎖該來源的流量,才能確保 API 的整體健康。設定配額可確保單一應用程式不會對使用 API 的其他應用程式造成負面影響。
本頁面提供與配額相關的重要功能總覽。
要求與用戶專案相連結
設定配額後,Endpoints 即會追蹤每個消費者 Google Cloud 專案在每分鐘提出要求的次數。每個呼叫 API 的應用程式都必須符合以下條件:
您可以讓 API 消費者在Google Cloud 控制台建立自己的專案,也可以為他們建立專案。由於 Endpoints 會以「專案」為單位執行配額限制,因此您必須為每個 API 用戶準備一項專案。
限制每分鐘提出的要求次數
您可以透過設定配額,限制每分鐘對整個 API 提出的要求次數;或者只限特定方法的要求次數。如果來自用戶專案的用戶端程式碼超過您設定的限制,則要求會在存取您的 API 之前遭拒,而系統則會傳回 HTTP 狀態碼 429 too many
requests。呼叫應用程式必須處理 429 狀態碼的問題,並使用指數輪詢或其他重試邏輯,以降低對 API 的呼叫頻率。
設定一或多個配額
您可以設定一或多個已命名的配額,並為每個配額指定不同的頻率限制。例如,您的 API 可能具備某些會大量消耗資源的方法 (例如執行複雜查詢並傳回大型結果清單的方法),也可能包含其他較為快速且輕量的方法。因此,您可能會想要設定兩個頻率限制相異的配額,將大量消耗資源的方法與其中一個配額建立關聯,並將輕量方法和另一個配額建立關聯。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-09 (世界標準時間)。"],[[["Cloud Endpoints uses quotas to control the rate at which applications can call an API, protecting it from excessive requests and ensuring that one application's usage doesn't negatively impact others."],["Quotas are enforced per consumer Google Cloud project, requiring each application to have a project, enable the API, and send an API key for tracking."],["Setting a quota can limit requests per minute for the entire API or specific methods, rejecting requests exceeding the limit with an HTTP 429 status code."],["Multiple named quotas can be configured with different rate limits for resource-intensive and lightweight methods, and costs can be assigned to methods to vary their consumption of the same quota."],["Configured quota limits can be overridden for specific consumer projects via the Endpoints \u003e Services page, allowing for customized limits per project."]]],[]]