API key not valid. Please pass a valid API key. is Google's answer when the Gemini API cannot match the request's key to a usable one: a typo, a deleted or restricted key, or a key that was issued for a different Google product. A key that Google has flagged as compromised returns a separate 403 instead of this message. The cure is either a fresh key minted in AI Studio, or a move to the gateway, where the API base is https://api.uplinkswitch.com/v1 and the Gemini SDK appends its own /v1beta path on top of that base to reach a healthy model such as gemini-4-argon.
What it means, per Google's docs
The Gemini troubleshooting page from Google treats this as a key-setup problem and says to verify how the key was created and passed, not to retry the call. Authentication failures, along with 400, 402 and 403 responses, are listed as conditions that a retry will not clear: the problem is in the request, the key or the account, not in a passing upstream state. Two setup details catch most people. First, a 200 from a models.list call does not prove that the same key will be accepted for generateContent against the model you want. Second, a key copied with a trailing space, a line break, or a surrounding quote stops matching, which Google's guidance frames as checking that the key is passed exactly as issued.
On the generative endpoints this exact message arrives as a 400 with status INVALID_ARGUMENT and reason API_KEY_INVALID; the Gemini API errors reference files a missing, invalid or expired key under its authentication class, reported as 401 on the Interactions surface. Google documents one adjacent case that produces different text on purpose: a key the system believes has been exposed is blocked with "Your API key was reported as leaked. Please use another API key.", returned as 403 PERMISSION_DENIED. That is not the same condition as this page's string, and no amount of re-sending the same key will move it. If you see the leaked-key wording, the only fix is a new key.
What the gateway changes
Point the Gemini SDK at UplinkSwitch and the authentication surface narrows to one place. The gateway's Gemini route, POST /v1beta/models/{model}:generateContent, accepts the Gemini SDK's own key header, so the SDK keeps sending the credential the way it always has. A credential the gateway rejects comes back in Google's native error shape, with the status name the Gemini SDK already parses, and the gateway's own code for that case is invalid_api_key. That failure is not retried and not failed over: per the gateway's OpenAPI, the gateway settles a 401 before it picks a route, so nothing runs and nothing is billed for the attempt. Every error also carries a request id in its response headers, which is the value to quote if you open a support ticket.
One routing fact is worth keeping in mind. The gateway's automatic fallback, where a models: [...] list names up to five models and the next is tried only once the one before it has failed, is defined for the OpenAI and Anthropic request formats. The Gemini format is not named for that list, and a Gemini model is served by a single route here, so a bad key on the Gemini surface simply fails; there is no sibling route to catch it. A credential failure is settled before any route is chosen, so no fallback list can rescue it; handle the rejection in your own code.
On the 2026-11-23 catalog gemini-4-argon read ok.
How to fix it
- Read the status, not just the text. A 400
INVALID_ARGUMENTwith reasonAPI_KEY_INVALID, or a 401UNAUTHENTICATED, is a credential problem. A 403 with the leaked-key wording is a different, terminal condition that needs a brand new key. - Re-copy the key. Paste it into a plain editor first and strip any trailing whitespace, newline or quote, then set it in the environment or secret store the process actually reads.
- Confirm the key is a Gemini key, created in AI Studio for the Gemini API, and not a key for another Google service that happens to be on hand.
- If the key is new, confirm it belongs to the Gemini API project you expect. A successful
models.listis not proof thatgenerateContentwill accept it. - If Google reports the key as leaked, stop reusing it. Generate a replacement and rotate anywhere the old value was stored.
- To remove per-provider key juggling altogether, move the call to the gateway. Create a gateway key with the
sk-uplink-live-prefix, point the base athttps://api.uplinkswitch.com/v1, and the Gemini SDK adds its own/v1betapath on top of it.
Once the key is accepted, a 404 on the model name is a separate issue; the sibling page models/<id> not found for v1beta covers that.