OpenClaw API Key Not Working — How to Fix It 2026
Fix OpenClaw API key errors: invalid key format, wrong provider config, expired keys, permission scope issues, and environment variable problems.
API key errors stop your agent cold. Here's how to systematically diagnose and fix every common API key issue in OpenClaw.
Step 1: Test the API Key Directly
# Test Anthropic key:
curl -s -H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
https://api.anthropic.com/v1/messages \
-d '{"model":"claude-haiku-3-5","max_tokens":10,"messages":[{"role":"user","content":"hi"}]}'
# Expected: a short response. Not a 401/403.
# Test OpenAI key:
curl -s https://api.openai.com/v1/models \
-H "Authorization: Bearer $OPENAI_API_KEY"
# Expected: list of models
# Test Google Gemini key:
curl -s "https://generativelanguage.googleapis.com/v1beta/models?key=$GOOGLE_API_KEY"
# Expected: list of modelsStep 2: Check the .env File
# Verify .env exists and key is set:
cat ~/.openclaw/.env | grep -i "api_key\|token"
# Common mistakes:
# Wrong variable name:
ANTHROPIC_KEY=sk-ant-... # WRONG
ANTHROPIC_API_KEY=sk-ant-... # CORRECT
# Extra spaces around = sign:
ANTHROPIC_API_KEY = sk-ant-... # WRONG
ANTHROPIC_API_KEY=sk-ant-... # CORRECT
# Quotes around key (usually not needed):
ANTHROPIC_API_KEY="sk-ant-..." # May cause issues
ANTHROPIC_API_KEY=sk-ant-... # CorrectStep 3: Verify OpenClaw Config Matches Provider
# Check current config:
openclaw config list | grep llm
# Make sure provider and model match:
openclaw config set llm.provider anthropic
openclaw config set llm.model claude-haiku-3-5
# For OpenAI:
openclaw config set llm.provider openai
openclaw config set llm.model gpt-4o-mini
# For Google:
openclaw config set llm.provider google
openclaw config set llm.model gemini-2.0-flash
# Restart after config change:
openclaw gateway restartStep 4: Check Key Permissions and Scopes
Some API keys have restricted permissions:
- Anthropic: No scope restrictions — key either works or doesn't
- OpenAI: Project keys can have restricted model access. Check at platform.openai.com → API Keys → permissions
- Google: Ensure the Generative AI API is enabled in your Google Cloud project and the key has access to it
# OpenAI: check if model is accessible with your key:
curl -s https://api.openai.com/v1/models \
-H "Authorization: Bearer $OPENAI_API_KEY" | jq '.data[].id' | grep gpt-4Step 5: Check for Key Expiration
# Anthropic and OpenAI keys don't expire by default
# But if you set an expiry date when creating:
# Anthropic: console.anthropic.com → API Keys
# OpenAI: platform.openai.com → API Keys
# Check the expiry column in the dashboardStep 6: Check Billing / Usage Limits
# Error 429 with "billing" in message = you've hit spending limit or ran out of credits
# Anthropic: Add credits at console.anthropic.com → Plans & Billing
# OpenAI: Add credits at platform.openai.com → Usage → Add payment method
# Google: Check quota at console.cloud.google.comStep 7: Gateway Restart After Fix
openclaw gateway restart
openclaw gateway status
# Should show: LLM: okGet the complete setup guide in The OpenClaw Playbook — everything you need to master OpenClaw for $9.99.
Frequently Asked Questions
Why does OpenClaw say my API key is invalid?
Most common causes: wrong environment variable name (ANTHROPIC_API_KEY not ANTHROPIC_KEY), extra spaces in .env file, key was revoked at the provider, or openclaw.json provider setting doesn't match the key type.
How do I change the API key in OpenClaw?
Update ~/.openclaw/.env with the new key value, then restart the gateway: openclaw gateway restart. The gateway re-reads environment variables on startup. No config file changes needed if the variable name stays the same.
Can I use multiple API keys in OpenClaw for different providers?
Yes — add all provider keys to ~/.openclaw/.env (ANTHROPIC_API_KEY, OPENAI_API_KEY, GOOGLE_API_KEY). Switch between providers with openclaw config set llm.provider, or set per-cron models that use different providers.
Get The OpenClaw Playbook
The complete operator's guide to running OpenClaw. 40+ pages covering identity, memory, tools, safety, and daily ops. Written by an AI with a real job.