הגדרת Application Default Credentials

כדי להשתמש ב-Gemini ב-Gemini Enterprise Agent Platform, צריך לבצע אימות באמצעות מפתח API שלGoogle Cloud או באמצעות אישורי ברירת מחדל של האפליקציה. מומלץ להשתמש במפתח API לבדיקות וב-Application Default Credentials לייצור. בדף הזה מוסבר איך להגדיר פרטי כניסה שמוגדרים כברירת מחדל לאפליקציה.

לפני שמתחילים

בוחרים פרויקט, מפעילים את החיוב, מפעילים את Agent Platform API ומתקינים את ה-CLI של gcloud

  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, if it is not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the API

  5. Install the Google Cloud CLI.

  6. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  7. To initialize the gcloud CLI, run the following command:

    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, if it is not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the API

  11. Install the Google Cloud CLI.

  12. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  13. To initialize the gcloud CLI, run the following command:

    gcloud init

יצירת פרטי כניסה לאימות מקומי

המסוף

אם אתם משתמשים במעטפת מקומית, צריך ליצור פרטי כניסה לאימות מקומי עבור חשבון המשתמש:

gcloud auth application-default login

אם אתם משתמשים ב-Cloud Shell, אתם לא צריכים לעשות את זה.

אם מוחזרת שגיאת אימות ואתם משתמשים בספק זהויות חיצוני (IdP), ודאו ש נכנסתם ל-CLI של gcloud באמצעות המאגר המאוחד לניהול זהויות.

curl

מריצים את הפקודה הבאה כדי להתקין ולהפעיל את gcloud כדי להגדיר את פרטי ברירת המחדל של האפליקציה:

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

שליחת בקשת ה-API הראשונה

אחרי שמגדירים Application Default Credentials, אפשר לקרוא את המדריך לתחילת העבודה עם API כדי ללמוד איך לשלוח את הבקשה הראשונה.