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

VariableConfig KeyDescription
OPENCLAW_CONFIGPath to config file (default: ./openclaw.yaml)
OPENCLAW_LOG_LEVELlogging.levelLog level: DEBUG, INFO, WARNING, ERROR
OPENCLAW_LOG_FORMATlogging.formatLog format: json, console
OPENCLAW_MAX_STEPSagent.max_stepsMaximum reasoning steps per task
OPENCLAW_MAX_TOKENSagent.max_tokensMaximum tokens per task
OPENCLAW_TIMEOUTagent.timeout_secondsTask timeout in seconds

LLM Provider Settings

VariableDescription
OPENAI_API_KEYOpenAI API key (standard OpenAI env var)
ANTHROPIC_API_KEYAnthropic API key
OPENCLAW_LLM_PROVIDERProvider: openai, anthropic, ollama, azure_openai
OPENCLAW_LLM_MODELModel name (e.g., gpt-4o, claude-3-5-sonnet-20241022)
OPENCLAW_LLM_BASE_URLCustom API endpoint (for Azure OpenAI or local proxies)
OPENCLAW_LLM_TEMPERATUREGeneration temperature (0.0–2.0)
AZURE_OPENAI_API_KEYAzure OpenAI API key (when provider=azure_openai)
AZURE_OPENAI_ENDPOINTAzure OpenAI endpoint URL
AZURE_OPENAI_API_VERSIONAzure API version string
OLLAMA_BASE_URLOllama server URL (default: http://localhost:11434)

Memory Settings

VariableDescription
OPENCLAW_MEMORY_SEMANTIC_ENABLEDEnable semantic memory (true/false)
OPENCLAW_MEMORY_SEMANTIC_BACKENDBackend: chroma, pinecone, in_memory
CHROMA_HOSTChromaDB host (when backend=chroma)
CHROMA_PORTChromaDB port (default: 8000)
PINECONE_API_KEYPinecone API key (when backend=pinecone)
PINECONE_INDEXPinecone index name

Server Settings

VariableDescription
OPENCLAW_SERVER_HOSTBind host (default: 0.0.0.0)
OPENCLAW_SERVER_PORTBind port (default: 8080)
OPENCLAW_SERVER_WORKERSUvicorn worker processes (default: 4)
OPENCLAW_API_KEYRequire this key in X-API-Key header; blank = no auth
OPENCLAW_MAX_CONCURRENT_TASKSMax tasks running simultaneously (default: 10)

Development and Debug Variables

VariableDescription
OPENCLAW_DEVEnable dev mode (hot reload, verbose errors) — set to 1
OPENCLAW_MOCK_LLMReplace LLM calls with echo mock — set to 1
OPENCLAW_DISABLE_CACHEDisable response caching — set to 1
OTEL_EXPORTER_OTLP_ENDPOINTOpenTelemetry collector endpoint (enables tracing)
OTEL_SERVICE_NAMEService 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=5

Use 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.