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.
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.
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?
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:
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:
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?
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):
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.