設定應用程式預設憑證

如要在 Gemini Enterprise Agent Platform 使用 Gemini,請使用 Google Cloud API 金鑰應用程式預設憑證進行驗證。建議您使用 API 金鑰進行測試,並使用應用程式預設憑證進行實際工作環境。本頁說明如何設定應用程式預設憑證。

事前準備

選取專案、啟用帳單功能、啟用 Agent Platform API、安裝 gcloud CLI

  1. 登入 Google 帳戶。

    如果沒有帳戶,請 註冊新帳戶

  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Agent Platform API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  5. 安裝 Google Cloud CLI。

  6. 若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI

  7. 執行下列指令,初始化 gcloud CLI:

    gcloud init
  8. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  9. Verify that billing is enabled for your Google Cloud project.

  10. Enable the Agent Platform API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  11. 安裝 Google Cloud CLI。

  12. 若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI

  13. 執行下列指令,初始化 gcloud CLI:

    gcloud init

建立本機驗證憑證

控制台

如果您使用本機殼層,請為使用者帳戶建立本機驗證憑證:

gcloud auth application-default login

如果您使用 Cloud Shell,則不需要執行這項操作。

如果系統傳回驗證錯誤,且您使用外部識別資訊提供者 (IdP),請確認您已 使用聯合身分登入 gcloud CLI

curl

執行下列指令來安裝及執行 gcloud,設定應用程式預設憑證:

curl -sSL https://storage.googleapis.com/cloud-samples-data/adc/setup_adc.sh

發出第一項 API 要求

設定應用程式預設憑證後,請參閱 API 快速入門導覽課程,瞭解如何發出第一個要求。