Back to issues
Medium priorityTested by MilanVerified fix

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.

MilanLast updated Mar 6, 2026Verified recovery sequence documented in this repo

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.

Issue FAQ

These answers are written to be self-contained, so you can confirm the likely problem before you start changing your setup.

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.

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.