Agent starts but all responses fail with '401 Unauthorized' or 'invalid_api_key' errors in the logs. In most cases, the underlying issue is the API key is set under the wrong environment variable, contains hidden whitespace, or was revoked by the provider.
API Key Not Working (Claude / OpenAI)
If you are seeing this exact OpenClaw issue, the fastest path is to confirm the likely cause, then work the recovery steps in order without skipping the full restart and retest sequence.
Likely Cause
The API key is set under the wrong environment variable, contains hidden whitespace, or was revoked by the provider.
Tags
Recovery Steps
- 1Check the .env file for the exact provider variable name.
- 2Paste the key into a plain text editor to remove hidden whitespace.
- 3Confirm the key is still active in the provider dashboard.
- 4Verify the .env file sits in the project root.
- 5Restart OpenClaw fully because .env changes do not hot-reload.
Related OpenClaw resources
Adjacent issue guides
Issue FAQ
These answers are written to be self-contained, so you can confirm the likely problem before you start changing your setup.
Work through the recovery steps in order and fully restart OpenClaw before retesting. Skipping the restart or leaving stale auth/config state in place usually causes the issue to return.
Move to the related guide or service link below so you can rule out adjacent configuration problems instead of repeating the same failed steps.
Still blocked?
If the steps above do not clear it, review the full fixes index or book direct troubleshooting help.