API キーは、割り当て、課金、モニタリングのためにGoogle Cloud プロジェクトを識別する単純な文字列です。デベロッパーは、Google Cloud コンソールでプロジェクトの API キーを生成し、このキーをクエリ パラメータとして、またはリクエスト ヘッダーとしてすべての API 呼び出しに埋め込みます。
API 構成で API キーを必須として指定した場合、API Gateway はその API キーを使用して、関連付けられた Google Cloud プロジェクトを検索します。現在お使いの Google Cloud プロジェクトまたは API が有効になっている他のGoogle Cloud プロジェクトで API キーが生成されていない場合、API ゲートウェイ はリクエストを拒否します。
API キーを作成するか、 Google Cloud プロジェクト内ですでに使用可能な API キーを表示するには、[API とサービス] > [認証情報] ページに移動します。
API キーは、デフォルトでは制限されません。制限されていないキーは、誰でもどこからでも使用できるため安全ではありません。可能な限り、API の制限を追加することをおすすめします。API の制限では、API キーを使用した呼び出しを許可する API を指定します。本番環境アプリケーションで使用されるすべての API キーには、API 制限を追加する必要があります。
API の制限を追加するには:
API 構成に記載されている API のタイトルを確認します。次の例では、API のタイトルは My Example Config です。
# openapi.yamlswagger:'2.0'info:title:My Example Configdescription:Sample API on API Gatewayversion:1.0.0...
Google Cloud コンソールで、[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-04-22 UTC。"],[[["\u003cp\u003eAPI keys are simple strings used to identify a Google Cloud project for quota, billing, and monitoring in API Gateway.\u003c/p\u003e\n"],["\u003cp\u003eAPI Gateway requires API keys generated within your Google Cloud project, or projects where your API is enabled, to authorize requests.\u003c/p\u003e\n"],["\u003cp\u003eWhile useful for features like quotas, API keys are vulnerable to man-in-the-middle attacks and should not be the sole form of authentication for sensitive data.\u003c/p\u003e\n"],["\u003cp\u003eEnabling API key support for a service requires using the \u003ccode\u003egcloud services enable MANAGED_SERVICE_NAME\u003c/code\u003e command, specifying the managed service's name.\u003c/p\u003e\n"],["\u003cp\u003eFor security, API keys should be restricted to specific APIs through the Google Cloud console's \u003cstrong\u003eAPIs & Services > Credentials\u003c/strong\u003e page, ensuring they are not used by unauthorized parties.\u003c/p\u003e\n"]]],[],null,[]]