Gemini API returns 401 ACCESS_TOKEN_TYPE_UNSUPPORTED with an AI Studio AQ... API key

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-genai version 2.29.0

  • Model: gemini-2.5-flash

Checks already completed:

  1. The Gemini API is enabled in Google Cloud.

  2. The API key’s API restriction is set to Gemini API.

  3. Application restrictions are set to None.

  4. The key is loaded from my .env file and passed explicitly to the Google GenAI SDK.

  5. I checked for conflicting GEMINI_API_KEY and GOOGLE_API_KEY environment variables.

  6. 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.

Hello @Harsh_Simpy ,

  1. Could you please try creating an API key in a new project within the Google AI Studio UI to check whether the issue is specific to your current project.

  2. If the error persists, please share the full JSON error response (including all details and metadata fields) along with your Google Cloud Project ID or Project Number so we can investigate further.