Gemini API returns 401 ACCESS_TOKEN_TYPE_UNSUPPORTED with valid AQ key

Hello Google Gemini API Support Team,

I am experiencing an authentication issue while integrating the Gemini API into my Python-based sports analysis application.

Environment:

  • OS: Windows 10

  • API: Gemini API (Generative Language API)

  • Model: gemini-3.1-pro-preview

  • Google Cloud Project: Default Gemini Project

  • Billing tier: Free tier

  • Authentication: AQ-format API key linked to a Google-managed service account

Issue:
Every API request returns the following error:

HTTP 401 Unauthorized

Error status: UNAUTHENTICATED

Error reason: ACCESS_TOKEN_TYPE_UNSUPPORTED

Error message:
“Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential.”

Troubleshooting already performed:

  1. Generated multiple Gemini API keys through Google AI Studio.

  2. Confirmed all three keys appear active in Google Cloud Console.

  3. Verified each key is linked to a service account.

  4. Confirmed the keys are restricted to the Gemini API.

  5. Tested authentication using the API key in the URL query parameter.

  6. Tested authentication using the x-goog-api-key HTTP header.

  7. Tested the GET /v1beta/models endpoint without generating any AI content.

  8. Both authentication methods returned HTTP 401.

The problem occurs even when using the API directly, independently of my application.

Questions:

  1. Why is a newly generated AQ-format Gemini API key rejected with ACCESS_TOKEN_TYPE_UNSUPPORTED?

  2. Does this indicate a Google-side authentication or service-account binding issue?

  3. Is any additional configuration required to use this API key with the Gemini Developer API?

  4. Is there a known issue or recommended workaround?

I would appreciate assistance identifying the root cause.

Thank you.

Hello @Juhyuk_Kang ,

  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.

Hello Google AI team,

I am building a Node.js AI assistant called NEXA on Windows.

I created a new API key in a completely new Google AI Studio project, but the issue persists.

My direct API test returns:

  • HTTP status: 401

  • Error status: UNAUTHENTICATED

  • Reason: ACCESS_TOKEN_TYPE_UNSUPPORTED

  • Service: generativelanguage.googleapis.com

The API key loads correctly from my .env file. I also tested the Gemini API directly, outside my application, and received the same error.

Could you please help me resolve this authentication problem?

I can provide my Google Cloud Project ID and the full sanitized error response if needed. I will not share my API key publicly.

Thank you.

Hello, I am experiencing exactly the same issue.

I have already created API keys in three different Google AI Studio projects. All keys start with AQ. and all requests fail with the same error:

401 UNAUTHENTICATED — ACCESS_TOKEN_TYPE_UNSUPPORTED

I have updated my code to use the x-goog-api-key header and the gemini-3.8-flash model, but the error persists.

Could you please advise how to resolve this issue?

I can provide my Google Cloud Project ID and the full sanitized JSON error response privately.

Thank you.

Hello Google AI team,

As requested, here are my project details and the full error response.

Google Cloud Project ID: gen-lang-client-0448719004

API key label in Google AI Studio: NEXA AI

Billing tier: Free tier

Direct API test result: HTTP 401

Error response:

{
  "code": 401,
  "message": "API key not valid. Please pass a valid API key.",
  "status": "UNAUTHENTICATED",
  "details": [
    {
      "@type": "type.googleapis.com/google.rpc.ErrorInfo",
      "reason": "ACCESS_TOKEN_TYPE_UNSUPPORTED",
      "metadata": {
        "method": "google.ai.generativelanguage.v1beta.GenerativeService.GenerateContent",
        "service": "generativelanguage.googleapis.com"
      }
    }
  ]
}

I have tested a key from a new Google AI Studio project, and the same error persists. I also tested the API directly using the x-goog-api-key header, independently of my Node.js application.

Could you please investigate this authentication issue?

Thank you.

Hello Google AI team,

I completed the additional checks you requested.

  • Google Cloud Project ID: gen-lang-client-04487190..

  • API key: Newly created in Google AI Studio; starts with AQ. (key not shared)

  • API restriction: Gemini API

  • Associated service account: Enabled

  • Environment: Node.js on Windows

  • Result: HTTP 401 on direct REST requests and from my NEXA application, even after creating a new project and key.

Full JSON error response:

{
  "error": {
    "code": 401,
    "message": "API key not valid. Please pass a valid API key.",
    "status": "UNAUTHENTICATED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.ErrorInfo",
        "reason": "ACCESS_TOKEN_TYPE_UNSUPPORTED",
        "metadata": {
          "method": "google.ai.generativelanguage.v1beta.GenerativeService.GenerateContent",
          "service": "generativelanguage.googleapis.com"
        }
      }
    ]
  }
}

I have confirmed that the key is loaded from .env, and tested multiple Gemini models. All return the same authentication failure.

Could you please investigate whether the key or project requires additional provisioning or correction?

Thank you.

Hello @Peter9 ,

DM’ed you for details.

Hello @keshav_home ,

AQ.-prefix API keys created in Google AI Studio work directly with the Gemini Developer API via the x-goog-api-key header and official SDKs with no additional setup required.

Please test a single request with a newly copied key pasted inline (rather than read from an environment variable) against gemini-3.8-flash:

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3.8-flash:generateContent" -H "Content-Type: application/json" -H "x-goog-api-key: YOUR_API_KEY" -d '{"contents":[{"parts":[{"text":"Hello"}]}]}'

Hello Google AI team,

I’m experiencing the same authentication issue with Gemini API keys generated in Google AI Studio.

Environment:

  • Windows / PowerShell

  • Model: gemini-3.8-flash

  • Billing tier: Free

  • API key format: AQ.

  • API endpoint: generativelanguage.googleapis.com

Issue:

I created new API keys in two separate Google AI Studio projects, but both failed.

Interestingly, retrieving model information succeeds with HTTP 200 OK, while generating content fails with:

HTTP 401 Unauthorized
Status: UNAUTHENTICATED
Message: API key not valid. Please pass a valid API key.
Reason: ACCESS_TOKEN_TYPE_UNSUPPORTED

I reproduced the issue using curl.exe in PowerShell with the x-goog-api-key header, independently of any third-party application.

I also tried connecting through a Chrome extension, but the connection test timed out.

Could you please investigate whether there is an authentication or provisioning issue with my API keys or projects?

I can provide my Google Cloud Project IDs and sanitized error details privately if needed.

Thank you!

Hello @damui ,

Since retrieving model information returns 200 OK with the same AQ. API key, your key and project are active and do not have a provisioning issue. A 401 (API key not valid) error on generateContent occurs when the x-goog-api-key header value is altered, truncated, or unread in the POST command (which can happen in Windows PowerShell with quoting, line continuations, or environment variables).

Please try the inline-key test shared above against gemini-3.8-flash using a newly copied key from Google AI Studio pasted directly inline:

Windows PowerShell:

Invoke-RestMethod -Method Post -Uri "https://generativelanguage.googleapis.com/v1beta/models/gemini-3.8-flash:generateContent" -Headers @{"x-goog-api-key"="YOUR_API_KEY"} -ContentType "application/json" -Body '{"contents":[{"parts":[{"text":"Hello"}]}]}'

macOS / Linux (bash / zsh):

curl -X POST "https://generativelanguage.googleapis.com/v1beta/models/gemini-3.8-flash:generateContent" -H "Content-Type: application/json" -H "x-goog-api-key: YOUR_API_KEY" -d '{"contents":[{"parts":[{"text":"Hello"}]}]}'

If generateContent still returns 401, please share the exact command you ran (with the API key redacted) and the full JSON error response.

Hello Pooja, @Pooja_Kapse

Thank you for your response.

I followed your instructions and tested “gemini-3.8-flash” using a freshly copied API key pasted directly into the PowerShell command.

However, this time I received a different error:

HTTP 503 Service Unavailable

I also tested the same model through my Chrome extension, and it returned HTTP 503 as well.

Interestingly, “gemini-3.6-flash” successfully passed the connection test after I modified the extension’s test settings, but “gemini-3.8-flash” still fails.

Could this indicate a model-specific service availability issue rather than an API key authentication problem?

Is there anything else I should check to get “gemini-3.8-flash” working?

Thank you for your help!

Hello @damui ,

503 errors are due to our services being temporarily overloaded. Please see this pinned post for suggestions on how to handle this.

My Gemini API requests fail with HTTP 401 UNAUTHENTICATED, reason ACCESS_TOKEN_TYPE_UNSUPPORTED, using newly created AQ-format keys.

Environment: macOS, Python, google-genai 2.34.0.
Project ID: gen-lang-client-00839784…
Project number: 9551899885…
Endpoint: generativelanguage.googleapis.com

Verified:

  • Gemini API is enabled.

  • The key is bound to an enabled service account.

  • API restriction is Gemini API; application restrictions are None.

  • The key has no whitespace or wrapping quotes.

  • Explicit genai.Client(api_key=key, vertexai=False) fails when listing models.

  • files.upload also returns HTTP 401.

  • Creating another key in the same project did not resolve the issue.

Please advise how to diagnose the AQ-key authentication or project configuration. I have not included any API key values.

Hello @Poramin_Bheganan ,

Project gen-lang-client-008... (955189...) is active on the Free tier with no project-level block, and AQ. keys created in Google AI Studio work directly for listing models and uploading files via x-goog-api-key with no extra service account setup.

Please try the steps shared above in this thread in a clean terminal — create or copy a fresh key directly from Google AI Studio (rather than the Google Cloud console) and paste it inline with GOOGLE_API_KEY and GEMINI_API_KEY unset so no shell variable or proxy overrides it (see Using Gemini API keys):

macOS / Linux (bash / zsh):

env -u GOOGLE_API_KEY -u GEMINI_API_KEY curl "https://generativelanguage.googleapis.com/v1beta/models?pageSize=2" \
  -H "x-goog-api-key: YOUR_API_KEY"

Windows PowerShell:

Remove-Item Env:GOOGLE_API_KEY, Env:GEMINI_API_KEY -ErrorAction SilentlyContinue; curl.exe "https://generativelanguage.googleapis.com/v1beta/models?pageSize=2" -H "x-goog-api-key: YOUR_API_KEY"

If that command still returns 401, please let us know whether the key was created in Google AI Studio or the Google Cloud console and share the exact command you ran (with the API key redacted) along with the full JSON error response.