Back to issues
Medium priorityTested by MilanVerified fix

API Key Not Working (Claude / OpenAI)

Agent starts but all responses fail with '401 Unauthorized' or 'invalid_api_key' errors in the logs.

Likely Cause

The API key is set under the wrong environment variable, contains hidden whitespace, or was revoked by the provider.

Tags

ConfigAPI Key

Recovery Steps

  1. 1Check the .env file for the exact provider variable name.
  2. 2Paste the key into a plain text editor to remove hidden whitespace.
  3. 3Confirm the key is still active in the provider dashboard.
  4. 4Verify the .env file sits in the project root.
  5. 5Restart OpenClaw fully because .env changes do not hot-reload.

Still blocked?

If the steps above do not clear it, review the full fixes index or book direct troubleshooting help.