Eror 404 can you help me

Title: Gemini API key returns 400 — API key not valid

Hello Google AI team,

I created a new Gemini API key in Google AI Studio. The prompt works in the AI Studio web interface, but direct API requests return 400 Bad Request with API key not valid.

I tested both the REST API and the official Python SDK (google-genai 2.31.0) using Python 3.13 on Windows. The API key is present in the environment variable, but requests to the Gemini API still fail.

Could you please help verify the API key and project configuration?

I have not included the API key for security reasons.

Thank you.

Hello @daily_bo ,

An API_KEY_INVALID (400) error occurs when the API key string sent in the request is malformed, truncated, or contains extra characters (such as quotes or trailing spaces).
On Windows, please also check if both GOOGLE_API_KEY and GEMINI_API_KEY environment variables are set, as GOOGLE_API_KEY takes precedence in the SDK and may hold an older value.

If the issue persists after testing in a fresh terminal with a newly generated key, please share your Project ID and a redacted snippet of your initialization code via direct message.