Hi Google AI team,
I’m integrating the Gemini API into a Python FastAPI backend and consistently receive an authentication error when calling GenerateContent.
Error details:
-
HTTP status:
401 UNAUTHENTICATED -
Error reason:
ACCESS_TOKEN_TYPE_UNSUPPORTED -
Message: “Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential.”
-
Endpoint:
https://generativelanguage.googleapis.com/v1beta -
SDK:
google-genaiversion2.29.0 -
Model:
gemini-2.5-flash
Checks already completed:
-
The Gemini API is enabled in Google Cloud.
-
The API key’s API restriction is set to Gemini API.
-
Application restrictions are set to None.
-
The key is loaded from my
.envfile and passed explicitly to the Google GenAI SDK. -
I checked for conflicting
GEMINI_API_KEYandGOOGLE_API_KEYenvironment variables. -
The same authentication error occurs with the official SDK and direct REST requests using the API key.
The key was created through Google AI Studio, belongs to a Free-tier project, and has an AQ... prefix. I have not included the key itself for security.
Could you help determine why this key is being rejected as an unsupported authentication credential? Is there a project/key provisioning issue, or a specific diagnostic step I should perform before creating another key or project?
I can provide sanitized request details and the project ID privately if needed.
Thank you.