top of page

Gemini API rejects your new key with 401 ACCESS_TOKEN_TYPE_UNSUPPORTED: every cause and fix

25 minutes ago
9 min read
Gemini logo with the title Gemini API rejects your new key with 401 ACCESS_TOKEN_TYPE_UNSUPPORTED: every cause and fix, Data Studios original cover

Last verified: November 20, 2026


You created a fresh key in Google AI Studio, pasted it into your code or your favourite tool, and the very first request to the Gemini API came back with a 401 error saying the key is not valid. The key is visible in the AI Studio dashboard, it is restricted to the Gemini API, and nothing about it looks wrong. Developers have been posting this exact situation on Google's official AI developers forum since June 2026, and new threads were still appearing in the week of November 16 to 20.


The short answer is that the new key type works, but something between the key and the request breaks it. Since May 28, 2026, every key created in AI Studio is an authorization key bound to a Google Cloud service account, and Google staff on the forum repeat that these keys need no extra setup when they travel in the x-goog-api-key header. In most reported cases the request is carrying a different key than the one you think (an old environment variable wins), the key is sent in the wrong place (an Authorization: Bearer header on a native endpoint), or it was damaged when copied. A smaller group of users still get the error after every documented check, and for them the only route Google offers is a support report with the full error and the project ID.


··········


THE GEMINI API 401 ERROR AND WHERE IT APPEARS.


The error comes back from generativelanguage.googleapis.com on the first authenticated call, whether that call is a text generation request, a file upload or a simple request to list models. It looks the same in the official Python and JavaScript SDKs, in Google Apps Script and in raw REST calls made with curl. This is the full response body posted by several developers on the forum, with the method name changing according to the call:


{"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"}}]}}

Older reports from the summer show a different human-readable message with the same reason code. Both variants, and a related error that users mix up with it, are listed below.


........


Message shown

Reason code

Seen when

API key not valid. Please pass a valid API key.

ACCESS_TOKEN_TYPE_UNSUPPORTED

Most reports from October and November 2026

Request had invalid authentication credentials. Expected OAuth 2 access token...

ACCESS_TOKEN_TYPE_UNSUPPORTED

Reports from June to October 2026, including file uploads

401 API_KEY_SERVICE_BLOCKED

API_KEY_SERVICE_BLOCKED

A new key sent in an Authorization: Bearer header to a native endpoint, according to Google staff

Invalid Auth key. (HTTP 400)

none shown

The same failing key tried on the OpenAI-compatible chat endpoint, reported by one developer


........


The keys involved share one visible trait in every thread: users describe them as 53-character keys starting with "AQ.", generated in AI Studio. The reason code mentions an access token because the Gemini API's authentication layer treats the credential as a token type it does not accept for that request. The cause sits in how the credential arrives, which is why the checks below start with the request and end with the key.


··········


HOW GEMINI API KEYS CHANGED IN 2026.


Google's page "Using Gemini API keys", last updated on October 27, 2026, describes two kinds of credential. The distinction explains why a key created today behaves differently from one created a year ago, and why old setup notes no longer apply.


........


Key type

What Google's documentation says

What it means for this error

Standard API key

Tied to a Google Cloud project for billing and quota

The Gemini API rejects unrestricted standard keys; dormant unrestricted keys have been blocked since May 7, 2026

Authorization (auth) key

Bound directly to a Google Cloud service account

Default for every new AI Studio key since May 28, 2026; restricted to the Gemini API by default

Key restricted in the Cloud console for other services

Restriction applied outside AI Studio (Method B)

Google warns that Gemini API requests with that key fail after such restrictions


........


The same page shows only one way to send the key in a REST call, the x-goog-api-key header, and says the client libraries read the key from the GEMINI_API_KEY or GOOGLE_API_KEY environment variable. One line on that page explains a large share of the forum reports: if both variables are set, GOOGLE_API_KEY takes precedence. Our guide to Google AI Studio API keys and the new auth keys covers the setup side of the change in more detail.


··········


CAUSES OF THE GEMINI API ACCESS_TOKEN_TYPE_UNSUPPORTED ERROR.


The table orders the causes from the most common in the forum threads to the rarest. Each row says where the cause comes from, so you can tell documented behaviour from user reports.


........


Cause

How to check

Fix

An older key in GOOGLE_API_KEY or GEMINI_API_KEY overrides the new one (documented precedence; Windows case confirmed by Google staff)

Print both variables in the same shell or process that runs your code; on Windows check User and System variables too

Remove or update the stale variable, then restart the terminal or IDE

The key is sent as Authorization: Bearer to a native endpoint (Google staff)

Look at the request headers your code or tool sends

Use the x-goog-api-key header on native endpoints; keep Bearer only for the OpenAI-compatible endpoint

The key was truncated, quoted or padded when copied (Google staff)

Check the length and the first characters; look for quotes or spaces in .env files

Copy the key again from AI Studio and paste it without quotes

A key restricted in the Cloud console for other services (documented)

Open the key's restrictions in the Google Cloud console

Restrict it to the Gemini API only, or create a new key in AI Studio

A request to a shut-down or limited model (staff checklist, official model notes)

Compare the model ID with Google's current models page

Test with gemini-3.8-flash before debugging your own code

A single key that fails while other keys on the account work, including keys renamed after creation (user reports, not documented)

Create a second key and test both with the same request

Delete the failing key, use a new one and leave it unrenamed


........


··········


STEP-BY-STEP FIXES FOR THE GEMINI API KEY ERROR.


Work through the steps in order. Google staff on the forum ask users to complete them in this sequence before escalating, because each step rules out one of the causes above.


1. Test the key outside your application. Open a new terminal, copy the key again from the API keys page in AI Studio, and send the official test request from Google's getting-started page with the key pasted directly into the header. If this request succeeds, the key is fine and the problem is in your code, your environment or your tool.


curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "gemini-3.8-flash",
    "input": "Explain how AI works in a few words"
  }'

2. Clear competing environment variables. On macOS and Linux, run your test with both variables removed for that one command, as Google staff suggested in one thread. On Windows, a Gemini support account on the forum explained that an older User or System GEMINI_API_KEY variable overrides a .env file by default, and suggested removing both variables in the PowerShell session before testing. The commands below follow those staff instructions and are illustrative: replace the placeholder with your key.


# macOS / Linux (illustrative)
env -u GOOGLE_API_KEY -u GEMINI_API_KEY curl "https://generativelanguage.googleapis.com/v1beta/models" -H "x-goog-api-key: YOUR_NEW_KEY"

# Windows PowerShell (illustrative)
Remove-Item Env:GOOGLE_API_KEY -ErrorAction SilentlyContinue
Remove-Item Env:GEMINI_API_KEY -ErrorAction SilentlyContinue
curl.exe "https://generativelanguage.googleapis.com/v1beta/models" -H "x-goog-api-key: YOUR_NEW_KEY"

3. Fix the header. Native Gemini endpoints expect the key in x-goog-api-key. Google staff wrote that the Bearer form is only supported on the OpenAI-compatible endpoints, and that a new key sent as Bearer to a native endpoint produces 401 API_KEY_SERVICE_BLOCKED. If you use the OpenAI client libraries, Google's compatibility page sets the base URL to https://generativelanguage.googleapis.com/v1beta/openai/ and passes the Gemini key as the api_key value; in that case the library sends Bearer for you and that is correct.


4. Check how the key is stored. A key wrapped in quotes inside a .env loader that keeps them, a trailing space, or a line break copied from a chat window all turn a valid key into an invalid one. Staff answers on the forum treat a truncated or altered key as the most frequent cause when the key itself is reported as active.


5. Check the restrictions. Keys created in AI Studio are restricted to the Gemini API by default. If someone later edited the key in the Google Cloud console to allow other services, Google's documentation warns that Gemini API requests with that key will fail.


6. Use a current model for the test. Gemini 2.0 Flash is listed as shut down, and Google says access to the 2.5 family is limited to users who used those models before, with 3.5 Flash-Lite or 3.8 Flash recommended for new projects. A wrong model usually produces a different error, covered in our page on the Gemini API 404 NOT_FOUND error for gemini-2.5-flash, but staff ask users to rule it out before reporting a key problem.


7. Replace the key. Delete old keys that never worked, create a new key in a new project from the AI Studio interface, and test it with the request from step 1. One developer reported that two keys renamed after creation failed while unrenamed keys on the same account worked; this is a single report that Google has not confirmed, so leaving a new key with its default name costs nothing while you test.


8. Escalate with evidence. If a new key in a new project still fails the plain curl test in a clean terminal, Google staff ask for the full JSON error, the project ID and the steps already tried, posted in a new forum topic or sent through the form linked in their replies. Never post the key itself.


··········


WHAT GOOGLE DOCUMENTS AND WHAT DEVELOPERS ONLY REPORT.


The documentation and the staff answers agree on the main points, and they leave one gap open. The table separates the three levels of evidence available on November 20, 2026.


........


Statement

Source

Status

New AI Studio keys are auth keys bound to a service account, restricted to the Gemini API

Using Gemini API keys page

Documented

GOOGLE_API_KEY takes precedence over GEMINI_API_KEY when both are set

Using Gemini API keys page

Documented

AQ. keys work with x-goog-api-key and need no extra IAM roles or allowlisting

Google staff on the forum

Staff answer

Bearer is accepted only on OpenAI-compatible endpoints

Google staff on the forum, OpenAI compatibility page

Staff answer and documented example

A stale Windows GEMINI_API_KEY variable overrides .env

Gemini support account on the forum

Staff answer

Renamed keys fail; one key fails while others work

Individual developers

Reported, not confirmed

Some keys keep failing after every documented step

Several developers across threads

Reported, no fix published


........


The page on Gemini API keys has no troubleshooting entry for ACCESS_TOKEN_TYPE_UNSUPPORTED as of its October 27, 2026 update, and none of the forum threads reviewed for this page shows a solution marked as accepted. When the error survives a clean test with a brand-new key, the cause is on Google's side of the account, and only Google support can see it.


··········


PREVENTING GEMINI API KEY FAILURES AFTER UPDATES.


Most of these failures start the day a project switches to a new key while an old one is still set somewhere on the machine or in the deployment. Keep one variable name per project, and if your tooling reads both, set GOOGLE_API_KEY deliberately or remove it, since the documentation says it wins. In CI and hosting platforms, check the secret store as well as the code, because an old secret silently replaces a new local key once the code is deployed.


Keep keys server-side. Google's documentation tells developers to treat a Gemini key like a password and never expose it in client-side code in production. Requests made with authorization keys are not recorded in the service account usage metrics, according to the same page, so monitor usage from AI Studio and from your own logs. Authentication and quota are separate layers: once the key works, a 429 error is a rate-limit problem, explained in our page on Google AI Studio rate limits and 429 fixes.


When a tool you did not write asks for a Gemini key, check whether it calls the native API or the OpenAI-compatible endpoint, and whether it was updated after May 2026. A tool that hard-codes a Bearer header against native endpoints will fail with every new key until its developer changes the request.


··········


GEMINI API AUTH KEYS AND THE 401 ERROR: WHAT TO DO FIRST.


The ACCESS_TOKEN_TYPE_UNSUPPORTED reason looks like a broken key type, yet Google's own answers say the AQ. authorization keys created since May 28, 2026 are fully supported in the x-goog-api-key header. The fastest diagnosis is a single curl request with the key pasted inline in a clean terminal: success points to an environment variable, a header or a copy problem in your setup, and failure with a brand-new key in a new project points to an account-level issue that needs a report to Google with the full error and the project ID. Google has not documented the error itself, so the checks above come from its key documentation and from staff answers on its developer forum, and they should be revisited when the "Using Gemini API keys" page adds a troubleshooting entry.


··········


FOLLOW US FOR MORE.


·····


DATA STUDIOS


·····


datastudios.org


bottom of page