Managing API Keys and Environment Variables
Securely store and manage API keys, tokens, and environment variables for OpenClaw and skills.
API Key Management
OpenClaw needs API keys for AI models and optional services. Managing them securely is important.
Required Keys
AI Model Key
At minimum, you need one AI provider key:
- OpenRouter API key — Access to all models (recommended)
- Anthropic API key — For Claude models directly
- OpenAI API key — For GPT models directly
- Google AI API key — For Gemini models directly
Channel Tokens
- Telegram Bot Token — From BotFather
- Discord Bot Token — From Discord Developer Portal
- Slack Bot Token — From Slack API
Setting Environment Variables
Shell Profile
Add to ~/.bashrc, ~/.zshrc, or equivalent:
export OPENROUTER_API_KEY="sk-or-..."
export TELEGRAM_BOT_TOKEN="123456:ABC-..."
.env File
Create a .env file in your workspace:
OPENROUTER_API_KEY=sk-or-...
TELEGRAM_BOT_TOKEN=123456:ABC-...
Configuration Reference
In openclaw.json, reference environment variables:
{
"api_key_env": "OPENROUTER_API_KEY",
"channels": {
"telegram": {
"token_env": "TELEGRAM_BOT_TOKEN"
}
}
}
Per-Skill API Keys
Skills that need their own API keys:
{
"skills": {
"entries": {
"weather-skill": {
"env": {
"WEATHER_API_KEY": "your-weather-key"
}
}
}
}
}
These are scoped to the skill — they're set when the skill runs and removed after.
Security Best Practices
- Never commit keys — Add
.envto.gitignore - Use environment variables — Don't put raw keys in
openclaw.json - Rotate regularly — Change keys periodically
- Minimum permissions — Only grant the access each key needs
- Monitor usage — Check your provider dashboard for unexpected activity
Claw for All
With Claw for All, API key management is simplified — we provide and manage the AI model key. You only need to provide channel tokens (Telegram bot token, etc.) through the dashboard.
Ready for your AI assistant?
Get started with Claw for All today. No setup, no terminal, just sign up and go.
Get StartedRelated Guides
How OpenClaw Memory Works: MEMORY.md and USER.md
Understand OpenClaw's persistent memory system — MEMORY.md for facts and USER.md for personal info.
Personalizing Your OpenClaw Assistant
Customize OpenClaw's personality, response style, and behavior to match your preferences.
Managing Conversation History and Context
Control how OpenClaw handles conversation history, context windows, and session management.