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

API key not valid. Please pass a valid API key. means Gemini cannot match your key. Mint a fresh AI Studio key, or send the Gemini SDK to the gateway.

Checked 2026-11-22

·All fixes·Models

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

  1. Read the status, not just the text. A 400 INVALID_ARGUMENT with reason API_KEY_INVALID, or a 401 UNAUTHENTICATED, is a credential problem. A 403 with the leaked-key wording is a different, terminal condition that needs a brand new key.
  2. 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.
  3. 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.
  4. If the key is new, confirm it belongs to the Gemini API project you expect. A successful models.list is not proof that generateContent will accept it.
  5. If Google reports the key as leaked, stop reusing it. Generate a replacement and rotate anywhere the old value was stored.
  6. 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 at https://api.uplinkswitch.com/v1, and the Gemini SDK adds its own /v1beta path 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.

Questions and answers

Because a clean models.list response does not prove that generateContent will accept the same key for the model you want; per Google's troubleshooting docs, confirm the key belongs to the project and API you expect rather than inferring it from the listing. Also check that the key was pasted without a trailing space, newline or quote, any of which breaks the match. If both are clean and the call still returns the authentication error, the key itself is wrong for this project.

No. "Your API key was reported as leaked. Please use another API key." is a distinct 403 PERMISSION_DENIED that Google documents separately. It means the key has been seen in a public place and is blocked, so retrying or re-pasting the same value does nothing. The only resolution is to generate a new key and rotate every place the exposed one was stored. Treat it as terminal, not transient.

Yes, the Gemini SDK can target a host other than Google's, which is how it reaches the gateway at https://api.uplinkswitch.com/v1 while the SDK supplies its own /v1beta path. The exact option name and how the host and path are joined are handled on the change your base URL guide, and are left there deliberately.
Join on Telegram
Help