Spaces:
Paused
Paused
Commit Β·
5d11752
1
Parent(s): 33980b3
Prune stale dataset files after sync upload
Browse filesFiles changed (7)
- .env.example+11-1
- CHANGELOG.md+38
- ENV_VARIABLES_FULL_LIST.mdAdded+254
- README.md+2-2
- multi-provider-key-rotator.cjs+13-3
- openclaw-sync.py+65-16
- start.sh+110-2
131 unmodified lines13213313413513613713833 unmodified lines172173174175176177131 unmodified lines# have multiple accounts or want to spread rate-limit quota.## Pattern: <PROVIDER>_API_KEYS=key1,key2,key3# Fallback order: plural pool β singular key β LLM_API_KEY## Uncomment and fill in only the providers you use:#33 unmodified lines# is also picked up by OpenClaw β that provider's models become# available in the Control UI for manual selection.# 3. Rotation pools (*_API_KEYS) work for every active provider# independently and in parallel.## EXAMPLE β default Anthropic, also use OpenAI and Groq:131 unmodified lines13213313413513613713813914014133 unmodified lines175176177178179180181182183184185186187131 unmodified lines# have multiple accounts or want to spread rate-limit quota.## Pattern: <PROVIDER>_API_KEYS=key1,key2,key3# Fallback order: plural pool β singular key β LLM_API_KEY (optional)# Set false only if you want to disable global LLM_API_KEY fallback# across providers.LLM_API_KEY_FALLBACK_ENABLED=true## Uncomment and fill in only the providers you use:#33 unmodified lines# is also picked up by OpenClaw β that provider's models become# available in the Control UI for manual selection.# 3. Rotation pools (*_API_KEYS) work for every active provider## Optional: explicitly pin model lists per provider for Control UI visibility# when provider keys are configured.# Format: comma-separated model IDs# NVIDIA_MODELS=meta/llama-3.1-70b-instruct,nvidia/llama-3.1-nemotron-70b-instruct# OPENAI_MODELS=gpt-4o-mini,gpt-4.1# GROQ_MODELS=llama-3.3-70b-versatile,deepseek-r1-distill-llama-70b# independently and in parallel.## EXAMPLE β default Anthropic, also use OpenAI and Groq:
1 unmodified line2345671 unmodified lineAll notable changes to this project will be documented in this file.## [1.4.0] - 2026-04-25### Added1 unmodified line234567891011121314151617181920212223242526272829303132333435363738394041424344451 unmodified lineAll notable changes to this project will be documented in this file.## [1.5.0] - 2026-05-13### Added- **NVIDIA key-rotation support** β added `nvidia-key-rotator.cjs` wiring and startup integration so deployments can rotate NVIDIA credentials similarly to other provider key-rotation flows.- **Cloudflare keep-alive automation** β added/expanded `cloudflare-keepalive-setup.py` flow and startup wiring to provision keep-alive through Cloudflare Worker automation instead of the older UptimeRobot-first approach.- **Sync metadata marker model** β introduced a structured workspace marker `(file_count, total_size, newest_mtime, metadata_hash)` to support stronger change introspection in sync code.### Changed- **Workspace sync script rename finalized** β `workspace-sync.py` flow was migrated to `openclaw-sync.py` in Docker/startup/docs so restore/sync behavior is centralized under one script.- **Sync trigger behavior hardened for config churn** β OpenClaw config sync now debounces until JSON settles before immediate sync, reducing false/partial syncs during rapid config writes.- **Gateway restart flow now saves state first** β restart path was updated to run a pre-restart one-shot state sync so gateway reloads are less likely to drop recent state.- **Shutdown backup now uses a two-step pass** β graceful shutdown now attempts `sync-once-settled` then a final `sync-once` pass to better capture last-second writes.- **Telegram allowlist simplified** β consolidated Telegram allowlist into `TELEGRAM_ALLOWED_USERS` and aligned docs/examples.- **Plugin startup behavior aligned** β startup-installed plugins are synced into `plugins.allow` before gateway launch so runtime-installed plugins are recognized cleanly.- **Cloudflare proxy path matured** β multiple iterations improved fetch/proxy behavior (header handling, endpoint scoping, API root routing, URL parsing, and logging noise reduction), then simplified unstable undici patching paths.- **Health dashboard polish** β sync timestamps now show local time, footer credits were corrected, and status rendering/docs were updated for the Cloudflare keep-alive model.- **CI workflow churn documented** β GitHub workflow files for HF sync were added/renamed/cleaned multiple times as space/repo naming stabilized.### Fixed- **Missed rapid backup updates** β sync logic now relies on content fingerprint checks for no-op decisions so same-second or quick successive changes are less likely to be skipped.- **Non-deterministic metadata hashing** β metadata hashing now iterates paths deterministically to avoid hash jitter from traversal order.- **Transient file race sync failures** β sync fingerprinting/snapshot copy paths now tolerate transient `OSError` (file rotated/deleted mid-scan) instead of aborting the whole sync pass.- **State restore migration edge cases** β restore flow includes migration/cleanup behavior for legacy hidden state paths and stale backup entries.- **Startup/env robustness** β fixed shell export formatting/syntax issues (e.g., NVIDIA/XAI lines) and unbound-variable pitfalls in startup scripts.- **Proxy runtime errors and noise** β fixed specific proxy runtime issues (including `UND_ERR_INVALID_ARG`, fetch duplex handling, and upstream error visibility) and reduced noisy stdout logs that interfered with clean process output.- **HF workflow/repo reference mismatches** β corrected and later cleaned workflow repository references during repo migration/restructure.### Docs- README/.env/security docs were refreshed across multiple commits to reflect:- Cloudflare keep-alive replacing UptimeRobot setup path,- updated secrets and startup environment behavior,- provider/key-rotation options,- backup/sync behavior and troubleshooting guidance.## [1.4.0] - 2026-04-25### Added
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254# ENV Variables Full List (Repo Scope)
> Internal reference file. Not linked from README/docs navigation.
## 1) User-settable (Space Secrets / `.env`)
These are the main variables you can set directly.
### Core startup/auth- `LLM_API_KEY` β string API key. Example: `LLM_API_KEY=sk-ant-xxxx`- `LLM_MODEL` β `provider/model-id` string. Examples: - `LLM_MODEL=anthropic/claude-sonnet-4-5` - `LLM_MODEL=nvidia/meta/llama-3.1-70b-instruct`- `GATEWAY_TOKEN` β random secret string. Example: `GATEWAY_TOKEN=9d2f...`- `OPENCLAW_PASSWORD` β plaintext password string. Example: `OPENCLAW_PASSWORD=MyStrongPass123`
### Provider fallback/selection- `LLM_API_KEY_FALLBACK_ENABLED` β boolean-like: - enabled: `true`, `1`, `yes`, `on` - disabled: `false`, `0`, `no`, `off` - default/example: `LLM_API_KEY_FALLBACK_ENABLED=true`
### Provider-specific keys (single-key form)Use plain provider key strings. Examples:- `NVIDIA_API_KEY=nvapi-xxxx`- `OPENAI_API_KEY=sk-xxxx`- `GEMINI_API_KEY=AIzaSyxxxx`
Full list:- `ANTHROPIC_API_KEY`- `OPENAI_API_KEY`- `GEMINI_API_KEY`- `DEEPSEEK_API_KEY`- `OPENROUTER_API_KEY`- `KILOCODE_API_KEY`- `OPENCODE_API_KEY`- `ZAI_API_KEY`- `MOONSHOT_API_KEY`- `KIMI_API_KEY`- `MINIMAX_API_KEY`- `MODELSTUDIO_API_KEY`- `XIAOMI_API_KEY`- `VOLCANO_ENGINE_API_KEY`- `BYTEPLUS_API_KEY`- `QIANFAN_API_KEY`- `MISTRAL_API_KEY`- `XAI_API_KEY`- `NVIDIA_API_KEY`- `COHERE_API_KEY`- `GROQ_API_KEY`- `TOGETHER_API_KEY`- `CEREBRAS_API_KEY`- `VENICE_API_KEY`- `SYNTHETIC_API_KEY`- `COPILOT_GITHUB_TOKEN`- `HUGGINGFACE_HUB_TOKEN`- `AI_GATEWAY_API_KEY`
### Provider key pools (comma-separated rotation)Format: comma-separated keys, no spaces required. Examples:- `NVIDIA_API_KEYS=nvapi-key1,nvapi-key2`- `OPENAI_API_KEYS=sk-a,sk-b,sk-c`
Full list:- `ANTHROPIC_API_KEYS`- `OPENAI_API_KEYS`- `GEMINI_API_KEYS`- `DEEPSEEK_API_KEYS`- `OPENROUTER_API_KEYS`- `KILOCODE_API_KEYS`- `OPENCODE_API_KEYS`- `ZAI_API_KEYS`- `MOONSHOT_API_KEYS`- `MINIMAX_API_KEYS`- `XIAOMI_API_KEYS`- `VOLCANO_ENGINE_API_KEYS`- `BYTEPLUS_API_KEYS`- `QIANFAN_API_KEYS`- `MODELSTUDIO_API_KEYS`- `KIMI_API_KEYS`- `MISTRAL_API_KEYS`- `XAI_API_KEYS`- `NVIDIA_API_KEYS`- `GROQ_API_KEYS`- `COHERE_API_KEYS`- `TOGETHER_API_KEYS`- `CEREBRAS_API_KEYS`- `HUGGINGFACE_HUB_TOKENS`
### Provider model lists (optional, for Control UI visibility)Format: comma-separated model IDs; used only when that provider has key(s) configured.Examples:- `NVIDIA_MODELS=meta/llama-3.1-70b-instruct,nvidia/llama-3.1-nemotron-70b-instruct`- `OPENAI_MODELS=gpt-4o-mini,gpt-4.1`- `GROQ_MODELS=llama-3.3-70b-versatile,deepseek-r1-distill-llama-70b`
Supported:- `ANTHROPIC_MODELS`- `OPENAI_MODELS`- `GEMINI_MODELS`- `DEEPSEEK_MODELS`- `OPENROUTER_MODELS`- `KILOCODE_MODELS`- `OPENCODE_MODELS`- `ZAI_MODELS`- `MOONSHOT_MODELS`- `KIMI_MODELS`- `MINIMAX_MODELS`- `MODELSTUDIO_MODELS`- `XIAOMI_MODELS`- `VOLCANO_ENGINE_MODELS`- `BYTEPLUS_MODELS`- `QIANFAN_MODELS`- `GROQ_MODELS`- `MISTRAL_MODELS`- `XAI_MODELS`- `NVIDIA_MODELS`- `COHERE_MODELS`- `TOGETHER_MODELS`- `CEREBRAS_MODELS`
### Telegram / WhatsApp- `TELEGRAM_BOT_TOKEN` β bot token string. Example: `TELEGRAM_BOT_TOKEN=123456:ABC...`- `TELEGRAM_ALLOWED_USERS` β comma-separated numeric IDs. Example: `TELEGRAM_ALLOWED_USERS=12345,67890`- `TELEGRAM_USER_ID` β legacy single numeric ID. Example: `TELEGRAM_USER_ID=12345`- `TELEGRAM_USER_IDS` β legacy comma-separated IDs. Example: `TELEGRAM_USER_IDS=12345,67890`- `WHATSAPP_ENABLED` β boolean-like (`true/false`, `1/0`, `yes/no`, `on/off`). Example: `WHATSAPP_ENABLED=true`
### Backup/sync- `HF_TOKEN` β HF token string. Example: `HF_TOKEN=hf_xxxxx`- `HF_USERNAME` β HF username string. Example: `HF_USERNAME=myhandle`- `BACKUP_DATASET_NAME` β dataset slug string. Example: `BACKUP_DATASET_NAME=huggingclaw-backup`- `SYNC_INTERVAL` β integer seconds. Example: `SYNC_INTERVAL=180`- `SYNC_START_DELAY` β integer seconds. Example: `SYNC_START_DELAY=10`- `SYNC_MAX_FILE_BYTES` β integer bytes. Example: `SYNC_MAX_FILE_BYTES=52428800`- `OPENCLAW_CONFIG_WATCH_INTERVAL` β number (supports decimal seconds). Example: `OPENCLAW_CONFIG_WATCH_INTERVAL=1`- `OPENCLAW_CONFIG_SETTLE_SECONDS` β number (supports decimal seconds). Example: `OPENCLAW_CONFIG_SETTLE_SECONDS=3`
### Gateway/runtime tuning- `GATEWAY_HOST` β hostname/IP string. Example: `GATEWAY_HOST=127.0.0.1`- `GATEWAY_PORT` β integer port. Example: `GATEWAY_PORT=3456`- `GATEWAY_VERBOSE` β boolean-like. Example: `GATEWAY_VERBOSE=true`- `GATEWAY_READY_TIMEOUT` β integer seconds. Example: `GATEWAY_READY_TIMEOUT=60`- `GATEWAY_MAX_RESTARTS` β integer count. Example: `GATEWAY_MAX_RESTARTS=10`- `GATEWAY_RESTART_DELAY` β integer seconds. Example: `GATEWAY_RESTART_DELAY=2`- `TRUSTED_PROXIES` β comma-separated CIDR/IP list. Example: `TRUSTED_PROXIES=127.0.0.1,10.0.0.0/8`- `ALLOWED_ORIGINS` β comma-separated origins. Example: `ALLOWED_ORIGINS=https://a.com,https://b.com`- `PORT` β integer external port. Example: `PORT=7860`
### Browser/plugin controls- `BROWSER_PLUGIN_MODE` β mode string (`auto`, `builtin`, `external`, etc. depending on runtime). Example: `BROWSER_PLUGIN_MODE=auto`- `BROWSER_EXECUTABLE_PATH` β absolute path. Example: `BROWSER_EXECUTABLE_PATH=/usr/bin/chromium`- `BROWSER_DISABLED` β boolean-like. Example: `BROWSER_DISABLED=false`- `ACP_PLUGIN_MODE` β mode string. Example: `ACP_PLUGIN_MODE=auto`- `ACPX_DISABLED` β boolean-like. Example: `ACPX_DISABLED=true`
### OpenClaw logging/behavior- `OPENCLAW_VERSION` β image/app version string. Example: `OPENCLAW_VERSION=latest`- `OPENCLAW_RUNTIME_VERSION` β runtime tag string. Example: `OPENCLAW_RUNTIME_VERSION=v1.2.3`- `OPENCLAW_DISPLAY_VERSION` β display label string. Example: `OPENCLAW_DISPLAY_VERSION=Custom`- `OPENCLAW_DISABLE_BONJOUR` β boolean-like. Example: `OPENCLAW_DISABLE_BONJOUR=true`- `OPENCLAW_CONSOLE_LOG_LEVEL` β log level (`trace|debug|info|warn|error`). Example: `OPENCLAW_CONSOLE_LOG_LEVEL=warn`- `OPENCLAW_CONSOLE_LOG_STYLE` β style string. Example: `OPENCLAW_CONSOLE_LOG_STYLE=pretty`- `OPENCLAW_FILE_LOG_LEVEL` β log level (`trace|debug|info|warn|error`). Example: `OPENCLAW_FILE_LOG_LEVEL=info`
### Custom OpenAI-compatible provider- `CUSTOM_PROVIDER_NAME` β unique provider prefix. Example: `CUSTOM_PROVIDER_NAME=modal`- `CUSTOM_BASE_URL` β base URL only (not `/chat/completions`). Example: `CUSTOM_BASE_URL=https://api.modal.com/v1`- `CUSTOM_MODEL_ID` β model id string. Example: `CUSTOM_MODEL_ID=zai-org/GLM-5.1-FP8`- `CUSTOM_MODEL_NAME` β display name. Example: `CUSTOM_MODEL_NAME=GLM 5.1 FP8`- `CUSTOM_API_KEY` β provider key string. Example: `CUSTOM_API_KEY=sk-xxxx`- `CUSTOM_API_TYPE` β API mode string. Example: `CUSTOM_API_TYPE=openai-completions`- `CUSTOM_CONTEXT_WINDOW` β integer token window. Example: `CUSTOM_CONTEXT_WINDOW=128000`- `CUSTOM_MAX_TOKENS` β integer max tokens. Example: `CUSTOM_MAX_TOKENS=500`
### Cloudflare proxy/keepalive- `CLOUDFLARE_WORKERS_TOKEN` β API token string. Example: `CLOUDFLARE_WORKERS_TOKEN=cf_xxx`- `CLOUDFLARE_WORKER_NAME` β worker name string. Example: `CLOUDFLARE_WORKER_NAME=huggingclaw-proxy`- `CLOUDFLARE_ACCOUNT_ID` β account id string. Example: `CLOUDFLARE_ACCOUNT_ID=abc123...`- `CLOUDFLARE_PROXY_URL` β full proxy URL. Example: `CLOUDFLARE_PROXY_URL=https://my-worker.workers.dev`- `CLOUDFLARE_PROXY_SECRET` β shared secret string. Example: `CLOUDFLARE_PROXY_SECRET=long-random-secret`- `CLOUDFLARE_PROXY_DOMAINS` β comma-separated domains. Example: `CLOUDFLARE_PROXY_DOMAINS=api.openai.com,api.anthropic.com`- `CLOUDFLARE_PROXY_DEBUG` β boolean-like. Example: `CLOUDFLARE_PROXY_DEBUG=false`- `CLOUDFLARE_KEEPALIVE_ENABLED` β boolean-like. Example: `CLOUDFLARE_KEEPALIVE_ENABLED=true`- `CLOUDFLARE_KEEPALIVE_URL` β URL string. Example: `CLOUDFLARE_KEEPALIVE_URL=https://space-url.hf.space`- `CLOUDFLARE_KEEPALIVE_CRON` β cron string. Example: `CLOUDFLARE_KEEPALIVE_CRON=*/5 * * * *`- `CLOUDFLARE_KEEPALIVE_WORKER_NAME` β worker name string. Example: `CLOUDFLARE_KEEPALIVE_WORKER_NAME=huggingclaw-keepalive`
### Startup command replay/install helpers- `HUGGINGCLAW_RUN` β shell commands string. Example: `HUGGINGCLAW_RUN=apt-get update && apt-get install -y ffmpeg`- `HUGGINGCLAW_APT_PACKAGES` β comma/space separated package names. Example: `HUGGINGCLAW_APT_PACKAGES=ffmpeg,git`- `HUGGINGCLAW_PIP_PACKAGES` β pip package list string. Example: `HUGGINGCLAW_PIP_PACKAGES=yt-dlp,requests`- `HUGGINGCLAW_NPM_PACKAGES` β npm package list string. Example: `HUGGINGCLAW_NPM_PACKAGES=sharp,axios`- `HUGGINGCLAW_OPENCLAW_PLUGINS` β plugin ids list string. Example: `HUGGINGCLAW_OPENCLAW_PLUGINS=@openclaw/telegram,@openclaw/whatsapp`- `HUGGINGCLAW_STARTUP_SCRIPT` β shell script string. Example: `HUGGINGCLAW_STARTUP_SCRIPT=echo hello`- `HUGGINGCLAW_STARTUP_SCRIPT_B64` β base64 script content. Example: `HUGGINGCLAW_STARTUP_SCRIPT_B64=IyEvYmluL2Jhc2gKZWNobyBoaQ==`- `HUGGINGCLAW_STARTUP_COMMANDS` β newline/semicolon commands string.- `HUGGINGCLAW_STARTUP_STRICT` β boolean-like. Example: `HUGGINGCLAW_STARTUP_STRICT=true`- `WEBHOOK_URL` β webhook endpoint URL. Example: `WEBHOOK_URL=https://hooks.example.com/hc`
---
## 2) Runtime/Internal envs (normally do **not** set manually)
These are mostly derived/temporary/process variables used by scripts:
- `APP_BASE`- `BACKUP_DATASET`- `BROWSER_SHOULD_ENABLE`- `CF_PROXY_ENV_FILE`- `CLEAN_TG_TOKEN`- `CONFIG_JSON`- `CUSTOM_BASE_URL_NORMALIZED`- `CUSTOM_PROVIDER_NORMALIZED`- `CUSTOM_PROVIDER_OK`- `DEBIAN_FRONTEND`- `ERRORS`- `EXISTING_CONFIG`- `GATEWAY_EXIT_CODE`- `GATEWAY_PID`- `GATEWAY_RESTART_COUNT`- `GUARDIAN_PID`- `HC_STARTUP_FAILURES`- `HC_STARTUP_INDEX`- `HC_STARTUP_STRICT_NORMALIZED`- `HC_STARTUP_VAR`- `HOME`- `IDS_JSON`- `INSTALLS`- `LLM_PROVIDER`- `NODE_OPTIONS`- `NPM_CONFIG_PREFIX`- `OPENCLAW_APP_DIR`- `OPENCLAW_CONSOLE_LOG_LEVEL_CONFIGURED`- `OPENCLAW_CONSOLE_LOG_STYLE_CONFIGURED`- `OPENCLAW_FILE_LOG_LEVEL_CONFIGURED`- `ORIGINS_JSON`- `PATCHED`- `PATH`- `PLUGIN_ALLOW_JSON`- `PROXIES_JSON`- `PROXY_URL`- `PYTHONUSERBASE`- `RESET_MARKER_PATH`- `SPACE_AUTHOR_NAME`- `SPACE_HOST`- `SPACE_REPO_NAME`- `STARTUP_FILE`- `SYNC_LOOP_PID`- `VIRTUAL_ENV`- `WEBHOOK_BODY`- `WHATSAPP_CONFIG_ENABLED`- `WHATSAPP_ENABLED_CONFIGURED`- `WHATSAPP_ENABLED_NORMALIZED`249 unmodified lines250251252253254255256257258259249 unmodified lines**Fallback chain** (per provider):1. `{PROVIDER}_API_KEYS` β comma-separated pool *(preferred)*2. `{PROVIDER}_API_KEY` β single dedicated key3. `LLM_API_KEY` β universal fallback *(default for all providers)*> [!TIP]> If you only set `LLM_API_KEY`, all providers use it as a fallback automatically β no extra config needed. Add per-provider pools only when you need multi-key rotation.Supported per-provider variables: `ANTHROPIC_API_KEYS`, `OPENAI_API_KEYS`, `GEMINI_API_KEYS`, `DEEPSEEK_API_KEYS`, `GROQ_API_KEYS`, `MISTRAL_API_KEYS`, `OPENROUTER_API_KEYS`, `XAI_API_KEYS`, `NVIDIA_API_KEYS`, `COHERE_API_KEYS`, `TOGETHER_API_KEYS`, `CEREBRAS_API_KEYS`, and more β see `.env.example` for the full list.249 unmodified lines250251252253254255256257258259249 unmodified lines**Fallback chain** (per provider):1. `{PROVIDER}_API_KEYS` β comma-separated pool *(preferred)*2. `{PROVIDER}_API_KEY` β single dedicated key3. `LLM_API_KEY` β universal fallback *(enabled by default; disable with `LLM_API_KEY_FALLBACK_ENABLED=false`)*> [!TIP]> By default, `LLM_API_KEY` fallback is enabled for compatibility. Set `LLM_API_KEY_FALLBACK_ENABLED=false` if you want strict provider-only activation.Supported per-provider variables: `ANTHROPIC_API_KEYS`, `OPENAI_API_KEYS`, `GEMINI_API_KEYS`, `DEEPSEEK_API_KEYS`, `GROQ_API_KEYS`, `MISTRAL_API_KEYS`, `OPENROUTER_API_KEYS`, `XAI_API_KEYS`, `NVIDIA_API_KEYS`, `COHERE_API_KEYS`, `TOGETHER_API_KEYS`, `CEREBRAS_API_KEYS`, and more β see `.env.example` for the full list.
7 unmodified lines89101112131415 unmodified lines30313233343536143 unmodified lines1801811821831841851 unmodified line18718818919019119219314 unmodified lines2082092102112122137 unmodified lines** For each provider you can supply a comma-separated pool:* ANTHROPIC_API_KEYS=key1,key2,key3* Falls back to the singular env var, then to LLM_API_KEY.** Keys are rotated round-robin per provider independently.*15 unmodified lines// envPlural β env var that holds a comma-separated key pool (preferred)// envSingular β env var that holds a single key (fallback)//// LLM_API_KEY is the final fallback for every provider.//const PROVIDERS = [{143 unmodified lines// Build per-provider key pools + rotation indicesconst providerState = PROVIDERS.map(p => {const dedicatedKeys = normalizeKeys(process.env[p.envPlural] || '',process.env[p.envSingular] || '',1 unmodified lineconst hasDedicated = dedicatedKeys.length > 0;const keys = hasDedicated? dedicatedKeys: normalizeKeys(process.env.LLM_API_KEY || '');if (hasDedicated) {log(`[key-rotator] ${p.name}: ${keys.length} key${keys.length === 1 ? '' : 's'}`);14 unmodified lines}).length;if (fallbackCount > 0) {log(`[key-rotator] ${fallbackCount} provider(s) using LLM_API_KEY fallback`);}// βββ Runtime helpers βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ7 unmodified lines89101112131415 unmodified lines303132333435363738143 unmodified lines1821831841851861871881891 unmodified line19119219319419519619719819920020114 unmodified lines2162172182192202212222237 unmodified lines** For each provider you can supply a comma-separated pool:* ANTHROPIC_API_KEYS=key1,key2,key3* Falls back to the singular env var, and optionally to LLM_API_KEY.** Keys are rotated round-robin per provider independently.*15 unmodified lines// envPlural β env var that holds a comma-separated key pool (preferred)// envSingular β env var that holds a single key (fallback)//// LLM_API_KEY fallback can be controlled via:// LLM_API_KEY_FALLBACK_ENABLED=true|false// Default is enabled for backwards compatibility.//const PROVIDERS = [{143 unmodified lines// Build per-provider key pools + rotation indicesconst providerState = PROVIDERS.map(p => {const llmFallbackRaw = String(process.env.LLM_API_KEY_FALLBACK_ENABLED || '').trim().toLowerCase();const llmFallbackEnabled = !/^(0|false|no|off)$/.test(llmFallbackRaw);const dedicatedKeys = normalizeKeys(process.env[p.envPlural] || '',process.env[p.envSingular] || '',1 unmodified lineconst hasDedicated = dedicatedKeys.length > 0;const keys = hasDedicated? dedicatedKeys: (llmFallbackEnabled? normalizeKeys(process.env.LLM_API_KEY || ''): []);if (hasDedicated) {log(`[key-rotator] ${p.name}: ${keys.length} key${keys.length === 1 ? '' : 's'}`);14 unmodified lines}).length;if (fallbackCount > 0) {log(`[key-rotator] ${fallbackCount} provider(s) using LLM_API_KEY fallback`);} else if (process.env.LLM_API_KEY && /^(0|false|no|off)$/i.test(String(process.env.LLM_API_KEY_FALLBACK_ENABLED || ''))) {log('[key-rotator] LLM_API_KEY fallback disabled (set LLM_API_KEY_FALLBACK_ENABLED=true to re-enable)');}// βββ Runtime helpers βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
17 unmodified lines18192021222345 unmodified lines6970717273741 unmodified line767778798081198 unmodified lines2802812822832842852862872882892902912922934 unmodified lines2982993003013023033043053066 unmodified lines3133143153163173183193203219 unmodified lines33133233333433533633733833934055 unmodified lines39639739839940040140240340440540640740840941041123 unmodified lines4354364374384394403 unmodified lines44444544644744844945045117 unmodified linesimport tempfileimport threadingimport timefrom pathlib import Pathos.environ.setdefault("HF_HUB_DISABLE_PROGRESS_BARS", "1")45 unmodified lines"openclaw-app","gateway.log","browser",}WHATSAPP_CREDS_DIR = OPENCLAW_HOME / "credentials" / "whatsapp" / "default"WHATSAPP_BACKUP_DIR = STATE_DIR / "credentials" / "whatsapp" / "default"1 unmodified lineHF_API = HfApi(token=HF_TOKEN) if HF_TOKEN else NoneSTOP_EVENT = threading.Event()_REPO_ID_CACHE: str | None = Nonedef write_status(status: str, message: str) -> None:198 unmodified linesreturn (1, int(stat.st_size), int(stat.st_mtime_ns))def metadata_marker(root: Path) -> tuple[int, int, int]:if not root.exists():return (0, 0, 0)file_count = 0total_size = 0newest_mtime = 0for path in root.rglob("*"):if not path.is_file():continuerel = path.relative_to(root).as_posix()4 unmodified linesexcept OSError:continuefile_count += 1total_size += int(stat.st_size)newest_mtime = max(newest_mtime, int(stat.st_mtime_ns))return (file_count, total_size, newest_mtime)def fingerprint_dir(root: Path) -> str:6 unmodified linesif _should_exclude(rel, path):continuehasher.update(rel.encode("utf-8"))with path.open("rb") as handle:for chunk in iter(lambda: handle.read(1024 * 1024), b""):hasher.update(chunk)return hasher.hexdigest()9 unmodified linestarget.mkdir(parents=True, exist_ok=True)continuetarget.parent.mkdir(parents=True, exist_ok=True)shutil.copy2(path, target)return staging_rootdef restore_workspace() -> bool:if not HF_TOKEN:write_status("disabled", "HF_TOKEN is not configured.")55 unmodified linesdef _sync_once_unlocked(last_fingerprint: str | None = None,last_marker: tuple[int, int, int] | None = None,) -> tuple[str, tuple[int, int, int]]:if not HF_TOKEN:write_status("disabled", "HF_TOKEN is not configured.")return (last_fingerprint or "", last_marker or (0, 0, 0))snapshot_state_into_workspace()repo_id = ensure_repo_exists()current_marker = metadata_marker(WORKSPACE)if last_marker is not None and current_marker == last_marker:write_status("synced", "No workspace changes detected.")return (last_fingerprint or "", current_marker)23 unmodified linescommit_message=f"HuggingClaw sync {time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())}",ignore_patterns=[".git/*", ".git"],)finally:shutil.rmtree(snapshot_dir, ignore_errors=True)3 unmodified linesdef sync_once(last_fingerprint: str | None = None,last_marker: tuple[int, int, int] | None = None,) -> tuple[str, tuple[int, int, int]]:SYNC_LOCK_FILE.parent.mkdir(parents=True, exist_ok=True)with SYNC_LOCK_FILE.open("w", encoding="utf-8") as lock_handle:fcntl.flock(lock_handle, fcntl.LOCK_EX)17 unmodified lines1819202122232445 unmodified lines707172737475761 unmodified line78798081828384198 unmodified lines2832842852862872882892902912922932942952962974 unmodified lines3023033043053063073083093103113123133143153163173186 unmodified lines3253263273283293303313323333343353363373383393409 unmodified lines35035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838955 unmodified lines44544644744844945045145245345445545645745845923 unmodified lines4834844854864874884893 unmodified lines49349449549649749849950017 unmodified linesimport tempfileimport threadingimport timefrom typing import TypeAliasfrom pathlib import Pathos.environ.setdefault("HF_HUB_DISABLE_PROGRESS_BARS", "1")45 unmodified lines"openclaw-app","gateway.log","browser","npm",}WHATSAPP_CREDS_DIR = OPENCLAW_HOME / "credentials" / "whatsapp" / "default"WHATSAPP_BACKUP_DIR = STATE_DIR / "credentials" / "whatsapp" / "default"1 unmodified lineHF_API = HfApi(token=HF_TOKEN) if HF_TOKEN else NoneSTOP_EVENT = threading.Event()_REPO_ID_CACHE: str | None = NoneWorkspaceMarker: TypeAlias = tuple[int, int, int, str]def write_status(status: str, message: str) -> None:198 unmodified linesreturn (1, int(stat.st_size), int(stat.st_mtime_ns))def metadata_marker(root: Path) -> WorkspaceMarker:if not root.exists():return (0, 0, 0, "")file_count = 0total_size = 0newest_mtime = 0metadata_hasher = hashlib.sha256()for path in sorted(root.rglob("*")):if not path.is_file():continuerel = path.relative_to(root).as_posix()4 unmodified linesexcept OSError:continuefile_count += 1size = int(stat.st_size)mtime_ns = int(stat.st_mtime_ns)total_size += sizenewest_mtime = max(newest_mtime, mtime_ns)metadata_hasher.update(rel.encode("utf-8"))metadata_hasher.update(b"\0")metadata_hasher.update(str(size).encode("ascii"))metadata_hasher.update(b"\0")metadata_hasher.update(str(mtime_ns).encode("ascii"))metadata_hasher.update(b"\0")return (file_count, total_size, newest_mtime, metadata_hasher.hexdigest())def fingerprint_dir(root: Path) -> str:6 unmodified linesif _should_exclude(rel, path):continuehasher.update(rel.encode("utf-8"))try:with path.open("rb") as handle:for chunk in iter(lambda: handle.read(1024 * 1024), b""):hasher.update(chunk)except (FileNotFoundError, IsADirectoryError, NotADirectoryError):# Fingerprint must represent a complete view of the workspace.# Retry next sync pass instead of silently hashing a partial tree.raise RuntimeError(f"Workspace changed while hashing {rel}; retrying next sync pass.")return hasher.hexdigest()9 unmodified linestarget.mkdir(parents=True, exist_ok=True)continuetarget.parent.mkdir(parents=True, exist_ok=True)try:shutil.copy2(path, target)except (FileNotFoundError, IsADirectoryError, NotADirectoryError):# Do not upload a partial snapshot; let caller retry on next loop.raise RuntimeError(f"Snapshot changed while copying {rel_posix}; retrying next sync pass.")return staging_rootdef prune_remote_deleted_files(repo_id: str, snapshot_dir: Path) -> None:if HF_API is None:returnlocal_files = {path.relative_to(snapshot_dir).as_posix()for path in snapshot_dir.rglob("*")if path.is_file()}remote_files = HF_API.list_repo_files(repo_id=repo_id, repo_type="dataset")stale_files = [path for path in remote_filesif path not in local_files and path not in {".gitattributes"}]for stale_path in stale_files:HF_API.delete_file(path_in_repo=stale_path,repo_id=repo_id,repo_type="dataset",commit_message=f"Delete stale file {stale_path}",)def restore_workspace() -> bool:if not HF_TOKEN:write_status("disabled", "HF_TOKEN is not configured.")55 unmodified linesdef _sync_once_unlocked(last_fingerprint: str | None = None,last_marker: WorkspaceMarker | None = None,) -> tuple[str, WorkspaceMarker]:if not HF_TOKEN:write_status("disabled", "HF_TOKEN is not configured.")return (last_fingerprint or "", last_marker or (0, 0, 0, ""))snapshot_state_into_workspace()repo_id = ensure_repo_exists()current_marker = metadata_marker(WORKSPACE)if last_marker is not None and current_marker == last_marker:write_status("synced", "No workspace changes detected.")return (last_fingerprint or "", current_marker)23 unmodified linescommit_message=f"HuggingClaw sync {time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())}",ignore_patterns=[".git/*", ".git"],)prune_remote_deleted_files(repo_id, snapshot_dir)finally:shutil.rmtree(snapshot_dir, ignore_errors=True)3 unmodified linesdef sync_once(last_fingerprint: str | None = None,last_marker: WorkspaceMarker | None = None,) -> tuple[str, WorkspaceMarker]:SYNC_LOCK_FILE.parent.mkdir(parents=True, exist_ok=True)with SYNC_LOCK_FILE.open("w", encoding="utf-8") as lock_handle:fcntl.flock(lock_handle, fcntl.LOCK_EX)
130 unmodified lines131132133134135136148 unmodified lines285286287288289290249 unmodified lines540541542543544545546547548549130 unmodified lines;;esac# ββ Setup directories ββmkdir -p /home/node/.openclaw/agents/main/sessionsmkdir -p /home/node/.openclaw/credentials148 unmodified linesfifi# Browser configuration (managed local Chromium in HF/Docker)BROWSER_EXECUTABLE_PATH=""for candidate in /usr/bin/chromium /usr/bin/chromium-browser /snap/bin/chromium; do249 unmodified lines# ββ Trap SIGTERM for graceful shutdown ββgraceful_shutdown() {echo "Shutting down..."if [ -f "/home/node/app/openclaw-sync.py" ]; thenecho "Saving state before exit..."python3 /home/node/app/openclaw-sync.py sync-once || \echo "Warning: could not complete shutdown sync"fikill $(jobs -p) 2>/dev/nullexit 0130 unmodified lines131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178148 unmodified lines327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393249 unmodified lines643644645646647648649650651652653654655656657130 unmodified lines;;esac# Ensure OpenClaw provider discovery can see per-provider keys even when users# configure only *_API_KEYS pools. Mirror first pool key into singular env.promote_first_pool_key() {local singular_var="$1"local pool_var="$2"local singular_val="${!singular_var:-}"local pool_val="${!pool_var:-}"[ -n "$singular_val" ] && return 0[ -n "$pool_val" ] || return 0local firstfirst=$(printf '%s' "$pool_val" | tr ',' '\n' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | awk 'NF{print; exit}')[ -n "$first" ] || return 0export "${singular_var}=$first"}promote_first_pool_key "ANTHROPIC_API_KEY" "ANTHROPIC_API_KEYS"promote_first_pool_key "OPENAI_API_KEY" "OPENAI_API_KEYS"promote_first_pool_key "GEMINI_API_KEY" "GEMINI_API_KEYS"promote_first_pool_key "DEEPSEEK_API_KEY" "DEEPSEEK_API_KEYS"promote_first_pool_key "OPENROUTER_API_KEY" "OPENROUTER_API_KEYS"promote_first_pool_key "KILOCODE_API_KEY" "KILOCODE_API_KEYS"promote_first_pool_key "OPENCODE_API_KEY" "OPENCODE_API_KEYS"promote_first_pool_key "ZAI_API_KEY" "ZAI_API_KEYS"promote_first_pool_key "MOONSHOT_API_KEY" "MOONSHOT_API_KEYS"promote_first_pool_key "MINIMAX_API_KEY" "MINIMAX_API_KEYS"promote_first_pool_key "XIAOMI_API_KEY" "XIAOMI_API_KEYS"promote_first_pool_key "VOLCANO_ENGINE_API_KEY" "VOLCANO_ENGINE_API_KEYS"promote_first_pool_key "BYTEPLUS_API_KEY" "BYTEPLUS_API_KEYS"promote_first_pool_key "QIANFAN_API_KEY" "QIANFAN_API_KEYS"promote_first_pool_key "MODELSTUDIO_API_KEY" "MODELSTUDIO_API_KEYS"promote_first_pool_key "KIMI_API_KEY" "KIMI_API_KEYS"promote_first_pool_key "MISTRAL_API_KEY" "MISTRAL_API_KEYS"promote_first_pool_key "XAI_API_KEY" "XAI_API_KEYS"promote_first_pool_key "NVIDIA_API_KEY" "NVIDIA_API_KEYS"promote_first_pool_key "GROQ_API_KEY" "GROQ_API_KEYS"promote_first_pool_key "COHERE_API_KEY" "COHERE_API_KEYS"promote_first_pool_key "TOGETHER_API_KEY" "TOGETHER_API_KEYS"promote_first_pool_key "CEREBRAS_API_KEY" "CEREBRAS_API_KEYS"promote_first_pool_key "HUGGINGFACE_HUB_TOKEN" "HUGGINGFACE_HUB_TOKENS"# ββ Setup directories ββmkdir -p /home/node/.openclaw/agents/main/sessionsmkdir -p /home/node/.openclaw/credentials148 unmodified linesfifi# Optional: explicitly expose provider model lists in Control UI when# provider keys are configured. Format:# NVIDIA_MODELS=model1,model2# OPENAI_MODELS=gpt-4o-mini,gpt-4.1# This helps when provider auto-discovery does not populate models reliably.inject_provider_models_from_env() {local provider="$1"local models_env="$2"local key_env_single="$3"local key_env_pool="$4"local models_csv="${!models_env:-}"local single_key="${!key_env_single:-}"local pool_keys="${!key_env_pool:-}"# Only inject when both:# 1) provider has at least one configured key# 2) explicit model list env is providedif [ -z "$models_csv" ] || { [ -z "$single_key" ] && [ -z "$pool_keys" ]; }; thenreturn 0filocal models_jsonmodels_json=$(printf '%s' "$models_csv" \| tr ',' '\n' \| sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' \| awk 'NF' \| jq -R . \| jq -s 'map({id: ., name: .}) | unique_by(.id)')CONFIG_JSON=$(jq \--arg provider "$provider" \--argjson models "$models_json" \'.models.mode = "merge"| .models.providers[$provider] = ((.models.providers[$provider] // {}) + {models: $models})' <<<"$CONFIG_JSON")}# Built-in provider model envs (optional)inject_provider_models_from_env "anthropic" "ANTHROPIC_MODELS" "ANTHROPIC_API_KEY" "ANTHROPIC_API_KEYS"inject_provider_models_from_env "openai" "OPENAI_MODELS" "OPENAI_API_KEY" "OPENAI_API_KEYS"inject_provider_models_from_env "google" "GEMINI_MODELS" "GEMINI_API_KEY" "GEMINI_API_KEYS"inject_provider_models_from_env "deepseek" "DEEPSEEK_MODELS" "DEEPSEEK_API_KEY" "DEEPSEEK_API_KEYS"inject_provider_models_from_env "openrouter" "OPENROUTER_MODELS" "OPENROUTER_API_KEY" "OPENROUTER_API_KEYS"inject_provider_models_from_env "kilocode" "KILOCODE_MODELS" "KILOCODE_API_KEY" "KILOCODE_API_KEYS"inject_provider_models_from_env "opencode" "OPENCODE_MODELS" "OPENCODE_API_KEY" "OPENCODE_API_KEYS"inject_provider_models_from_env "zai" "ZAI_MODELS" "ZAI_API_KEY" "ZAI_API_KEYS"inject_provider_models_from_env "moonshot" "MOONSHOT_MODELS" "MOONSHOT_API_KEY" "MOONSHOT_API_KEYS"inject_provider_models_from_env "kimi-coding" "KIMI_MODELS" "KIMI_API_KEY" "KIMI_API_KEYS"inject_provider_models_from_env "minimax" "MINIMAX_MODELS" "MINIMAX_API_KEY" "MINIMAX_API_KEYS"inject_provider_models_from_env "modelstudio" "MODELSTUDIO_MODELS" "MODELSTUDIO_API_KEY" "MODELSTUDIO_API_KEYS"inject_provider_models_from_env "xiaomi" "XIAOMI_MODELS" "XIAOMI_API_KEY" "XIAOMI_API_KEYS"inject_provider_models_from_env "volcengine" "VOLCANO_ENGINE_MODELS" "VOLCANO_ENGINE_API_KEY" "VOLCANO_ENGINE_API_KEYS"inject_provider_models_from_env "byteplus" "BYTEPLUS_MODELS" "BYTEPLUS_API_KEY" "BYTEPLUS_API_KEYS"inject_provider_models_from_env "qianfan" "QIANFAN_MODELS" "QIANFAN_API_KEY" "QIANFAN_API_KEYS"inject_provider_models_from_env "groq" "GROQ_MODELS" "GROQ_API_KEY" "GROQ_API_KEYS"inject_provider_models_from_env "mistral" "MISTRAL_MODELS" "MISTRAL_API_KEY" "MISTRAL_API_KEYS"inject_provider_models_from_env "xai" "XAI_MODELS" "XAI_API_KEY" "XAI_API_KEYS"inject_provider_models_from_env "nvidia" "NVIDIA_MODELS" "NVIDIA_API_KEY" "NVIDIA_API_KEYS"inject_provider_models_from_env "cohere" "COHERE_MODELS" "COHERE_API_KEY" "COHERE_API_KEYS"inject_provider_models_from_env "together" "TOGETHER_MODELS" "TOGETHER_API_KEY" "TOGETHER_API_KEYS"inject_provider_models_from_env "cerebras" "CEREBRAS_MODELS" "CEREBRAS_API_KEY" "CEREBRAS_API_KEYS"# Browser configuration (managed local Chromium in HF/Docker)BROWSER_EXECUTABLE_PATH=""for candidate in /usr/bin/chromium /usr/bin/chromium-browser /snap/bin/chromium; do249 unmodified lines# ββ Trap SIGTERM for graceful shutdown ββgraceful_shutdown() {echo "Shutting down..."if [ -f "/home/node/app/openclaw-sync.py" ] && [ -n "${HF_TOKEN:-}" ]; thenecho "Saving state before exit..."timeout 8s python3 /home/node/app/openclaw-sync.py sync-once-settled || \echo "Warning: could not complete settled shutdown sync"sleep 1python3 /home/node/app/openclaw-sync.py sync-once || \echo "Warning: could not complete final shutdown sync"elif [ -f "/home/node/app/openclaw-sync.py" ]; thenecho "HF_TOKEN not set; skipping shutdown backup sync."fikill $(jobs -p) 2>/dev/nullexit 0
.env.example+11-1
CHANGELOG.md+38
ENV_VARIABLES_FULL_LIST.mdAdded+254
README.md+2-2
multi-provider-key-rotator.cjs+13-3
openclaw-sync.py+65-16
start.sh+110-2