(401) New API Key in New GCP Project Fails on Gemini API Call!!!!!!!!

Subject: Persistent HTTP 401 Unauthorized Error on Gemini API Call with Newly Created API Key

Hello, I am experiencing a critical and persistent 401 error when calling the Gemini API from a successfully deployed Cloud Run service. I am requesting official assistance to verify my Google Account and API Key’s backend status, as I have exhausted all client-side and configuration troubleshooting.

Technical Factors Eliminated (All are confirmed correct):

  1. Code and Architecture: The proxy code is robust (switched to Uvicorn/Waitress, includes BrokenPipeError capture, and full JSON validation). The core logic is sound (confirmed via Postman).

  2. Environment Health: A basic alpine:latest container running an echo command deployed successfully, proving the Cloud Run environment and networking are healthy.

  3. Permissions: The Cloud Run service account has sufficient IAM roles (Vertex AI User, Service Usage Consumer). My user account is Owner/Editor.

  4. Billing/Quotas: The GCP project has an active billing account, and all relevant API quotas are well below limits.

  5. Key Validity: The API key is newly generated, unrestricted, and passed correctly as an environment variable (GEMINI_API_KEY).

The Problem:

Despite all correct configurations, the service consistently receives an HTTP 401 Unauthorized error when attempting to call the Gemini API. This occurs immediately upon API client initialization.

Request for Assistance:

Since all software and configuration issues have been eliminated, the problem is suspected to be a backend account state issue (e.g., internal block, temporary account flag, or key status issue). I request a Google engineer to check my project’s backend status and the internal validity of the API Key.

  1. Thank you for your time.:laughing: