Gemini API returns HTTP 401 with a newly created, service-account-bound AI Studio key

Hello Google Gemini API team,

I am investigating an authentication failure during a small, controlled API compatibility test.

Environment

  • Platform: Windows 11, Python 3.14

  • Google Cloud project: Default Gemini Project (Free Tier)

  • API key: Created in Google AI Studio on October 16, 2026

  • Key type: Service-account-bound authorization key

  • API restriction: Gemini API

  • Application restriction: None

  • Gemini API: Enabled

  • Endpoint: POST /v1beta/interactions

  • Model: gemini-3.8-flash

  • Authentication: x-goog-api-key header

Observed result — October 17, 2026

The HTTPS request returned HTTP 401.

Our local audit recorded:

  • Transport completed: true

  • HTTP status: 401

  • Error class: authentication

  • No confirmed model generation or usage

For security reasons, our application intentionally discarded the raw error body. Therefore, I cannot confirm whether the underlying Google error reason was ACCESS_TOKEN_TYPE_UNSUPPORTED.

I have confirmed that the key exists in the correct Google Cloud project, is bound to a service account, and is restricted to the Gemini API.

Could you please clarify:

  1. Are there any additional requirements for service-account-bound authorization keys when calling the Gemini Interactions API?

  2. Could HTTP 401 indicate a key provisioning or service-account binding problem even when these settings appear correct?

  3. Is there a recommended diagnostic method to identify the specific authentication error without exposing the API key?

I have preserved the original failed attempt and have not retried it. I can provide additional sanitized evidence and project identifiers privately if needed.

Thank you.

The first thing I’d change is the logging, not the key. The error body doesn’t contain your key, so you can store it safely. Keep error.code, error.status and error.details[].reason. That reason tells you what’s actually wrong.

Then do one quick check against a simple endpoint, to separate a key problem from an Interactions problem:

curl -s -H "x-goog-api-key: $GEMINI_API_KEY" https://generativelanguage.googleapis.com/v1beta/models

If that also returns 401 with ACCESS_TOKEN_TYPE_UNSUPPORTED, it’s usually the key string itself: truncated on copy, a trailing newline from the env file, or quotes left in. AQ. auth keys work fine with x-goog-api-key, so the binding shouldn’t need anything extra. Also make sure your HTTP client isn’t adding an Authorization: Bearer header as well. That gives a 401 too.

If /models returns 200 and only the Interactions call fails, post the reason and it gets a lot narrower.

Hello @Freejiee_Ya @victorgrosser ,

  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.

Thanks Pooja. That one’s mostly for @Freejiee_Ya, since it’s their key and project. One addition: before sharing the full error JSON, it’s worth running the quick /v1beta/models check from my earlier reply with the new key too. If /models works and only /interactions returns 401, that narrows it down a lot for your team.