Memory & Personalization
🔑

Managing API Keys and Environment Variables

Securely store and manage API keys, tokens, and environment variables for OpenClaw and skills.

4 min read|
api keysenvironment variablessecrets

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

  1. Never commit keys — Add .env to .gitignore
  2. Use environment variables — Don't put raw keys in openclaw.json
  3. Rotate regularly — Change keys periodically
  4. Minimum permissions — Only grant the access each key needs
  5. 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.

api keysenvironment variablessecretssecuritykey management

Ready for your AI assistant?

Get started with Claw for All today. No setup, no terminal, just sign up and go.

Get Started

Related Guides