How to Generate a Google Gemini API Key (Service Account Key)
These steps will create a Google Cloud service account with the right permissions and give you a JSON key file to share securely.
1. Sign in to Google Cloud Console
-
Make sure you’re in the correct Google Cloud project that is tied to your Google Workspace / Gemini instance.
2. Enable the Vertex AI API (if not already enabled)
-
In the top search bar, type "Vertex AI API".
-
Click Enable.
- If it says “API enabled,” you can skip this step.
3. Create a Service Account
-
In the left menu, go to IAM & Admin > Service Accounts.
-
Click + CREATE SERVICE ACCOUNT.
-
Fill in:
-
Service account name:
gemini-api-access(or similar) -
Description: "Access for Gemini API calls"
-
-
Click Create and Continue.
4. Grant the Required Role
-
Under Grant this service account access, click + Select a role.
-
In the search box, type:
Vertex AI Userand select it.
-
(Optional but safer) If you want to scope it down further, you can create a custom role that only has:
aiplatform.endpoints.predictbut "Vertex AI User" is the standard.
-
Click Continue, then Done.
5. Create a JSON Key
-
In the Service Accounts list, find your new account.
-
Click the three dots (⋮) on the right > Manage keys.
-
Under Keys, click Add key > Create new key.
-
Choose JSON and click Create.
-
This downloads a file ending in
.json. -
This file is your API key.
-
6. Send the Key Securely
-
Do not email the file as an attachment.
-
Instead:
-
Upload it to a secure company file-share (e.g., Google Drive with restricted access).
-
Or use a secure password manager’s sharing feature.
-
-
Notify us when it’s shared.