Esc

401 Unauthorized / Incorrect API key provided

The service did not accept your key. Usually it is a typo, a key from another project, a key that was revoked, or a variable that was never loaded.

AI Place Hub 22
PromptCopied
Error code: 401 - Incorrect API key provided: sk-...abcd. You can find your API key in your account settings.

A 401 means the request reached the service and the key was refused. The server is working, so do not chase network problems.

The usual causes are a stray space or newline copied with the key, a key created in a different account or project, a key that was deleted or rotated, and an environment variable that is empty in the process that makes the call. A key sent to the wrong provider also fails, for example a key for one vendor sent to another vendor endpoint.

Notes from the author

Print the length of the key, not the key. In code, log how many characters the variable has. Zero means it did not load. A few extra characters means whitespace.

Check where the variable lives. A key exported in one terminal is not visible in another, and a .env file is only read if your code loads it. Restart the app after you change it.

Compare with the dashboard. Check the key is active, belongs to the project you expect, and has permission for the model you call. Create a new one if in doubt, and delete the old one.

Never paste the key into a chat or a public repository. If you did, revoke it now. This guide is general information and comes with no guarantee. Settings and messages differ by provider and version.

For information only, not professional advice. You use it at your own risk and we are not liable for any loss or damage. See the disclaimer.

Fork

Did this work for you?

Sign in to flag it

Related