Hello,
I am using Google AI Studio and the latest google-genai SDK.
Project:
travel-2026-510412
When I create an API key in AI Studio, the generated credential starts with:
AQ…
instead of the traditional Gemini API key format:
AIzaSy…
Using the credential in Python:
from google import genai
client = genai.Client(
api_key=“AQ…”
)
All requests fail with:
401 UNAUTHENTICATED
ACCESS_TOKEN_TYPE_UNSUPPORTED
Environment:
google-genai 2.25.0
Python 3.12
Windows 11
Questions:
1. Is the new AQ… credential expected to work with google-genai SDK?
2. Should I use a different authentication method?
3. How can I generate a Gemini API key compatible with google-genai?
Thank you. 401 UNAUTHENTICATED
ACCESS_TOKEN_TYPE_UNSUPPORTED
Hello @bayar_choijil ,
Yes, AQ.-prefix API keys created in Google AI Studio work directly with the Gemini Developer API using genai.Client(api_key=...) or the GEMINI_API_KEY environment variable, without any additional authentication or configuration.
Please try the below steps:
- Delete all old, non-working keys and create a new key specifically within the Google AI Studio UI.
- Please ensure you are not using a deprecated model.
- If you still face the issue, please share the exact cURL command that produces the error (ensuring the API key itself is redacted).
Thank you for your reply.
I created a brand-new AQ… key directly in Google AI Studio and tested it with google-genai 2.25.0.
The result is still:
401 UNAUTHENTICATED
ACCESS_TOKEN_TYPE_UNSUPPORTED
I also tested:
-
gemini-2.5-flash
-
google-genai 2.25.0
-
Windows 11
-
Python 3.12
Could you please provide a minimal cURL example that should work with an AQ… key?
I will test the exact cURL request and provide the results.
Hello @bayar_choijil,
The issue you are facing might be because your new project does not currently have access to the gemini-2.5-flash model (as gemini-2.5-flash is not automatically granted to new projects, see the documentation).
Could you please test your key with the gemini-3.8-flash or other 3.x model instead?
Hi Mahesh,
Thank you for the reply.
I tested the cURL command using the new AQ... key as suggested. Here are the results:
- Request with
Authorization: Bearer returned the following exact terminal error:
JSON{
“error”: {
“code”: 401,
“message”: “Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential.”,
“status”: “UNAUTHENTICATED”,
“details”: [
{
“@type”: “type.googleapis.com/google.rpc.ErrorInfo”,
“reason”: “API_KEY_SERVICE_BLOCKED”,
“metadata”: {
“method”: “google.ai.generativelanguage.v1beta.GenerativeService.GenerateContent”,
“service”: “generativelanguage.googleapis.com”
}
}
]
}
}
It appears that the Generative Language API ([generativelanguage.googleapis.com](http://generativelanguage.googleapis.com)) is currently blocked/restricted for my account/project.
Could you please assist in checking why the service is blocked and unblocking it for my project?
Best regards,
Bayar Choijil
Hello @bayar_choijil ,
Could you please try with this cmd?
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" \
-X POST \
-d '{
"contents": [{
"parts": [{"text": "Explain how AI works in a few words"}]
}]
}'