Environment Variables Reference
All OpenClaw configuration values can be set or overridden via environment variables. Environment variables take precedence over the YAML config file. Variable names use the prefix OPENCLAW_ followed by the config key path in uppercase with dots replaced by underscores.
Core Settings
| Variable | Config Key | Description |
|---|---|---|
OPENCLAW_CONFIG | — | Path to config file (default: ./openclaw.yaml) |
OPENCLAW_LOG_LEVEL | logging.level | Log level: DEBUG, INFO, WARNING, ERROR |
OPENCLAW_LOG_FORMAT | logging.format | Log format: json, console |
OPENCLAW_MAX_STEPS | agent.max_steps | Maximum reasoning steps per task |
OPENCLAW_MAX_TOKENS | agent.max_tokens | Maximum tokens per task |
OPENCLAW_TIMEOUT | agent.timeout_seconds | Task timeout in seconds |
LLM Provider Settings
| Variable | Description |
|---|---|
OPENAI_API_KEY | OpenAI API key (standard OpenAI env var) |
ANTHROPIC_API_KEY | Anthropic API key |
OPENCLAW_LLM_PROVIDER | Provider: openai, anthropic, ollama, azure_openai |
OPENCLAW_LLM_MODEL | Model name (e.g., gpt-4o, claude-3-5-sonnet-20241022) |
OPENCLAW_LLM_BASE_URL | Custom API endpoint (for Azure OpenAI or local proxies) |
OPENCLAW_LLM_TEMPERATURE | Generation temperature (0.0–2.0) |
AZURE_OPENAI_API_KEY | Azure OpenAI API key (when provider=azure_openai) |
AZURE_OPENAI_ENDPOINT | Azure OpenAI endpoint URL |
AZURE_OPENAI_API_VERSION | Azure API version string |
OLLAMA_BASE_URL | Ollama server URL (default: http://localhost:11434) |
Memory Settings
| Variable | Description |
|---|---|
OPENCLAW_MEMORY_SEMANTIC_ENABLED | Enable semantic memory (true/false) |
OPENCLAW_MEMORY_SEMANTIC_BACKEND | Backend: chroma, pinecone, in_memory |
CHROMA_HOST | ChromaDB host (when backend=chroma) |
CHROMA_PORT | ChromaDB port (default: 8000) |
PINECONE_API_KEY | Pinecone API key (when backend=pinecone) |
PINECONE_INDEX | Pinecone index name |
Server Settings
| Variable | Description |
|---|---|
OPENCLAW_SERVER_HOST | Bind host (default: 0.0.0.0) |
OPENCLAW_SERVER_PORT | Bind port (default: 8080) |
OPENCLAW_SERVER_WORKERS | Uvicorn worker processes (default: 4) |
OPENCLAW_API_KEY | Require this key in X-API-Key header; blank = no auth |
OPENCLAW_MAX_CONCURRENT_TASKS | Max tasks running simultaneously (default: 10) |
Development and Debug Variables
| Variable | Description |
|---|---|
OPENCLAW_DEV | Enable dev mode (hot reload, verbose errors) — set to 1 |
OPENCLAW_MOCK_LLM | Replace LLM calls with echo mock — set to 1 |
OPENCLAW_DISABLE_CACHE | Disable response caching — set to 1 |
OTEL_EXPORTER_OTLP_ENDPOINT | OpenTelemetry collector endpoint (enables tracing) |
OTEL_SERVICE_NAME | Service name in traces (default: openclaw) |
Example .env File
# .env — copy to .env.local and fill in your values
# NEVER commit .env.local to version control
OPENAI_API_KEY=sk-...
OPENCLAW_LLM_MODEL=gpt-4o-mini
OPENCLAW_LOG_LEVEL=INFO
OPENCLAW_SERVER_PORT=8080
OPENCLAW_API_KEY=your-secure-api-key-here
OPENCLAW_MAX_CONCURRENT_TASKS=5Use a .env file during development (loaded by python-dotenv if installed) and real environment variables in production. Never commit a .env file containing real credentials to version control — add .env.local and .env to your .gitignore.
Security Considerations for Environment Variables
Environment variables are a common and convenient way to pass secrets to applications, but they have security implications you should understand. In containerized environments (Docker, Kubernetes), environment variables are visible to all processes in the container and can be read from /proc/[pid]/environ by any process running as the same user. In Kubernetes, secrets passed as environment variables are stored in etcd and are accessible to anyone with read access to the pod spec.
For OpenClaw specifically: never pass API keys via environment variables on a shared system where other untrusted processes run. In production, prefer Kubernetes Secrets (with encryption at rest enabled) or a secrets manager (AWS Secrets Manager, HashiCorp Vault, GCP Secret Manager) over plain environment variables. OpenClaw supports the openclaw.secrets plugin interface for fetching secrets from external managers at startup, keeping them out of the environment entirely.
Audit your environment variables regularly — remove any that are no longer used, rotate keys on a schedule, and ensure that environment variable values don't appear in application logs (OpenClaw's structured logging sanitizes known secret fields, but check that no custom tool implementations log their environment variables).
When to Use Environment Variables vs. Config File
The general principle: secrets go in environment variables, non-secret configuration goes in the config file. API keys, database passwords, and private tokens should never appear in a config file that might be committed to version control — use environment variables for everything sensitive. On the other hand, agent name, system prompt, max_steps, and tool configuration are not secrets and are fine in the config file where they're readable, documentable, and version-controlled.
In development, a .env file loaded via python-dotenv is a convenient way to manage environment variables locally without polluting your shell. In CI/CD pipelines, use the platform's secret store (GitHub Actions secrets, GitLab CI variables, CircleCI contexts) instead of storing secrets in .env files. In production Kubernetes deployments, use Kubernetes Secrets mounted as environment variables or a cloud secrets manager for the most secure approach.
Twelve-Factor App Compliance
OpenClaw's environment variable configuration is designed to be fully compliant with the Twelve-Factor App methodology, which specifies that configuration (anything that varies between deployments) is stored in the environment, not in the code. The combination of an environment variable for every configuration key, no default values that are deployment-specific, and the ability to override all settings via environment makes OpenClaw straightforward to deploy in twelve-factor environments like Heroku, Fly.io, Render, and containerized cloud platforms. Follow twelve-factor practices — all deployment-specific configuration in environment variables, code and generic configuration in version control — for the most maintainable and portable deployments.
Variable Priority and Override Order
Configuration values are resolved in this priority order (highest to lowest): command-line flags override environment variables, which override the YAML config file, which override compiled defaults. This ordering means you can set a default in the config file and override it for a specific deployment via an environment variable without modifying the file — a clean separation of defaults from environment-specific overrides that makes deployment management predictable. Use openclaw config show at any time to see the current effective configuration after all overrides are applied, making it easy to verify that an override was applied correctly.
Keeping Secrets Out of Environment Variables
For production deployments, prefer injecting API keys via a secrets manager (AWS Secrets Manager, HashiCorp Vault, Kubernetes Secrets) rather than raw environment variables visible in ps aux or container inspect output. When direct env injection is unavoidable, restrict process visibility using the operating system's access controls — run the agent under a dedicated service account and lock down process listing to that account. Always rotate API keys regularly and revoke old ones promptly. Document which keys are in use and which services they belong to in your internal runbook — undocumented credentials become security liabilities during incident response when you need to identify and rotate them quickly.