What’s most rage-inducing isn’t that the model can’t write—it’s that just as you’re about to get to work, the console throws API key invalid, 401, or network error. The thing I’ve stumbled over the most is this: the key is fine; the problem is the “surrounding configuration.” This checklist is organized in the order I most often use: ChatGPT, Claude, then Gemini.
First, make sure you’re using the right key and the right project
A lot of people copy an old key, a test key, or switch projects in the console without noticing. I suggest you create a new key directly in the provider’s dashboard and replace it immediately—don’t get stuck wrestling with the old environment.
No permissions or billing enabled = effectively no key
A 401/403 doesn’t necessarily mean the key is wrong. Common causes are billing not enabled, insufficient permission scope, or organization/project restrictions. This is especially common with Claude and Gemini: it “looks like it should work,” but the moment you hit the API it errors out—don’t ask me how I know.
Environment variables and whitespace are silent killers
An extra space in your .env file, an unhandled newline, or a deployment platform failing to inject variables can all turn into an “invalid key.” Printing the key length and trimming leading/trailing whitespace is more useful than staring at the error for half an hour.


