Overview
The better-openclaw API supports optional API key authentication via theX-API-Key header. Authentication is disabled by default - when no API keys are configured, all requests are accepted.
Configuration
Configure valid API keys using theAPI_KEYS environment variable:
API_KEYS is set:
- Requests with a valid key are accepted
- Requests with an invalid key receive a
401 Unauthorizedresponse - Requests without a key are still accepted (but subject to lower rate limits)
Making Authenticated Requests
Include your API key in theX-API-Key header:
Example: Generate Stack with Authentication
Authentication Errors
Invalid API Key
Request:Security Best Practices
Key Format Recommendations
Use descriptive prefixes to identify key types:sk_live_- Production keyssk_test_- Development/testing keyssk_dev_- Local development keys
Key Generation
Generate secure random keys using:Environment Variables
Never commit API keys to version control. Use environment files:Rate Limiting Benefits
Authenticated requests receive higher rate limits:| Request Type | Unauthenticated | Authenticated |
|---|---|---|
| Standard endpoints | 100/15min | 500/15min |
| Generate endpoint | 10/15min | 50/15min |
Security Features
Timing-Safe Comparison
API keys are validated using SHA-256 hashes with constant-time comparison to prevent timing attacks:No Key Storage
Keys are hashed in memory - raw keys are never stored on disk.Development vs Production
Development (No Authentication)
For local development, run withoutAPI_KEYS:
Production (With Authentication)
For production, always configureAPI_KEYS:
Testing Authentication
Health Check (No Auth Required)
Protected Endpoint Test
Troubleshooting
Getting 401 errors on all requests
Getting 401 errors on all requests
Check that your
API_KEYS environment variable is set correctly and matches the key in your X-API-Key header. Verify no extra whitespace in the environment variable.API keys not being validated
API keys not being validated
Ensure the API server was restarted after setting
API_KEYS. Environment variables are loaded at startup.Keys work locally but not in Docker
Keys work locally but not in Docker
Verify
API_KEYS is passed to the container via env_file or environment in docker-compose.yml.Next Steps
Services Endpoint
Browse available services with authentication
Generate Endpoint
Generate stacks with authenticated requests