API Key Security

Your API keys stay on your machine. Never stored in plaintext on remote servers, never transmitted to OpenClaw.

How OpenClaw Handles Your Keys

Four principles that govern API key security in OpenClaw.

🚫

Never Transmitted to OpenClaw

Your API keys are never sent to any OpenClaw server. There is no OpenClaw server to send them to — you self-host the entire application.

💾

Stored Locally Only

Keys live in a .env file on your machine. They're read by your local OpenClaw process at startup and held in memory during operation.

🔀

Direct Provider Connections

When OpenClaw sends a request to GPT-4 or Claude, it goes directly from your server to the AI provider. No middleman, no proxy, no relay.

🗑️

Instant Revocation

Since you own the keys, you can revoke them at your AI provider's dashboard at any time. Remove the key from .env and restart — done.

API Key Data Flow

Exactly where your API key goes when OpenClaw makes an AI request.

Your machine
.env file → OpenClaw process
Your machine
HTTP request with auth header
External
AI Provider API

Note: The key is read from your local .env file, added to the Authorization header, and sent directly to the AI provider. At no point does the key pass through any OpenClaw-operated infrastructure.

Best Practices

Use environment variables

Store keys in a .env file, never hardcode them in config files that might be committed to version control.

terminal
"comment"># .env file on your machine
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...

"comment"># Never commit .env to git
echo ".env" >> .gitignore

Restrict file permissions

Set file permissions so only your user account can read the .env file. Prevents other users on shared systems from accessing your keys.

terminal
chmod 600 .env
"comment"># Only your user can read the file
ls -la .env
"comment"># -rw------- 1 you you 128 Apr 11 .env

Rotate keys periodically

Generate new keys every 90 days. Update your .env, restart OpenClaw, and revoke the old key at your provider's dashboard.

terminal
"comment"># 1. Generate new key at provider dashboard
"comment"># 2. Update your .env
nano ~/openclaw/.env

"comment"># 3. Restart OpenClaw to pick up new key
docker compose restart

"comment"># 4. Revoke old key at provider dashboard

Use scoped keys when available

Many AI providers offer project-scoped or usage-limited keys. Use the most restrictive key that meets your needs.

terminal
"comment"># Use provider-specific key restrictions:
"comment"># - OpenAI: Project keys with limited permissions
"comment"># - Anthropic: Workspace keys with usage limits
"comment"># - Google: API keys restricted to specific APIs

Common Mistakes to Avoid

Never commit .env files to git repositories. Add .env to your .gitignore immediately.

Never paste API keys in chat messages, forum posts, or issue trackers — even private ones.

Never share API keys between users. Each person should use their own key from their own provider account.

Never use production keys for testing. Create separate keys with lower rate limits for development.

Multi-User Key Isolation

How API keys stay isolated in multi-user OpenClaw deployments.

In a multi-user setup, each user configures their own AI provider API key. Keys are isolated per workspace — one user's key is never accessible to another user. This means each user pays only for their own AI usage and can revoke their key independently.

workspace isolation
"comment"># Each user brings their own API key
"comment"># User A: uses OpenAI GPT-4
OPENAI_API_KEY=sk-userA-xxxxx

"comment"># User B: uses Anthropic Claude
ANTHROPIC_API_KEY=sk-ant-userB-xxxxx

"comment"># Keys are isolated — User A cannot access User B's key

Start Using OpenClaw Securely

Set up OpenClaw with proper API key management in under 5 minutes.