Set up Gemini Code Assist for a project

Before you can use Gemini Code Assist, your team needs to perform the setup steps that are described in this document:

  1. Optional: Purchase a subscription to Gemini Code Assist. Gemini Code Assist is available to try at no cost until July 11, 2024, limited to one user per billing account.

  2. Activate Gemini Code Assist in a Google Cloud project. An administrator typically performs this step.

  3. Optional: To use Gemini Code Assist in an IDE, install the Cloud Code plugin.

Optional: Purchase a Gemini Code Assist subscription

Gemini Code Assist is available to try without a subscription at no cost until July 11, 2024, limited to one user per billing account. Organizations with multiple users per billing account need to purchase a subscription as described in this section. If you have existing contracts with Google Cloud, contact our sales team before purchasing a subscription.

  1. In the Google Cloud console, go to the Gemini for Google Cloud page.

    Go to Gemini for Google Cloud

  2. Click Get started with Gemini.

  3. If asked, select a billing account, and then click Continue to Admin for Gemini page.

  4. In Configure subscription, complete the fields to configure the subscription, including the commitment term (monthly or yearly) and the number of licenses in the subscription.

    Choose whether you want to auto-renew your subscription after the commitment term (monthly or yearly). Auto-renew keeps your subscription and licenses active. If the subscription doesn't auto-renew, it ends when the current term ends, and you need to go through the purchase process again to regain the licenses.

  5. To review the subscription details, click Continue.

  6. If you agree to the terms, click Complete Purchase, and then confirm your subscription.

Billing is now enabled for Gemini. You now need to activate Gemini Code Assist in one or more projects that are associated with this billing account. Users won't see Gemini until you activate it in at least one project.

Activate Gemini Code Assist in a Google Cloud project

To activate Gemini Code Assist in a Google Cloud project, an administrator needs to enable the Cloud AI Companion API and grant the Cloud AI Companion User and Service Usage Viewer IAM roles to users.

Console

  1. To enable the Cloud AI Companion API, go to the Gemini for Google Cloud page.

    Go to Gemini for Google Cloud

  2. In the project selector, select a project.

  3. Click Enable.

    The page updates and shows a status of Enabled. Gemini is now available in the selected Google Cloud project to all users who have the required IAM roles.

  4. To grant the IAM roles that are required to use Gemini, go to the IAM & Admin page.

    Go to IAM & Admin

  5. In the Principal column, find a principal for which you want to enable access to Gemini, and then click Edit principal in that row.

  6. In the Edit access pane, click Add another role.

  7. In Select a role, select Cloud AI Companion User.

  8. Click Add another role and select Service Usage Viewer.

  9. Click Save.

gcloud

  1. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

  2. In the project selector drop-down list, select a project.

  3. Enable the Cloud AI Companion API for Gemini using the gcloud services enable command:

    gcloud services enable cloudaicompanion.googleapis.com
    

    If you want to enable the Cloud AI Companion API for a different Google Cloud project, add the --project parameter:

    gcloud services enable cloudaicompanion.googleapis.com --project PROJECT_ID
    

    Replace PROJECT_ID with your Google Cloud project ID.

    The output is similar to the following:

    Waiting for async operation operations/acf.2e2fcfce-8327-4984-9040-a67777082687 to complete...
    Operation finished successfully.
    

    Gemini is now available in the specified Google Cloud project to all users who have the required IAM roles.

  4. Grant the two IAM roles that are required to use Gemini:

    1. Grant the Cloud AI Companion User role:

      gcloud projects add-iam-policy-binding  PROJECT_ID \
          --member=PRINCIPAL --role=roles/cloudaicompanion.user
      

      Replace PRINCIPAL with the identifier for the principal. The identifier takes the form user|group|serviceAccount:email or domain:domain—for example, user:cloudysanfrancisco@gmail.com, group:admins@example.com, serviceAccount:test123@example.domain.com, or domain:example.domain.com.

      The output is a list of policy bindings that includes the following:

      - members:
        - user:PRINCIPAL
        role: roles/cloudaicompanion.user
      
    2. Grant the Service Usage Viewer role:

      gcloud projects add-iam-policy-binding  PROJECT_ID \
          --member=PRINCIPAL --role=roles/serviceusage.serviceUsageViewer
      

      The output is a list of policy bindings that includes the following:

      - members:
        - user:PRINCIPAL
        role: roles/serviceusage.serviceUsageViewer
      

    For more information, see Grant a single role and gcloud projects add-iam-policy-binding.

All of the users who have been granted these roles can access Gemini features in the Google Cloud console within the specified project. For more information, see Use Gemini for AI assistance and development.

Optional: Use Gemini Code Assist in an IDE

If you're a developer who wants to use Gemini in your IDE, then you need to install the Cloud Code plugin. For more information, see the following:

Advanced setup tasks

Instead of using the Google Cloud console or the gcloud CLI to grant predefined IAM roles, you can do any of the following:

  • Use IAM REST APIs or IAM client libraries to grant roles.

    If you use these interfaces, use the fully qualified role names:

    • roles/cloudaicompanion.user
    • roles/serviceusage.serviceUsageViewer

    For more information about granting roles, see Manage access to projects, folders, and organizations.

  • Create and grant custom roles.

    Any custom roles that you create need the following permissions to access Gemini:

    • cloudaicompanion.companions.generateChat
    • cloudaicompanion.companions.generateCode
    • serviceusage.services.get

What's next