VS Code
How to fix Cline returning 401 or an invalid API key
A 401 means the request reached the AI Code With server but failed authentication. The issue is in the API key itself, its validity, or the account state — not in the Base URL or model.
Start with these checks
The request reached the server, but authentication failed.
- Cline shows 401, Unauthorized, or Invalid API Key after sending a message.
- The pasted API key is incomplete, has extra spaces, or is the wrong key
- Open Cline settings (Cline icon in the activity bar → gear icon at the top right)
401UnauthorizedInvalid API Key01
Confirm the request reached the server
401 / Unauthorized means the request successfully reached the AI Code With endpoint and was rejected at authentication. Do not change the Base URL or model; check the API key first.
02
Re-paste and verify the API key
In Cline settings, keep Anthropic as the Provider and paste the full AI Code With API key into the Anthropic API Key field. Avoid trailing newlines or spaces when copying.
- 1Open Cline settings (Cline icon in the activity bar → gear icon at the top right)
- 2Re-paste the full API key into the Anthropic API Key field, with no extra spaces
03
Verify the key and account
Confirm the key is active and the account has balance on the AI Code With API key page. After saving, send a short message — no more 401 means the credential chain works.
- 1Re-paste the full API key into the Anthropic API Key field, with no extra spaces
- 2Confirm the key is a valid AI Code With API key (see the API key page)
If it is still not fixed
Sources
Reconfigure
Return to the integration center and continue the setup steps.
Return to the related setup step