Environment Variables
Configure OpenClaw with environment variables—API keys, tokens, paths
Configure OpenClaw with environment variables—API keys, tokens, paths
OpenClaw reads several environment variables for API keys, channel tokens, workspace paths, and gateway settings. Use environment variables instead of hardcoding secrets in your config file for better security and portability.
Set these before starting the gateway or in your shell profile (~/.bashrc, ~/.zshrc):
ANTHROPIC_API_KEY — Anthropic API key (if not using OAuth)OPENAI_API_KEY — OpenAI API keyGOOGLE_GENERATIVE_AI_API_KEY — Google Gemini API keyOPENROUTER_API_KEY — OpenRouter API keyXAI_API_KEY — xAI (Grok) API keyTELEGRAM_BOT_TOKEN, DISCORD_BOT_TOKEN, etc. — Channel tokens (or use Secrets Management)Override default paths:
OPENCLAW_CONFIG or CLAWDBOT_CONFIG — Path to config JSONOPENCLAW_WORKSPACE — Workspace root (default ~/.openclaw/workspace)OPENCLAW_HOME — Home directory for OpenClaw dataLegacy installs may use CLAWDBOT_* or MOLTBOT_* variants.
Export variables in your shell or use a .env file with a loader. For production, prefer SecretRef and vault integration over plain environment variables.
export ANTHROPIC_API_KEY="sk-ant-..."
export OPENAI_API_KEY="sk-..."
openclaw start
Full list of supported variables: docs.openclaw.ai. For channel tokens and gateway auth, see Secrets Management and Configuration Guide.