Error DictionaryLast Updated: Jan 31, 2026

Fix: 401 Unauthorized / Invalid API Key

Step-by-step fix for '401 Unauthorized' or 'Invalid API Key' errors when using OpenClaw with OpenAI or Anthropic.

This page helps you fix API authentication errors when OpenClaw tries to connect to AI providers.


🔴 Raw Error Log (What You Actually See)

You may see one of these errors:

Error: Request failed with status code 401

Or:

Error: Invalid authentication
Error: Incorrect API key provided
Error: Invalid API key

Or OpenClaw seems to work but:

  • Bot replies with empty messages
  • Bot says "I cannot help with that"

If your situation matches, you are in the right place.


🔍 Why This Happens (Root Cause)

The API key in your .env file is:

  1. Missing entirely
  2. Copied incorrectly (extra spaces, quotes, or line breaks)
  3. Expired or revoked
  4. Wrong key for the service (e.g., using OpenAI key for Anthropic)

✅ How to Fix It (Step-by-Step)

Step 1 — Check for Invisible Spaces (Most Common!)

Open your .env file and look carefully:

# ❌ WRONG - has trailing space
OPENAI_API_KEY=sk-1234567890abcdef   

# ❌ WRONG - has quotes
OPENAI_API_KEY="sk-1234567890abcdef"

# ❌ WRONG - has line break in middle
OPENAI_API_KEY=sk-1234567890
abcdef

# ✅ CORRECT - clean, no extras
OPENAI_API_KEY=sk-1234567890abcdef

Step 2 — Verify Key is Active

For OpenAI:

  1. Go to OpenAI API Keys
  2. Check if your key is listed and not revoked
  3. Check Billing — you need credits!

For Anthropic:

  1. Go to Anthropic Console
  2. Verify your API key is active
  3. Ensure you have credits loaded ($5 minimum)

Step 3 — Generate a New Key (If Needed)

If your key might be compromised or isn't working:

  1. Delete the old key from the provider's dashboard
  2. Create a new key
  3. Update your .env file with the new key

Step 4 — Restart OpenClaw

⚠️ Critical: OpenClaw only reads .env when it starts!

# Stop the bot (Ctrl+C)
# Then restart
npm run start

🔎 Verify the Fix

After applying the fix, run:

npm run start

Then try sending a message to the bot.

✅ Expected Result

The bot responds with an intelligent reply instead of:

  • Empty messages
  • "I cannot help with that"
  • Error messages

❌ Still Not Working?


🧭 Advanced Notes

Using Multiple API Keys?

If your .env has keys for multiple services:

OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...

Make sure both keys are valid if OpenClaw uses both services.


🔗 Related: Common Errors Summary | Error Dictionary

Internal Ref: ERROR_API_001
ErrorAPIAuthenticationOpenAIAnthropic401