We are encountering authentication issues while trying to access the Google Vertex AI API.
Below are the steps we have taken in our production environment and the corresponding issue.We have verified the service account roles, key file integrity, and environment variable configurations but are unable to resolve the issue. We would appreciate your guidance on resolving this problem
Steps Undertaken:
1. Service Account Creation and Configuration:
- Service Account with JSON Key: We created a service account and generated a JSON key in the production environment by navigating to "IAM & Admin" > "Service Accounts" > "CREATE SERVICE ACCOUNT".
- Role Configuration: We assigned the following roles to the service account:
- Editor
- Owner
- AI Platform Notebooks Service Agent
- Colab Enterprise Admin
- Colab Enterprise User
- Notebook Runtime Admin
- Notebook Runtime User
- Service Account Token Creator
- Vertex AI Administrator
- Vertex AI Custom Code Service Agent
- Vertex AI Service Agent
- Vertex AI User
- Vertex AI Viewer
- Key Generation: We created a new key for the service account by selecting JSON as the key type and downloaded the JSON file locally from the service account key management page.
2. Local Testing with a Spring Boot Project:
- Maven Dependencies: We included the following Maven dependencies in our project:
xml
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-vertexai</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-aiplatform</artifactId>
<version>3.33.0</version>
</dependency>
- Environment Variable Configuration:
- In PowerShell: $env:GOOGLE_APPLICATION_CREDENTIALS="xxxxx.json"
- In IDEA: Configured GOOGLE_APPLICATION_CREDENTIALS in the startup configurations to the same path.
- Test Code Implementation: We implemented the following test code:
- Retrieved the GOOGLE_APPLICATION_CREDENTIALS environment variable.
- Initialized VertexAI with our project ID and location, and configured GenerationConfig and GenerativeModel with the model name and parameters.
- Created a list of contents with messages and attempted to generate content stream using the model, printing out the responses.
Issue Encountered:
During the API call, we received the following error:
- Error Message: UNAUTHENTICATED: Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie, or other valid authentication credentials.